You are here

protected function LocalTaskManagerTest::setupFactoryAndLocalTaskPlugins in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 451
Contains \Drupal\Tests\Core\Menu\LocalTaskManagerTest.

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(isset($info['weight']) ? $info['weight'] : 0);
    $mock
      ->getCacheContexts()
      ->willReturn(isset($info['cache_contexts']) ? $info['cache_contexts'] : []);
    $mock
      ->getCacheTags()
      ->willReturn(isset($info['cache_tags']) ? $info['cache_tags'] : []);
    $mock
      ->getCacheMaxAge()
      ->willReturn(isset($info['cache_max_age']) ? $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')
    ->will($this
    ->returnValueMap($map));
}