function LayoutEntityHelperTraitTest::testGetEntitySections

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()
  2. 8.9.x core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testGetEntitySections()
  3. 11.x 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 224

Class

LayoutEntityHelperTraitTest
@coversDefaultClass \Drupal\layout_builder\LayoutEntityHelperTrait[[api-linebreak]]

Namespace

Drupal\Tests\layout_builder\Kernel

Code

public function testGetEntitySections() : void {
  $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));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.