function PathPluginBaseTest::testGetRestRoute

Same name in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\display\PathPluginBaseTest::testGetRestRoute()
  2. 8.9.x core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\display\PathPluginBaseTest::testGetRestRoute()
  3. 11.x core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\display\PathPluginBaseTest::testGetRestRoute()

Tests the altering of a REST route.

File

core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php, line 321

Class

PathPluginBaseTest
@coversDefaultClass \Drupal\views\Plugin\views\display\PathPluginBase @group views

Namespace

Drupal\Tests\views\Unit\Plugin\display

Code

public function testGetRestRoute() : void {
    $collection = new RouteCollection();
    $route = new Route('test_route', [
        '_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController::content',
    ]);
    $route->setMethods([
        'GET',
    ]);
    $route->setRequirement('_format', 'json');
    $collection->add('test_route', $route);
    [
        $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'));
}

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