function ContextualLinkManagerTest::testGetContextualLinksArrayByGroup
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::testGetContextualLinksArrayByGroup()
- 10 core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::testGetContextualLinksArrayByGroup()
- 11.x core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php \Drupal\Tests\Core\Menu\ContextualLinkManagerTest::testGetContextualLinksArrayByGroup()
Tests the getContextualLinksArrayByGroup method.
See also
\Drupal\Core\Menu\ContextualLinkManager::getContextualLinksArrayByGroup()
File
-
core/
tests/ Drupal/ Tests/ Core/ Menu/ ContextualLinkManagerTest.php, line 240
Class
- ContextualLinkManagerTest
- @coversDefaultClass \Drupal\Core\Menu\ContextualLinkManager @group Menu
Namespace
Drupal\Tests\Core\MenuCode
public function testGetContextualLinksArrayByGroup() {
$definitions = [
'test_plugin1' => [
'id' => 'test_plugin1',
'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
'title' => 'Plugin 1',
'weight' => 0,
'group' => 'group1',
'route_name' => 'test_route',
'options' => [],
],
'test_plugin2' => [
'id' => 'test_plugin2',
'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
'title' => 'Plugin 2',
'weight' => 2,
'group' => 'group1',
'route_name' => 'test_route2',
'options' => [
'key' => 'value',
],
],
'test_plugin3' => [
'id' => 'test_plugin3',
'class' => '\\Drupal\\Core\\Menu\\ContextualLinkDefault',
'title' => 'Plugin 3',
'weight' => 5,
'group' => 'group2',
'route_name' => 'test_router3',
'options' => [],
],
];
$this->pluginDiscovery
->expects($this->once())
->method('getDefinitions')
->will($this->returnValue($definitions));
$this->accessManager
->expects($this->any())
->method('checkNamedRoute')
->will($this->returnValue(AccessResult::allowed()));
// Set up mocking of the plugin factory.
$map = [];
foreach ($definitions as $plugin_id => $definition) {
$map[] = [
$plugin_id,
[],
new ContextualLinkDefault([], $plugin_id, $definition),
];
}
$this->factory
->expects($this->any())
->method('createInstance')
->will($this->returnValueMap($map));
$this->moduleHandler
->expects($this->at(1))
->method('alter')
->with($this->equalTo('contextual_links'), new Count(2), $this->equalTo('group1'), $this->equalTo([
'key' => 'value',
]));
$result = $this->contextualLinkManager
->getContextualLinksArrayByGroup('group1', [
'key' => 'value',
]);
$this->assertCount(2, $result);
foreach ([
'test_plugin1',
'test_plugin2',
] as $plugin_id) {
$definition = $definitions[$plugin_id];
$this->assertEquals($definition['weight'], $result[$plugin_id]['weight']);
$this->assertEquals($definition['title'], $result[$plugin_id]['title']);
$this->assertEquals($definition['route_name'], $result[$plugin_id]['route_name']);
$this->assertEquals($definition['options'], $result[$plugin_id]['localized_options']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.