You are here

public function PathPluginBaseTest::testAlterRoutesWithOptionalParameters in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\display\PathPluginBaseTest::testAlterRoutesWithOptionalParameters()
  2. 10 core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php \Drupal\Tests\views\Unit\Plugin\display\PathPluginBaseTest::testAlterRoutesWithOptionalParameters()

Tests altering routes with optional parameters in the overridden route.

File

core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php, line 491
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\display

Code

public function testAlterRoutesWithOptionalParameters() {
  $collection = new RouteCollection();
  $collection
    ->add('test_route', new Route('test_route/{parameter}', [
    '_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController::content',
  ]));
  list($view) = $this
    ->setupViewExecutableAccessPlugin();
  $display = [];
  $display['display_plugin'] = 'page';
  $display['id'] = 'page_1';
  $display['display_options'] = [
    'path' => 'test_route/%',
  ];
  $display['display_options']['arguments'] = [
    'test_id' => [],
    'test_id2' => [],
  ];
  $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'));

  // Ensure that the path did not changed and placeholders are respected.
  $this
    ->assertEquals('/test_route/{parameter}/{arg_1}', $route
    ->getPath());
  $this
    ->assertEquals([
    'arg_0' => 'parameter',
  ], $route
    ->getOption('_view_argument_map'));
  $this
    ->assertEquals('my views title', $route
    ->getDefault('_title'));
}