protected function LocalTaskIntegrationTestBase::getLocalTaskManager in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTestBase.php \Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase::getLocalTaskManager()
- 9 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 57
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
->setAccessible(TRUE);
$property
->setValue($manager, $argumentResolver);
// todo mock a request with a route.
$request_stack = new RequestStack();
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'requestStack');
$property
->setAccessible(TRUE);
$property
->setValue($manager, $request_stack);
$accessManager = $this
->createMock('Drupal\\Core\\Access\\AccessManagerInterface');
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'accessManager');
$property
->setAccessible(TRUE);
$property
->setValue($manager, $accessManager);
$route_provider = $this
->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'routeProvider');
$property
->setAccessible(TRUE);
$property
->setValue($manager, $route_provider);
$module_handler = $this
->getMockBuilder('Drupal\\Core\\Extension\\ModuleHandlerInterface')
->disableOriginalConstructor()
->getMock();
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'moduleHandler');
$property
->setAccessible(TRUE);
$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
->setAccessible(TRUE);
$property
->setValue($manager, $pluginDiscovery);
$method = new \ReflectionMethod('Drupal\\Core\\Menu\\LocalTaskManager', 'alterInfo');
$method
->setAccessible(TRUE);
$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')
->will($this
->returnValue($plugin_stub));
$property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'factory');
$property
->setAccessible(TRUE);
$property
->setValue($manager, $factory);
$cache_backend = $this
->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$manager
->setCacheBackend($cache_backend, 'local_task.en', [
'local_task',
]);
return $manager;
}