function LocalTaskManagerTest::setupFactoryAndLocalTaskPlugins

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php \Drupal\Tests\Core\Menu\LocalTaskManagerTest::setupFactoryAndLocalTaskPlugins()
  2. 10 core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php \Drupal\Tests\Core\Menu\LocalTaskManagerTest::setupFactoryAndLocalTaskPlugins()
  3. 11.x core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php \Drupal\Tests\Core\Menu\LocalTaskManagerTest::setupFactoryAndLocalTaskPlugins()
1 call to LocalTaskManagerTest::setupFactoryAndLocalTaskPlugins()
LocalTaskManagerTest::testGetTasksBuildWithCacheabilityMetadata in core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php
@covers ::getTasksBuild

File

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

Class

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

Namespace

Drupal\Tests\Core\Menu

Code

protected function setupFactoryAndLocalTaskPlugins(array $definitions, $active_plugin_id) {
    $map = [];
    $access_manager_map = [];
    foreach ($definitions as $plugin_id => $info) {
        $info += [
            'access' => AccessResult::allowed(),
        ];
        $mock = $this->prophesize(LocalTaskInterface::class);
        $mock->willImplement(CacheableDependencyInterface::class);
        $mock->getRouteName()
            ->willReturn($info['route_name']);
        $mock->getTitle()
            ->willReturn($info['title']);
        $mock->getRouteParameters(Argument::cetera())
            ->willReturn([]);
        $mock->getOptions(Argument::cetera())
            ->willReturn([]);
        $mock->getActive()
            ->willReturn($plugin_id === $active_plugin_id);
        $mock->getWeight()
            ->willReturn($info['weight'] ?? 0);
        $mock->getCacheContexts()
            ->willReturn($info['cache_contexts'] ?? []);
        $mock->getCacheTags()
            ->willReturn($info['cache_tags'] ?? []);
        $mock->getCacheMaxAge()
            ->willReturn($info['cache_max_age'] ?? Cache::PERMANENT);
        $access_manager_map[] = [
            $info['route_name'],
            [],
            $this->account,
            TRUE,
            $info['access'],
        ];
        $map[] = [
            $info['id'],
            [],
            $mock->reveal(),
        ];
    }
    $this->accessManager
        ->expects($this->any())
        ->method('checkNamedRoute')
        ->willReturnMap($access_manager_map);
    $this->factory
        ->expects($this->any())
        ->method('createInstance')
        ->willReturnMap($map);
}

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