function LocalTaskManagerTest::testGetTasksBuildWithCacheabilityMetadata

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php \Drupal\Tests\Core\Menu\LocalTaskManagerTest::testGetTasksBuildWithCacheabilityMetadata()
  2. 10 core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php \Drupal\Tests\Core\Menu\LocalTaskManagerTest::testGetTasksBuildWithCacheabilityMetadata()
  3. 11.x core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php \Drupal\Tests\Core\Menu\LocalTaskManagerTest::testGetTasksBuildWithCacheabilityMetadata()

@covers ::getTasksBuild

File

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

Class

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

Namespace

Drupal\Tests\Core\Menu

Code

public function testGetTasksBuildWithCacheabilityMetadata() {
    $definitions = $this->getLocalTaskFixtures();
    $this->pluginDiscovery
        ->expects($this->once())
        ->method('getDefinitions')
        ->will($this->returnValue($definitions));
    // Set up some cacheability metadata and ensure its merged together.
    $definitions['menu_local_task_test_tasks_settings']['cache_tags'] = [
        'tag.example1',
    ];
    $definitions['menu_local_task_test_tasks_settings']['cache_contexts'] = [
        'context.example1',
    ];
    $definitions['menu_local_task_test_tasks_edit']['cache_tags'] = [
        'tag.example2',
    ];
    $definitions['menu_local_task_test_tasks_edit']['cache_contexts'] = [
        'context.example2',
    ];
    // Test the cacheability metadata of access checking.
    $definitions['menu_local_task_test_tasks_view_child1']['access'] = AccessResult::allowed()->addCacheContexts([
        'user.permissions',
    ]);
    $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 ParameterBag());
    $cacheability = new CacheableMetadata();
    $local_tasks = $this->manager
        ->getTasksBuild('menu_local_task_test_tasks_view', $cacheability);
    // Ensure that all cacheability metadata is merged together.
    $this->assertEquals([
        'tag.example1',
        'tag.example2',
    ], $cacheability->getCacheTags());
    $this->assertEquals([
        'context.example1',
        'context.example2',
        'route',
        'user.permissions',
    ], $cacheability->getCacheContexts());
}

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