function LocalTaskManagerTest::testGetLocalTasks

Tests the getLocalTasksForRoute method.

@dataProvider providerTestGetLocalTasks

File

core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php, line 488

Class

LocalTaskManagerTest
@coversDefaultClass \Drupal\Core\Menu\LocalTaskManager @group Menu

Namespace

Drupal\Tests\Core\Menu

Code

public function testGetLocalTasks($new_weights, $expected) : void {
    $definitions = $this->getLocalTaskFixtures();
    // Add another child, that will be first in an alphabetical sort.
    $definitions['menu_local_task_test_tasks_view_a_child'] = [
        'route_name' => 'menu_local_task_test_tasks_a_child_page',
        'title' => 'Settings child a_child',
        'parent_id' => 'menu_local_task_test_tasks_view.tab',
        'id' => 'menu_local_task_test_tasks_view_a_child',
        'route_parameters' => [],
        'base_route' => '',
        'weight' => 0,
        'options' => [],
        'class' => 'Drupal\\Core\\Menu\\LocalTaskDefault',
    ];
    // Update the task weights.
    foreach ($new_weights as $local_task => $weight) {
        $definitions[$local_task] = array_merge($definitions[$local_task], $weight);
    }
    $this->pluginDiscovery
        ->expects($this->once())
        ->method('getDefinitions')
        ->willReturn($definitions);
    $this->setupFactoryAndLocalTaskPlugins($definitions, 'menu_local_task_test_tasks_view');
    $this->setupLocalTaskManager();
    $this->argumentResolver
        ->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 InputBag());
    $cacheability = new CacheableMetadata();
    $this->manager
        ->getTasksBuild('menu_local_task_test_tasks_view', $cacheability);
    // Get the local tasks for each level and assert that the order is as
    // expected.
    foreach ([
        0,
        1,
    ] as $level) {
        $local_tasks = $this->manager
            ->getLocalTasks('menu_local_task_test_tasks_view', $level);
        $data = $local_tasks['tabs'];
        $this->assertEquals($expected[$level], array_keys($data));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.