function PluginAlterTest::testPluginAlter

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Render/Element/PluginAlterTest.php \Drupal\KernelTests\Core\Render\Element\PluginAlterTest::testPluginAlter()
  2. 10 core/tests/Drupal/KernelTests/Core/Render/Element/PluginAlterTest.php \Drupal\KernelTests\Core\Render\Element\PluginAlterTest::testPluginAlter()
  3. 11.x core/tests/Drupal/KernelTests/Core/Render/Element/PluginAlterTest.php \Drupal\KernelTests\Core\Render\Element\PluginAlterTest::testPluginAlter()

Tests hook_element_plugin_alter().

File

core/tests/Drupal/KernelTests/Core/Render/Element/PluginAlterTest.php, line 20

Class

PluginAlterTest
@group Render

Namespace

Drupal\KernelTests\Core\Render\Element

Code

public function testPluginAlter() {
    $info_manager = $this->container
        ->get('plugin.manager.element_info');
    $this->assertArrayHasKey('weight', $info_manager->getDefinitions());
    // @see element_info_test_element_plugin_alter()
    $this->container
        ->get('state')
        ->set('hook_element_plugin_alter:remove_weight', TRUE);
    // The definition will be cached.
    $this->assertArrayHasKey('weight', $info_manager->getDefinitions());
    // Clearing the caches removes the definition.
    $info_manager->clearCachedDefinitions();
    $this->assertArrayNotHasKey('weight', $info_manager->getDefinitions());
}

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