public function OverridesSectionStorageTest::testGetSectionListFromId in Drupal 8
@covers ::getSectionListFromId
@dataProvider providerTestGetSectionListFromId
@expectedDeprecation \Drupal\layout_builder\SectionStorageInterface::getSectionListFromId() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. The section list should be derived from context. See https://www.drupal.org/node/3016262.
@group legacy
File
- core/
modules/ layout_builder/ tests/ src/ Unit/ OverridesSectionStorageTest.php, line 129
Class
- OverridesSectionStorageTest
- @coversDefaultClass \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage
Namespace
Drupal\Tests\layout_builder\UnitCode
public function testGetSectionListFromId($success, $expected_entity_type_id, $id) {
$defaults['the_parameter_name'] = $id;
if ($expected_entity_type_id) {
$entity_without_layout = $this
->prophesize(FieldableEntityInterface::class);
$entity_without_layout
->hasField(OverridesSectionStorage::FIELD_NAME)
->willReturn(FALSE);
$entity_without_layout
->get(OverridesSectionStorage::FIELD_NAME)
->shouldNotBeCalled();
$this->entityRepository
->getActive('my_entity_type', 'entity_without_layout')
->willReturn($entity_without_layout
->reveal());
$entity_with_layout = $this
->prophesize(FieldableEntityInterface::class);
$entity_with_layout
->hasField(OverridesSectionStorage::FIELD_NAME)
->willReturn(TRUE);
$entity_with_layout
->get(OverridesSectionStorage::FIELD_NAME)
->willReturn('the_return_value');
$this->entityRepository
->getActive('my_entity_type', 'entity_with_layout')
->willReturn($entity_with_layout
->reveal());
$entity_type = new EntityType([
'id' => $expected_entity_type_id,
]);
$this->entityTypeManager
->getDefinition($expected_entity_type_id)
->willReturn($entity_type);
}
else {
$this->entityTypeManager
->getStorage(Argument::any())
->shouldNotBeCalled();
$this->entityTypeManager
->getDefinition(Argument::any())
->shouldNotBeCalled();
}
if (!$success) {
$this
->expectException(\InvalidArgumentException::class);
}
$result = $this->plugin
->getSectionListFromId($id);
if ($success) {
$this
->assertEquals('the_return_value', $result);
}
}