public function MatcherDumperTest::testDump

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

File

drupal/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperTest.php, line 118
Definition of Drupal\system\Tests\Routing\UrlMatcherDumperTest.

Class

MatcherDumperTest
Basic tests for the UrlMatcherDumper.

Namespace

Drupal\system\Tests\Routing

Code

public function testDump() {
  $connection = Database::getConnection();
  $dumper = new MatcherDumper($connection, '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(
    'route_set' => '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->pattern, '/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.');
}