diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index f71f2f4..7b19e64 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -190,7 +190,7 @@ protected function addMissingDefaultTab($base_route_name) { $definitions = array(); try { $route = $this->routeProvider->getRouteByName($base_route_name); - $title = $route->attributes->get('_title'); + $title = $route->getDefault('_title'); $plugin_id = 'default_local_task:' . $base_route_name; $definitions[$plugin_id] = array( 'route_name' => $base_route_name, diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 7c8986d..b3ce479 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -12,6 +12,8 @@ use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Exception\RouteNotFoundException; +use Symfony\Component\Routing\Route; use Zend\Stdlib\ArrayObject; /** @@ -101,11 +103,6 @@ protected function setUp() { $this->controllerResolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface'); $this->request = new Request(); $this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface'); - $fake_route = new \stdClass; - $fake_route->attributes = new ParameterBag(); - $this->routeProvider->expects($this->any()) - ->method('getRouteByName') - ->will($this->returnValue($fake_route)); $this->pluginDiscovery = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface'); $this->factory = $this->getMock('Drupal\Component\Plugin\Factory\FactoryInterface'); $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); @@ -217,6 +214,7 @@ public function testGetLocalTaskForRouteWithFilledCache() { * Tests findDefinitions and ensure that default tabs are added automatically. * * @see \Drupal\Core\Menu\LocalTaskManager::findDefinitions() + * @see \Drupal\Core\Menu\LocalTaskManager::addMisingDefaultTab() */ public function testFindDefinitions() { $definitions = $this->getLocalTasksFixture2(); @@ -231,12 +229,48 @@ public function testFindDefinitions() { $this->setupLocalTaskManager(); + $route = new Route('/route-4', array('_title' => 'example')); + $this->routeProvider->expects($this->any()) + ->method('getRouteByName') + ->with($this->equalTo('route_4')) + ->will($this->returnValue($route)); + $local_tasks = $this->manager->getDefinitions(); $this->assertNotEmpty($local_tasks['default_local_task:route_4']); $local_task = $local_tasks['default_local_task:route_4']; $this->assertEquals('route_4', $local_task['route_name']); $this->assertEquals('route_4', $local_task['base_route_name']); + $this->assertEquals('example', $local_task['title']); + } + + /** + * Tests findDefinitions with default tab with wrong specific route name. + * + * @see \Drupal\Core\Menu\LocalTaskManager::findDefinitions() + * @see \Drupal\Core\Menu\LocalTaskManager::addMisingDefaultTab() + */ + public function testFindDefinitionsWithInvalidBaseRouteName() { + $definitions = $this->getLocalTasksFixture2(); + $this->pluginDiscovery->expects($this->once()) + ->method('getDefinitions') + ->will($this->returnValue($definitions)); + + // Ensure that the alter hook is called. + $this->moduleHandler->expects($this->once()) + ->method('alter') + ->with($this->equalTo('local_tasks')); + + $this->setupLocalTaskManager(); + + $this->routeProvider->expects($this->any()) + ->method('getRouteByName') + ->with($this->equalTo('route_4')) + ->will($this->throwException(new RouteNotFoundException())); + + $local_tasks = $this->manager->getDefinitions(); + + $this->assertTrue(empty($local_tasks['default_local_task:route_4'])); } /** @@ -244,6 +278,7 @@ public function testFindDefinitions() { * * @see \Drupal\Core\Menu\LocalTaskManager::findDefinitions() * @see \Drupal\Core\Menu\LocalTaskManager::getDefinition() + * @see \Drupal\Core\Menu\LocalTaskManager::addMisingDefaultTab() */ public function testFindDefinitionsWithSingleDefinition() { $definitions = $this->getLocalTasksFixture2(); @@ -253,6 +288,12 @@ public function testFindDefinitionsWithSingleDefinition() { $this->setupLocalTaskManager(); + $route = new Route('/route-4', array('_title' => 'example')); + $this->routeProvider->expects($this->any()) + ->method('getRouteByName') + ->with($this->equalTo('route_4')) + ->will($this->returnValue($route)); + $local_task = $this->manager->getDefinition('default_local_task:route_4'); $this->assertNotEmpty($local_task); $this->assertEquals('route_4', $local_task['route_name']);