/** * Tests the getTitle method. * * @see \Drupal\system\Plugin\Type\MenuLocalTaskManager::getTitle() */ public function testGetTitle() { $menu_local_task = $this->getMock('Drupal\\Core\\Menu\\LocalTaskInterface'); $menu_local_task->expects($this->once())->method('getTitle'); $this->controllerResolver->expects($this->once())->method('getArguments')->with($this->request, array($menu_local_task, 'getTitle'))->will($this->returnValue(array())); $this->manager->getTitle($menu_local_task); }
/** * Setups the local task manager for the test. */ protected function setupLocalTaskManager() { $this->manager = $this->getMockBuilder('Drupal\\Core\\Menu\\LocalTaskManager')->disableOriginalConstructor()->setMethods(NULL)->getMock(); $property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'controllerResolver'); $property->setAccessible(TRUE); $property->setValue($this->manager, $this->controllerResolver); $request_stack = new RequestStack(); $request_stack->push($this->request); $property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'requestStack'); $property->setAccessible(TRUE); $property->setValue($this->manager, $request_stack); $property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'accessManager'); $property->setAccessible(TRUE); $property->setValue($this->manager, $this->accessManager); $property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'routeBuilder'); $property->setAccessible(TRUE); $property->setValue($this->manager, $this->routeBuilder); $property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'discovery'); $property->setAccessible(TRUE); $property->setValue($this->manager, $this->pluginDiscovery); $property = new \ReflectionProperty('Drupal\\Core\\Menu\\LocalTaskManager', 'factory'); $property->setAccessible(TRUE); $property->setValue($this->manager, $this->factory); $language_manager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface'); $language_manager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue(new Language(array('id' => 'en')))); $this->manager->setCacheBackend($this->cacheBackend, 'local_task:en', array('local_task' => 1)); }
/** * @covers ::getTasksBuild */ public function testGetTasksBuildWithCacheabilityMetadata() { $definitions = $this->getLocalTaskFixtures(); $this->pluginDiscovery->expects($this->once())->method('getDefinitions')->will($this->returnValue($definitions)); // Set up some cacheablity metadata and ensure its merged together. $definitions['menu_local_task_test_tasks_settings']['cache_tags'] = ['tag.example1']; $definitions['menu_local_task_test_tasks_settings']['cache_contexts'] = ['context.example1']; $definitions['menu_local_task_test_tasks_edit']['cache_tags'] = ['tag.example2']; $definitions['menu_local_task_test_tasks_edit']['cache_contexts'] = ['context.example2']; // Test the cacheability metadata of access checking. $definitions['menu_local_task_test_tasks_view_child1']['access'] = AccessResult::allowed()->addCacheContexts(['user.permissions']); $this->setupFactoryAndLocalTaskPlugins($definitions, 'menu_local_task_test_tasks_view'); $this->setupLocalTaskManager(); $this->controllerResolver->expects($this->any())->method('getArguments')->willReturn([]); $this->routeMatch->expects($this->any())->method('getRouteName')->willReturn('menu_local_task_test_tasks_view'); $this->routeMatch->expects($this->any())->method('getRawParameters')->willReturn(new ParameterBag()); $cacheability = new CacheableMetadata(); $local_tasks = $this->manager->getTasksBuild('menu_local_task_test_tasks_view', $cacheability); // Ensure that all cacheability metadata is merged together. $this->assertEquals(['tag.example1', 'tag.example2'], $cacheability->getCacheTags()); $this->assertEquals(['context.example1', 'context.example2', 'route', 'user.permissions'], $cacheability->getCacheContexts()); }