You are here

public function MatcherDumperTest::testDump in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php \Drupal\KernelTests\Core\Routing\MatcherDumperTest::testDump()
  2. 10 core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php \Drupal\KernelTests\Core\Routing\MatcherDumperTest::testDump()

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

File

core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php, line 106

Class

MatcherDumperTest
Confirm that the matcher dumper is functioning properly.

Namespace

Drupal\KernelTests\Core\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', RouteCompiler::class);
  $collection = new RouteCollection();
  $collection
    ->add('test_route', $route);
  $dumper
    ->addRoutes($collection);
  $this->fixtures
    ->createTables($connection);
  $dumper
    ->dump([
    'provider' => 'test',
  ]);
  $record = $connection
    ->query("SELECT * FROM {test_routes} WHERE name= :name", [
    ':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
    ->assertInstanceOf(Route::class, $loaded_route);
}