function LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage()
  2. 8.9.x core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage()
  3. 11.x 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 188

Class

LayoutEntityHelperTraitTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21layout_builder%21src%21LayoutEntityHelperTrait.php/trait/LayoutEntityHelperTrait/10" title="Methods to help with entities using the layout builder." class="local">\Drupal\layout_builder\LayoutEntityHelperTrait</a>

Namespace

Drupal\Tests\layout_builder\Kernel

Code

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.