public function LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage in Drupal 9
Same name and namespace in other branches
- 8 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 185
Class
- LayoutEntityHelperTraitTest
- @coversDefaultClass \Drupal\layout_builder\LayoutEntityHelperTrait
Namespace
Drupal\Tests\layout_builder\KernelCode
public function testOriginalEntityUsesDefaultStorage($entity_storages, $is_new, $has_original, $expected) {
$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));
}