public function PathPluginBaseTest::testAlterRoute in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\display\PathPluginBaseTest::testAlterRoute()
- 9 core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\display\PathPluginBaseTest::testAlterRoute()
Tests the alter route method.
File
- core/
modules/ views/ tests/ src/ Unit/ Plugin/ display/ PathPluginBaseTest.php, line 229 - Contains \Drupal\Tests\views\Unit\Plugin\display\PathPluginBaseTest.
Class
- PathPluginBaseTest
- @coversDefaultClass \Drupal\views\Plugin\views\display\PathPluginBase @group views
Namespace
Drupal\Tests\views\Unit\Plugin\displayCode
public function testAlterRoute() {
$collection = new RouteCollection();
$collection
->add('test_route', new Route('test_route', [
'_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController::content',
]));
$route_2 = new Route('test_route/example', [
'_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController::content',
]);
$collection
->add('test_route_2', $route_2);
[
$view,
] = $this
->setupViewExecutableAccessPlugin();
$display = [];
$display['display_plugin'] = 'page';
$display['id'] = 'page_1';
$display['display_options'] = [
'path' => 'test_route',
];
$this->pathPlugin
->initDisplay($view, $display);
$view_route_names = $this->pathPlugin
->alterRoutes($collection);
$this
->assertEquals([
'test_id.page_1' => 'test_route',
], $view_route_names);
// Ensure that the test_route is overridden.
$route = $collection
->get('test_route');
$this
->assertInstanceOf(Route::class, $route);
$this
->assertEquals('test_id', $route
->getDefault('view_id'));
$this
->assertEquals('page_1', $route
->getDefault('display_id'));
$this
->assertEquals('Drupal\\views\\Routing\\ViewPageController::getTitle', $route
->getDefault('_title_callback'));
// Ensure that the test_route_2 is not overridden.
$route = $collection
->get('test_route_2');
$this
->assertInstanceOf(Route::class, $route);
$this
->assertFalse($route
->hasDefault('view_id'));
$this
->assertFalse($route
->hasDefault('display_id'));
$this
->assertSame($collection
->get('test_route_2'), $route_2);
}