function LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage
Same name in other branches
- 9 core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage()
- 8.9.x core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage()
- 10 core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage()
@covers ::originalEntityUsesDefaultStorage
@dataProvider providerTestOriginalEntityUsesDefaultStorage
File
-
core/
modules/ layout_builder/ tests/ src/ Kernel/ LayoutEntityHelperTraitTest.php, line 187
Class
- LayoutEntityHelperTraitTest
- @coversDefaultClass \Drupal\layout_builder\LayoutEntityHelperTrait
Namespace
Drupal\Tests\layout_builder\KernelCode
public function testOriginalEntityUsesDefaultStorage($entity_storages, $is_new, $has_original, $expected) : void {
$this->assertFalse($is_new && $has_original);
$entity = EntityTest::create([
'name' => 'updated',
]);
if (!$is_new) {
$entity->save();
if ($has_original) {
$original_entity = EntityTest::create([
'name' => 'original',
]);
$entity->original = $original_entity;
}
}
$section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class);
$section_storage_manager->load('')
->willReturn(NULL);
$storages = [
'default' => $this->prophesize(DefaultsSectionStorageInterface::class)
->reveal(),
'override' => $this->prophesize(OverridesSectionStorageInterface::class)
->reveal(),
];
$section_storage_manager->findByContext(Argument::cetera())
->will(function ($arguments) use ($storages, $entity_storages) {
$contexts = $arguments[0];
if (isset($contexts['entity'])) {
/** @var \Drupal\entity_test\Entity\EntityTest $entity */
$entity = $contexts['entity']->getContextData()
->getValue();
return $storages[$entity_storages[$entity->getName()]];
}
});
$this->container
->set('plugin.manager.layout_builder.section_storage', $section_storage_manager->reveal());
$class = new TestLayoutEntityHelperTrait();
$this->assertSame($expected, $class->originalEntityUsesDefaultStorage($entity));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.