You are here

protected function LocalTaskIntegrationTestBase::getLocalTaskManager in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 62
Contains \Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase.

Class

LocalTaskIntegrationTestBase
Defines a base unit test for testing existence of local tasks.

Namespace

Drupal\Tests\Core\Menu

Code

protected function getLocalTaskManager($module_dirs, $route_name, $route_params) {
  $manager = $this
    ->getMockBuilder('Drupal\\Core\\Menu\\LocalTaskManager')
    ->disableOriginalConstructor()
    ->setMethods(NULL)
    ->getMock();
  $controllerResolver = $this
    ->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
  $property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'controllerResolver');
  $property
    ->setAccessible(TRUE);
  $property
    ->setValue($manager, $controllerResolver);

  // 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
    ->getMock('Drupal\\Core\\Access\\AccessManagerInterface');
  $property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'accessManager');
  $property
    ->setAccessible(TRUE);
  $property
    ->setValue($manager, $accessManager);
  $route_provider = $this
    ->getMock('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')
    ->will($this
    ->returnCallback(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
    ->getMock('Drupal\\Core\\Menu\\LocalTaskInterface');
  $factory = $this
    ->getMock('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
    ->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
  $manager
    ->setCacheBackend($cache_backend, 'local_task.en', array(
    'local_task',
  ));
  return $manager;
}