function LocalTaskIntegrationTestBase::getLocalTaskManager
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTestBase.php \Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase::getLocalTaskManager()
- 8.9.x core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTestBase.php \Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase::getLocalTaskManager()
- 11.x core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTestBase.php \Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase::getLocalTaskManager()
Sets up the local task manager for the test.
1 call to LocalTaskIntegrationTestBase::getLocalTaskManager()
- LocalTaskIntegrationTestBase::assertLocalTasks in core/
tests/ Drupal/ Tests/ Core/ Menu/ LocalTaskIntegrationTestBase.php - Tests integration for local tasks.
File
-
core/
tests/ Drupal/ Tests/ Core/ Menu/ LocalTaskIntegrationTestBase.php, line 59
Class
- LocalTaskIntegrationTestBase
- Defines a base unit test for testing existence of local tasks.
Namespace
Drupal\Tests\Core\MenuCode
protected function getLocalTaskManager($module_dirs, $route_name, $route_params) {
$manager = $this->getMockBuilder('Drupal\\Core\\Menu\\LocalTaskManager')
->disableOriginalConstructor()
->onlyMethods([])
->getMock();
$argumentResolver = $this->createMock('Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolverInterface');
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'argumentResolver');
$property->setValue($manager, $argumentResolver);
// @todo Mock a request with a route.
$request_stack = new RequestStack();
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'requestStack');
$property->setValue($manager, $request_stack);
$accessManager = $this->createMock('Drupal\\Core\\Access\\AccessManagerInterface');
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'accessManager');
$property->setValue($manager, $accessManager);
$route_provider = $this->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'routeProvider');
$property->setValue($manager, $route_provider);
$module_handler = $this->getMockBuilder('Drupal\\Core\\Extension\\ModuleHandlerInterface')
->disableOriginalConstructor()
->getMock();
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'moduleHandler');
$property->setValue($manager, $module_handler);
// Set all the modules as being existent.
$module_handler->expects($this->any())
->method('moduleExists')
->willReturnCallback(function ($module) use ($module_dirs) {
return isset($module_dirs[$module]);
});
$pluginDiscovery = new YamlDiscovery('links.task', $module_dirs);
$pluginDiscovery = new ContainerDerivativeDiscoveryDecorator($pluginDiscovery);
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'discovery');
$property->setValue($manager, $pluginDiscovery);
$method = new \ReflectionMethod('Drupal\\Core\\Menu\\LocalTaskManager', 'alterInfo');
$method->invoke($manager, 'local_tasks');
$plugin_stub = $this->createMock('Drupal\\Core\\Menu\\LocalTaskInterface');
$factory = $this->createMock('Drupal\\Component\\Plugin\\Factory\\FactoryInterface');
$factory->expects($this->any())
->method('createInstance')
->willReturn($plugin_stub);
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'factory');
$property->setValue($manager, $factory);
$cache_backend = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$manager->setCacheBackend($cache_backend, 'local_task.en', [
'local_task',
]);
return $manager;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.