diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index ade40cf..c4dd3d8 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -109,23 +109,13 @@ public function testGetLocalTasksForRouteSingleLevelTitle() { $mock_plugin = $this->getMock('Drupal\Core\Menu\LocalTaskInterface'); - $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), - ); - $this->factory->expects($this->any()) - ->method('createInstance') - ->will($this->returnValueMap($map)); - + $this->setupFactory($mock_plugin); $this->setupLocalTaskManager(); $local_tasks = $this->manager->getLocalTasksForRoute('menu_local_task_test_tasks_view'); - $this->assertEquals(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, - )), $local_tasks); + $result = $this->getLocalTasksForRouteResult($mock_plugin); + + $this->assertEquals($result, $local_tasks); } /** @@ -139,26 +129,11 @@ public function testGetLocalTaskForRouteWithEmptyCache() { ->will($this->returnValue($definitions)); $mock_plugin = $this->getMock('Drupal\Core\Menu\LocalTaskInterface'); - - $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), - ); - - $this->factory->expects($this->any()) - ->method('createInstance') - ->will($this->returnValueMap($map)); + $this->setupFactory($mock_plugin); $this->setupLocalTaskManager(); - $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->cacheBackend->expects($this->at(0)) ->method('get') @@ -188,26 +163,11 @@ public function testGetLocalTaskForRouteWithFilledCache() { ->method('getDefinitions'); $mock_plugin = $this->getMock('Drupal\Core\Menu\LocalTaskInterface'); - - $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), - ); - - $this->factory->expects($this->any()) - ->method('createInstance') - ->will($this->returnValueMap($map)); + $this->setupFactory($mock_plugin); $this->setupLocalTaskManager(); - $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->cacheBackend->expects($this->at(0)) ->method('get') @@ -294,7 +254,10 @@ protected function setupLocalTaskManager() { } /** + * Return some local tasks plugin definitions. + * * @return array + * An array of plugin definition keyed by plugin ID. */ protected function getLocalTaskFixtures() { $definitions = array(); @@ -323,5 +286,42 @@ protected function getLocalTaskFixtures() { return $definitions; } + /** + * Setups the plugin factory with some local task plugins. + * + * @param \PHPUnit_Framework_MockObject_MockObject $mock_plugin + * 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), + ); + $this->factory->expects($this->any()) + ->method('createInstance') + ->will($this->returnValueMap($map)); + } + + /** + * Returns an expected result for getLocalTasksForRoute. + * + * @param \PHPUnit_Framework_MockObject_MockObject $mock_plugin + * The mock plugin. + * + * @return array + * The expected result, keyed by local task leve. + */ + 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_edit' => $mock_plugin, + ) + ); + return $result; + } + }