You are here

public function MatcherDumperTest::testDump in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php \Drupal\KernelTests\Core\Routing\MatcherDumperTest::testDump()
  2. 9 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
    ->select('test_routes', 'tr')
    ->fields('tr')
    ->condition('name', 'test_route')
    ->execute()
    ->fetchObject();
  $loaded_route = unserialize($record->route);
  $this
    ->assertEquals('test_route', $record->name, 'Dumped route has correct name.');
  $this
    ->assertEquals('/test/{my}/path', $record->path, 'Dumped route has correct pattern.');
  $this
    ->assertEquals('/test/%/path', $record->pattern_outline, 'Dumped route has correct pattern outline.');

  // Verify that the dumped route has the correct fit. Note that 5 decimal
  // equals 101 binary.
  $this
    ->assertEquals(5, $record->fit, 'Dumped route has correct fit.');
  $this
    ->assertInstanceOf(Route::class, $loaded_route);
}