function EntityCloneConfigActionTest::testCloneEntityDisplay
Tests cloning entity displays, which have specialized logic for that.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ EntityCloneConfigActionTest.php, line 98
Class
- EntityCloneConfigActionTest
- @covers \Drupal\Core\Config\Action\Plugin\ConfigAction\EntityClone @group Recipe
Namespace
Drupal\KernelTests\Core\RecipeCode
public function testCloneEntityDisplay() : void {
$this->container
->get(ModuleInstallerInterface::class)
->install([
'node',
]);
$this->createContentType([
'type' => 'alpha',
]);
$this->createContentType([
'type' => 'beta',
]);
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = $this->container
->get(EntityDisplayRepositoryInterface::class);
// Create the default view displays for each node type.
$display_repository->getViewDisplay('node', 'alpha')
->save();
$display_repository->getViewDisplay('node', 'beta')
->save();
// Ensure the `rss` displays don't exist yet.
$this->assertTrue($display_repository->getViewDisplay('node', 'alpha', 'rss')
->isNew());
$this->assertTrue($display_repository->getViewDisplay('node', 'beta', 'rss')
->isNew());
// Use the action to clone the default view displays to the `rss` view mode.
/** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
$manager = $this->container
->get('plugin.manager.config_action');
$manager->applyAction('cloneAs', 'core.entity_view_display.node.alpha.default', 'node.alpha.rss');
$manager->applyAction('entity_method:core.entity_view_display:createCopy', 'core.entity_view_display.node.beta.default', 'rss');
$this->assertFalse($display_repository->getViewDisplay('node', 'alpha', 'rss')
->isNew());
$this->assertFalse($display_repository->getViewDisplay('node', 'beta', 'rss')
->isNew());
// Ensure that this also works with wildcards.
$this->assertTrue($display_repository->getViewDisplay('node', 'alpha', 'search_result')
->isNew());
$this->assertTrue($display_repository->getViewDisplay('node', 'beta', 'search_result')
->isNew());
$manager->applyAction('entity_method:core.entity_view_display:createCopy', 'core.entity_view_display.node.*.default', 'search_result');
$this->assertFalse($display_repository->getViewDisplay('node', 'alpha', 'search_result')
->isNew());
$this->assertFalse($display_repository->getViewDisplay('node', 'beta', 'search_result')
->isNew());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.