public function InfoAlterTest::testLinkAttributesManagerInfoAlter in Link Attributes widget 8
Tests that plugin definition is changed with alterInfo.
Tests that info data is changed after a module that implements hook_link_attributes_plugin_alter() is enabled.
File
- tests/
src/ Kernel/ InfoAlterTest.php, line 29
Class
- InfoAlterTest
- Tests link_attributes_plugin alterInfo.
Namespace
Drupal\Tests\link_attributes\KernelCode
public function testLinkAttributesManagerInfoAlter() {
/** @var \Drupal\link_attributes\LinkAttributesManager $linkAttributesManager */
$linkAttributesManager = $this->container
->get('plugin.manager.link_attributes');
$definition = $linkAttributesManager
->getDefinitions();
$this
->assertEquals('textfield', $definition['class']['type'], 'Without altering the plugin definition the class attribute is a textfield.');
// Set our flag to alter the plugin definition in
// link_attributes_test_alterinfo module.
\Drupal::state()
->set('link_attributes_test_alterinfo.hook_link_attributes_plugin_alter', TRUE);
$linkAttributesManager
->clearCachedDefinitions();
$definition = $linkAttributesManager
->getDefinitions();
$this
->assertEquals('select', $definition['class']['type'], 'After altering the plugin definition the class attribute is a select.');
$this
->assertArrayHasKey('button', $definition['class']['options']);
}