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. 8.9.x core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php \Drupal\Tests\Core\Menu\LocalTaskManagerTest::testGetTasksBuildWithCacheabilityMetadata()
  3. 10 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 399

Class

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

Namespace

Drupal\Tests\Core\Menu

Code

public function testGetTasksBuildWithCacheabilityMetadata() : void {
    $definitions = $this->getLocalTaskFixtures();
    $this->pluginDiscovery
        ->expects($this->once())
        ->method('getDefinitions')
        ->willReturn($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 InputBag());
    $cacheability = new CacheableMetadata();
    $this->manager
        ->getTasksBuild('menu_local_task_test_tasks_view', $cacheability);
    // Ensure that all cacheability metadata is merged together.
    $this->assertEqualsCanonicalizing([
        'tag.example1',
        'tag.example2',
    ], $cacheability->getCacheTags());
    $this->assertEqualsCanonicalizing([
        '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.