function ContextualLinkManagerTest::testGetContextualLinkPluginsByGroup

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

Tests the getContextualLinkPluginsByGroup method.

See also

\Drupal\Core\Menu\ContextualLinkManager::getContextualLinkPluginsByGroup()

File

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

Class

ContextualLinkManagerTest
@coversDefaultClass \Drupal\Core\Menu\ContextualLinkManager @group Menu

Namespace

Drupal\Tests\Core\Menu

Code

public function testGetContextualLinkPluginsByGroup() {
    $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',
        ],
        'test_plugin3' => [
            'id' => 'test_plugin3',
            'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
            'group' => 'group2',
            'route_name' => 'test_router3',
        ],
    ];
    $this->pluginDiscovery
        ->expects($this->once())
        ->method('getDefinitions')
        ->willReturn($definitions);
    // Test with a non existing group.
    $result = $this->contextualLinkManager
        ->getContextualLinkPluginsByGroup('group_non_existing');
    $this->assertEmpty($result);
    $result = $this->contextualLinkManager
        ->getContextualLinkPluginsByGroup('group1');
    $this->assertEquals([
        'test_plugin1',
        'test_plugin2',
    ], array_keys($result));
    $result = $this->contextualLinkManager
        ->getContextualLinkPluginsByGroup('group2');
    $this->assertEquals([
        'test_plugin3',
    ], array_keys($result));
}

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