public function PathPluginBaseTest::testAlterPostRestRoute in Drupal 9
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::testAlterPostRestRoute()
Tests the altering of a REST route.
File
- core/
modules/ views/ tests/ src/ Unit/ Plugin/ display/ PathPluginBaseTest.php, line 266 - 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 testAlterPostRestRoute() {
$collection = new RouteCollection();
$route = new Route('test_route', [
'_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController::content',
]);
$route
->setMethods([
'POST',
]);
$collection
->add('test_route', $route);
list($view) = $this
->setupViewExecutableAccessPlugin();
$display = [];
$display['display_plugin'] = 'page';
$display['id'] = 'page_1';
$display['display_options'] = [
'path' => 'test_route',
];
$this->pathPlugin
->initDisplay($view, $display);
$this->pathPlugin
->collectRoutes($collection);
$view_route_names = $this->pathPlugin
->alterRoutes($collection);
$this
->assertEquals([], $view_route_names);
// Ensure that the test_route is not overridden.
$this
->assertCount(2, $collection);
$route = $collection
->get('test_route');
$this
->assertInstanceOf(Route::class, $route);
$this
->assertFalse($route
->hasDefault('view_id'));
$this
->assertFalse($route
->hasDefault('display_id'));
$this
->assertSame($collection
->get('test_route'), $route);
$route = $collection
->get('view.test_id.page_1');
$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'));
}