You are here

public function LayoutEntityHelperTraitTest::testGetEntitySections in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testGetEntitySections()

@covers ::getEntitySections

File

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

Class

LayoutEntityHelperTraitTest
@coversDefaultClass \Drupal\layout_builder\LayoutEntityHelperTrait

Namespace

Drupal\Tests\layout_builder\Kernel

Code

public function testGetEntitySections() {
  $entity = EntityTest::create([
    'name' => 'updated',
  ]);
  $section_storage_manager = $this
    ->prophesize(SectionStorageManagerInterface::class);
  $section_storage_manager
    ->load('')
    ->willReturn(NULL);
  $section_storage = $this
    ->prophesize(SectionStorageInterface::class);
  $sections = [
    new Section('layout_onecol'),
  ];
  $this
    ->assertCount(1, $sections);
  $section_storage
    ->getSections()
    ->willReturn($sections);
  $section_storage
    ->count()
    ->willReturn(1);
  $section_storage_manager
    ->findByContext(Argument::cetera())
    ->willReturn($section_storage
    ->reveal());
  $this->container
    ->set('plugin.manager.layout_builder.section_storage', $section_storage_manager
    ->reveal());
  $class = new TestLayoutEntityHelperTrait();

  // Ensure that if the entity has a section storage the sections will be
  // returned.
  $this
    ->assertSame($sections, $class
    ->getEntitySections($entity));
  $section_storage_manager
    ->findByContext(Argument::cetera())
    ->willReturn(NULL);
  $this->container
    ->set('plugin.manager.layout_builder.section_storage', $section_storage_manager
    ->reveal());

  // Ensure that if the entity has no section storage an empty array will be
  // returned.
  $this
    ->assertSame([], $class
    ->getEntitySections($entity));
}