function PathPluginBaseTest::testAlterRoutesWithParametersAndUpcasting

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

Tests altering routes with parameters and upcasting information.

File

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

Class

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

Namespace

Drupal\Tests\views\Unit\Plugin\display

Code

public function testAlterRoutesWithParametersAndUpcasting() {
    $collection = new RouteCollection();
    $collection->add('test_route', new Route('test_route/{parameter}', [
        '_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController::content',
    ], [], [
        'parameters' => [
            'taxonomy_term' => 'entity:entity_test',
        ],
    ]));
    [
        $view,
    ] = $this->setupViewExecutableAccessPlugin();
    // Manually set up an argument handler.
    $argument = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\argument\\ArgumentPluginBase')
        ->disableOriginalConstructor()
        ->getMock();
    $view->argument['test_id'] = $argument;
    $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('\\Symfony\\Component\\Routing\\Route', $route);
    $this->assertEquals('test_id', $route->getDefault('view_id'));
    $this->assertEquals('page_1', $route->getDefault('display_id'));
    $this->assertEquals([
        'taxonomy_term' => 'entity:entity_test',
    ], $route->getOption('parameters'));
    // Ensure that the path did not changed and placeholders are respected  kk.
    $this->assertEquals('/test_route/{parameter}', $route->getPath());
    $this->assertEquals([
        'arg_0' => 'parameter',
    ], $route->getOption('_view_argument_map'));
    $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.