diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php index 3924e4e..6fe62a1 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php @@ -213,6 +213,16 @@ public function providerTestGetWeight() { 'local_task_default', 0, ), + // Ensure that a default tab of a derivative gets the default value. + array( + array( + 'base_route' => 'local_task_example', + 'id' => 'local_task_derivative_default:example_id', + 'route_name' => 'local_task_example', + ), + 'local_task_derivative_default:example_id', + -10, + ), ); } diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index a5cf842..d78e03f 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -122,13 +122,7 @@ public function testGetLocalTasksForRouteSingleLevelTitle() { $local_tasks = $this->manager->getLocalTasksForRoute('menu_local_task_test_tasks_view'); - $result = array( - 0 => array( - 'menu_local_task_test_tasks_settings' => $mock_plugin, - 'menu_local_task_test_tasks_view' => $mock_plugin, - 'menu_local_task_test_tasks_edit' => $mock_plugin, - ) - ); + $result = $this->getLocalTasksForRouteResult($mock_plugin); $this->assertEquals($result, $local_tasks); } @@ -266,26 +260,38 @@ protected function setupLocalTaskManager() { protected function getLocalTaskFixtures() { $definitions = array(); $definitions['menu_local_task_test_tasks_settings'] = array( - 'id' => 'menu_local_task_test_tasks_settings', 'route_name' => 'menu_local_task_test_tasks_settings', 'title' => 'Settings', 'base_route' => 'menu_local_task_test_tasks_view', ); $definitions['menu_local_task_test_tasks_edit'] = array( - 'id' => 'menu_local_task_test_tasks_edit', 'route_name' => 'menu_local_task_test_tasks_edit', 'title' => 'Settings', 'base_route' => 'menu_local_task_test_tasks_view', 'weight' => 20, ); - $definitions['menu_local_task_test_tasks_view'] = array( - 'id' => 'menu_local_task_test_tasks_view', + // Make this ID different from the route name to catch code that + // confuses them. + $definitions['menu_local_task_test_tasks_view.tab'] = array( 'route_name' => 'menu_local_task_test_tasks_view', 'title' => 'Settings', 'base_route' => 'menu_local_task_test_tasks_view', ); - // Add the defaults from the LocalTaskManager. + + $definitions['menu_local_task_test_tasks_view_child1'] = array( + 'route_name' => 'menu_local_task_test_tasks_child1_page', + 'title' => 'Settings child #1', + 'parent_id' => 'menu_local_task_test_tasks_view.tab', + ); + $definitions['menu_local_task_test_tasks_view_child2'] = array( + 'route_name' => 'menu_local_task_test_tasks_child2_page', + 'title' => 'Settings child #2', + 'parent_id' => 'menu_local_task_test_tasks_view.tab', + 'base_route' => 'this_should_be_replaced', + ); + // Add the ID and defaults from the LocalTaskManager. foreach ($definitions as $id => &$info) { + $info['id'] = $id; $info += array( 'id' => '', 'route_name' => '', @@ -308,11 +314,10 @@ protected function getLocalTaskFixtures() { * The mock plugin. */ protected function setupFactory($mock_plugin) { - $map = array( - array('menu_local_task_test_tasks_settings', array(), $mock_plugin), - array('menu_local_task_test_tasks_edit', array(), $mock_plugin), - array('menu_local_task_test_tasks_view', array(), $mock_plugin), - ); + $map = array(); + foreach ($this->getLocalTaskFixtures() as $info) { + $map[] = array($info['id'], array(), $mock_plugin); + } $this->factory->expects($this->any()) ->method('createInstance') ->will($this->returnValueMap($map)); @@ -325,15 +330,19 @@ protected function setupFactory($mock_plugin) { * The mock plugin. * * @return array - * The expected result, keyed by local task leve. + * The expected result, keyed by local task level. */ protected function getLocalTasksForRouteResult($mock_plugin) { $result = array( 0 => array( 'menu_local_task_test_tasks_settings' => $mock_plugin, - 'menu_local_task_test_tasks_view' => $mock_plugin, + 'menu_local_task_test_tasks_view.tab' => $mock_plugin, 'menu_local_task_test_tasks_edit' => $mock_plugin, - ) + ), + 1 => array( + 'menu_local_task_test_tasks_view_child1' => $mock_plugin, + 'menu_local_task_test_tasks_view_child2' => $mock_plugin, + ), ); return $result; } @@ -344,16 +353,26 @@ protected function getLocalTasksForRouteResult($mock_plugin) { * @return array */ protected function getLocalTasksCache() { + $local_task_fixtures = $this->getLocalTaskFixtures(); return array( 'base_routes' => array( 'menu_local_task_test_tasks_view' => 'menu_local_task_test_tasks_view', ), 'parents' => array( - 'menu_local_task_test_tasks_view' => 1, + 'menu_local_task_test_tasks_view.tab' => TRUE, ), 'children' => array( - '> menu_local_task_test_tasks_view' => $this->getLocalTaskFixtures(), - ) + '> menu_local_task_test_tasks_view' => array( + 'menu_local_task_test_tasks_settings' => $local_task_fixtures['menu_local_task_test_tasks_settings'], + 'menu_local_task_test_tasks_edit' => $local_task_fixtures['menu_local_task_test_tasks_edit'], + 'menu_local_task_test_tasks_view.tab' => $local_task_fixtures['menu_local_task_test_tasks_view.tab'], + ), + 'menu_local_task_test_tasks_view.tab' => array( + // The manager will fill in the base_route before caching. + 'menu_local_task_test_tasks_view_child1' => array('base_route' => 'menu_local_task_test_tasks_view') + $local_task_fixtures['menu_local_task_test_tasks_view_child1'], + 'menu_local_task_test_tasks_view_child2' => array('base_route' => 'menu_local_task_test_tasks_view') + $local_task_fixtures['menu_local_task_test_tasks_view_child2'], + ), + ), ); }