function ContextualLinkManagerTest::testGetContextualLinkPluginsByGroupWithCache

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::testGetContextualLinkPluginsByGroupWithCache()
  2. 8.9.x core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::testGetContextualLinkPluginsByGroupWithCache()
  3. 10 core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::testGetContextualLinkPluginsByGroupWithCache()

Tests the getContextualLinkPluginsByGroup method with a prefilled cache.

File

core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php, line 142

Class

ContextualLinkManagerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Menu%21ContextualLinkManager.php/class/ContextualLinkManager/11.x" title="Defines a contextual link plugin manager to deal with contextual links." class="local">\Drupal\Core\Menu\ContextualLinkManager</a> @group Menu

Namespace

Drupal\Tests\Core\Menu

Code

public function testGetContextualLinkPluginsByGroupWithCache() : void {
    $definitions = [
        'test_plugin1' => [
            'id' => 'test_plugin1',
            'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
            'group' => 'group1',
            'route_name' => 'test_route',
        ],
        'test_plugin2' => [
            'id' => 'test_plugin2',
            'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
            'group' => 'group1',
            'route_name' => 'test_route2',
        ],
    ];
    $this->cacheBackend
        ->expects($this->once())
        ->method('get')
        ->with('contextual_links_plugins:en:group1')
        ->willReturn((object) [
        'data' => $definitions,
    ]);
    $result = $this->contextualLinkManager
        ->getContextualLinkPluginsByGroup('group1');
    $this->assertEquals($definitions, $result);
    // Ensure that the static cache works, so no second cache get is executed.
    $result = $this->contextualLinkManager
        ->getContextualLinkPluginsByGroup('group1');
    $this->assertEquals($definitions, $result);
}

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