function LayoutEntityHelperTraitTest::testGetSectionStorageForEntity
Same name in other branches
- 9 core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testGetSectionStorageForEntity()
- 8.9.x core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testGetSectionStorageForEntity()
- 11.x core/modules/layout_builder/tests/src/Kernel/LayoutEntityHelperTraitTest.php \Drupal\Tests\layout_builder\Kernel\LayoutEntityHelperTraitTest::testGetSectionStorageForEntity()
@covers ::getSectionStorageForEntity
@dataProvider providerTestGetSectionStorageForEntity
File
-
core/
modules/ layout_builder/ tests/ src/ Kernel/ LayoutEntityHelperTraitTest.php, line 84
Class
- LayoutEntityHelperTraitTest
- @coversDefaultClass \Drupal\layout_builder\LayoutEntityHelperTrait
Namespace
Drupal\Tests\layout_builder\KernelCode
public function testGetSectionStorageForEntity($entity_type_id, $values, $expected_context_keys) : void {
$section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class);
$section_storage_manager->load('')
->willReturn(NULL);
$section_storage_manager->findByContext(Argument::cetera())
->will(function ($arguments) {
return $arguments[0];
});
$this->container
->set('plugin.manager.layout_builder.section_storage', $section_storage_manager->reveal());
$entity = $this->container
->get('entity_type.manager')
->getStorage($entity_type_id)
->create($values);
$entity->save();
$class = new TestLayoutEntityHelperTrait();
$result = $class->getSectionStorageForEntity($entity);
$this->assertEquals($expected_context_keys, array_keys($result));
if ($entity instanceof EntityViewDisplayInterface) {
$this->assertEquals(EntityContext::fromEntity($entity), $result['display']);
}
elseif ($entity instanceof FieldableEntityInterface) {
$this->assertEquals(EntityContext::fromEntity($entity), $result['entity']);
$this->assertInstanceOf(Context::class, $result['view_mode']);
$this->assertEquals('full', $result['view_mode']->getContextData()
->getValue());
$expected_display = EntityViewDisplay::collectRenderDisplay($entity, 'full');
$this->assertInstanceOf(EntityContext::class, $result['display']);
/** @var \Drupal\Core\Plugin\Context\EntityContext $display_entity_context */
$display_entity_context = $result['display'];
/** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $display_entity */
$display_entity = $display_entity_context->getContextData()
->getValue();
$this->assertInstanceOf(LayoutBuilderEntityViewDisplay::class, $display_entity);
$this->assertEquals('full', $display_entity->getMode());
$this->assertEquals($expected_display->getEntityTypeId(), $display_entity->getEntityTypeId());
$this->assertEquals($expected_display->getComponents(), $display_entity->getComponents());
$this->assertEquals($expected_display->getThirdPartySettings('layout_builder'), $display_entity->getThirdPartySettings('layout_builder'));
}
else {
throw new \UnexpectedValueException("Unexpected entity type.");
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.