You are here

public function ContextualLinkManagerTest::testGetContextualLinkPluginsByGroup in Zircon Profile 8

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

Class

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

Namespace

Drupal\Tests\Core\Menu

Code

public function testGetContextualLinkPluginsByGroup() {
  $definitions = array(
    'test_plugin1' => array(
      'id' => 'test_plugin1',
      'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
      'group' => 'group1',
      'route_name' => 'test_route',
    ),
    'test_plugin2' => array(
      'id' => 'test_plugin2',
      'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
      'group' => 'group1',
      'route_name' => 'test_route2',
    ),
    'test_plugin3' => array(
      'id' => 'test_plugin3',
      'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
      'group' => 'group2',
      'route_name' => 'test_router3',
    ),
  );
  $this->pluginDiscovery
    ->expects($this
    ->once())
    ->method('getDefinitions')
    ->will($this
    ->returnValue($definitions));

  // Test with a non existing group.
  $result = $this->contextualLinkManager
    ->getContextualLinkPluginsByGroup('group_non_existing');
  $this
    ->assertEmpty($result);
  $result = $this->contextualLinkManager
    ->getContextualLinkPluginsByGroup('group1');
  $this
    ->assertEquals(array(
    'test_plugin1',
    'test_plugin2',
  ), array_keys($result));
  $result = $this->contextualLinkManager
    ->getContextualLinkPluginsByGroup('group2');
  $this
    ->assertEquals(array(
    'test_plugin3',
  ), array_keys($result));
}