function EntityMethodConfigActionsTest::testRemoveComponentFromDisplay
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Recipe/EntityMethodConfigActionsTest.php \Drupal\KernelTests\Core\Recipe\EntityMethodConfigActionsTest::testRemoveComponentFromDisplay()
Tests remove component from display.
Attributes
#[TestWith([
"hideComponent",
])]
#[TestWith([
"hideComponents",
])]
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ EntityMethodConfigActionsTest.php, line 176
Class
- EntityMethodConfigActionsTest
- Tests entity method config actions.
Namespace
Drupal\KernelTests\Core\RecipeCode
public function testRemoveComponentFromDisplay(string $action_name) : void {
$this->assertStringStartsWith('hideComponent', $action_name);
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $repository */
$repository = $this->container
->get(EntityDisplayRepositoryInterface::class);
$view_display = $repository->getViewDisplay('entity_test_with_bundle', 'test');
$this->assertIsArray($view_display->getComponent('name'));
// The `hideComponent` action is an alias for `removeComponent`, proving
// that entity methods can be aliased.
$this->configActionManager
->applyAction("entity_method:core.entity_view_display:{$action_name}", $view_display->getConfigDependencyName(), $action_name === 'hideComponents' ? [
'name',
] : 'name');
$view_display = $repository->getViewDisplay('entity_test_with_bundle', 'test');
$this->assertNull($view_display->getComponent('name'));
// The underlying action name should not be available. It should be hidden
// by the alias.
$plugin_id = str_replace('hide', 'remove', $action_name);
$this->assertFalse($this->configActionManager
->hasDefinition($plugin_id));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.