function LayoutEntityHelperTraitTest::testOriginalEntityUsesDefaultStorage

Tests original entity uses default storage.

@legacy-covers ::originalEntityUsesDefaultStorage

Attributes

#[DataProvider('providerTestOriginalEntityUsesDefaultStorage')]

File

core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php, line 190

Class

LayoutEntityHelperTraitTest
Tests Drupal\layout_builder\LayoutEntityHelperTrait.

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->setOriginal($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.