function MatcherDumperTest::testDump

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php \Drupal\KernelTests\Core\Routing\MatcherDumperTest::testDump()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php \Drupal\KernelTests\Core\Routing\MatcherDumperTest::testDump()
  3. 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 122

Class

MatcherDumperTest
Confirm that the matcher dumper is functioning properly.

Namespace

Drupal\KernelTests\Core\Routing

Code

public function testDump() : void {
    $connection = Database::getConnection();
    $dumper = new MatcherDumper($connection, $this->state, $this->logger, '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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.