function ViewsLocalTaskTest::testGetDerivativeDefinitionsWithDefaultLocalTask
Same name in other branches
- 9 core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php \Drupal\Tests\views\Unit\Plugin\Derivative\ViewsLocalTaskTest::testGetDerivativeDefinitionsWithDefaultLocalTask()
- 8.9.x core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php \Drupal\Tests\views\Unit\Plugin\Derivative\ViewsLocalTaskTest::testGetDerivativeDefinitionsWithDefaultLocalTask()
- 10 core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php \Drupal\Tests\views\Unit\Plugin\Derivative\ViewsLocalTaskTest::testGetDerivativeDefinitionsWithDefaultLocalTask()
Tests fetching the derivatives on a view with a default local task.
File
-
core/
modules/ views/ tests/ src/ Unit/ Plugin/ Derivative/ ViewsLocalTaskTest.php, line 223
Class
- ViewsLocalTaskTest
- @coversDefaultClass \Drupal\views\Plugin\Derivative\ViewsLocalTask @group views
Namespace
Drupal\Tests\views\Unit\Plugin\DerivativeCode
public function testGetDerivativeDefinitionsWithDefaultLocalTask() : void {
$executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')
->disableOriginalConstructor()
->getMock();
$storage = $this->getMockBuilder('Drupal\\views\\Entity\\View')
->disableOriginalConstructor()
->getMock();
$storage->expects($this->any())
->method('id')
->willReturn('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')
->onlyMethods([
'getOption',
])
->disableOriginalConstructor()
->getMock();
$display_plugin->expects($this->exactly(2))
->method('getOption')
->with('menu')
->willReturn([
'type' => 'default tab',
'weight' => 12,
'title' => 'Example title',
]);
$executable->display_handler = $display_plugin;
$result = [
[
'example_view',
'page_1',
],
];
$this->localTaskDerivative
->setApplicableMenuViews($result);
// Mock the view route names state.
$view_route_names = [];
$view_route_names['example_view.page_1'] = 'view.example_view.page_1';
$this->state
->expects($this->exactly(2))
->method('get')
->with('views.view_route_names')
->willReturn($view_route_names);
$definitions = $this->localTaskDerivative
->getDerivativeDefinitions($this->baseDefinition);
$this->assertCount(1, $definitions);
$plugin = $definitions['view.example_view.page_1'];
$this->assertEquals('view.example_view.page_1', $plugin['route_name']);
$this->assertEquals(12, $plugin['weight']);
$this->assertEquals('Example title', $plugin['title']);
$this->assertEquals($this->baseDefinition['class'], $plugin['class']);
$this->assertEquals('view.example_view.page_1', $plugin['base_route']);
// Setup the prefix of the derivative.
$definitions['views_view:view.example_view.page_1'] = $definitions['view.example_view.page_1'];
unset($definitions['view.example_view.page_1']);
$this->localTaskDerivative
->alterLocalTasks($definitions);
$plugin = $definitions['views_view:view.example_view.page_1'];
$this->assertCount(1, $definitions);
$this->assertEquals('view.example_view.page_1', $plugin['route_name']);
$this->assertEquals(12, $plugin['weight']);
$this->assertEquals('Example title', $plugin['title']);
$this->assertEquals($this->baseDefinition['class'], $plugin['class']);
$this->assertEquals('view.example_view.page_1', $plugin['base_route']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.