You are here

public function MatcherDumperTest::testDump in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Routing/MatcherDumperTest.php \Drupal\system\Tests\Routing\MatcherDumperTest::testDump()

Confirm that we can dump a route collection to the database.

File

core/modules/system/src/Tests/Routing/MatcherDumperTest.php, line 118
Contains \Drupal\system\Tests\Routing\MatcherDumperTest.

Class

MatcherDumperTest
Confirm that the matcher dumper is functioning properly.

Namespace

Drupal\system\Tests\Routing

Code

public function testDump() {
  $connection = Database::getConnection();
  $dumper = new MatcherDumper($connection, $this->state, 'test_routes');
  $route = new Route('/test/{my}/path');
  $route
    ->setOption('compiler_class', 'Drupal\\Core\\Routing\\RouteCompiler');
  $collection = new RouteCollection();
  $collection
    ->add('test_route', $route);
  $dumper
    ->addRoutes($collection);
  $this->fixtures
    ->createTables($connection);
  $dumper
    ->dump(array(
    'provider' => 'test',
  ));
  $record = $connection
    ->query("SELECT * FROM {test_routes} WHERE name= :name", array(
    ':name' => 'test_route',
  ))
    ->fetchObject();
  $loaded_route = unserialize($record->route);
  $this
    ->assertEqual($record->name, 'test_route', 'Dumped route has correct name.');
  $this
    ->assertEqual($record->path, '/test/{my}/path', 'Dumped route has correct pattern.');
  $this
    ->assertEqual($record->pattern_outline, '/test/%/path', 'Dumped route has correct pattern outline.');
  $this
    ->assertEqual($record->fit, 5, 'Dumped route has correct fit.');
  $this
    ->assertTrue($loaded_route instanceof Route, 'Route object retrieved successfully.');
}