You are here

public function ViewsLocalTaskTest::testGetDerivativeDefinitionsWithOverrideRoute in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php \Drupal\Tests\views\Unit\Plugin\Derivative\ViewsLocalTaskTest::testGetDerivativeDefinitionsWithOverrideRoute()

Tests fetching the derivatives on a view which overrides an existing route.

File

core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php, line 168
Contains \Drupal\Tests\views\Unit\Plugin\Derivative\ViewsLocalTaskTest.

Class

ViewsLocalTaskTest
@coversDefaultClass \Drupal\views\Plugin\Derivative\ViewsLocalTask @group views

Namespace

Drupal\Tests\views\Unit\Plugin\Derivative

Code

public function testGetDerivativeDefinitionsWithOverrideRoute() {
  $executable = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->getMock();
  $storage = $this
    ->getMockBuilder('Drupal\\views\\Entity\\View')
    ->disableOriginalConstructor()
    ->getMock();
  $storage
    ->expects($this
    ->any())
    ->method('id')
    ->will($this
    ->returnValue('example_view'));
  $storage
    ->expects($this
    ->any())
    ->method('getExecutable')
    ->willReturn($executable);
  $executable->storage = $storage;
  $this->viewStorage
    ->expects($this
    ->any())
    ->method('load')
    ->with('example_view')
    ->willReturn($storage);
  $display_plugin = $this
    ->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\PathPluginBase')
    ->setMethods([
    'getOption',
  ])
    ->disableOriginalConstructor()
    ->getMockForAbstractClass();
  $display_plugin
    ->expects($this
    ->once())
    ->method('getOption')
    ->with('menu')
    ->will($this
    ->returnValue([
    'type' => 'tab',
    'weight' => 12,
  ]));
  $executable->display_handler = $display_plugin;
  $result = [
    [
      'example_view',
      'page_1',
    ],
  ];
  $this->localTaskDerivative
    ->setApplicableMenuViews($result);

  // Mock the view route names state.
  $view_route_names = [];

  // Setup a view which overrides an existing route.
  $view_route_names['example_view.page_1'] = 'example_overridden_route';
  $this->state
    ->expects($this
    ->once())
    ->method('get')
    ->with('views.view_route_names')
    ->will($this
    ->returnValue($view_route_names));
  $definitions = $this->localTaskDerivative
    ->getDerivativeDefinitions($this->baseDefinition);
  $this
    ->assertCount(0, $definitions);
}