You are here

public function PathPluginBaseTest::testAlterPostRestRoute 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::testAlterPostRestRoute()
  2. 10 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\display

Code

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('my views title', $route
    ->getDefault('_title'));
}