public function DefaultsSectionStorageTest::testExtractEntityFromRoute in Drupal 9
Same name and namespace in other branches
- 8 core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php \Drupal\Tests\layout_builder\Unit\DefaultsSectionStorageTest::testExtractEntityFromRoute()
@covers ::extractEntityFromRoute
@dataProvider providerTestExtractEntityFromRoute
Parameters
bool $success: Whether a successful result is expected.
string|null $expected_entity_id: The expected entity ID.
string $value: The value to pass to ::extractEntityFromRoute().
array $defaults: The defaults to pass to ::extractEntityFromRoute().
File
- core/
modules/ layout_builder/ tests/ src/ Unit/ DefaultsSectionStorageTest.php, line 122
Class
- DefaultsSectionStorageTest
- @coversDefaultClass \Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage
Namespace
Drupal\Tests\layout_builder\UnitCode
public function testExtractEntityFromRoute($success, $expected_entity_id, $value, array $defaults) {
if ($expected_entity_id) {
$entity_storage = $this
->prophesize(EntityStorageInterface::class);
$entity_storage
->load($expected_entity_id)
->willReturn('the_return_value');
$this->entityTypeManager
->getDefinition('entity_view_display')
->willReturn(new EntityType([
'id' => 'entity_view_display',
]));
$this->entityTypeManager
->getStorage('entity_view_display')
->willReturn($entity_storage
->reveal());
}
else {
$this->entityTypeManager
->getDefinition('entity_view_display')
->shouldNotBeCalled();
$this->entityTypeManager
->getStorage('entity_view_display')
->shouldNotBeCalled();
}
$method = new \ReflectionMethod($this->plugin, 'extractEntityFromRoute');
$method
->setAccessible(TRUE);
$result = $method
->invoke($this->plugin, $value, $defaults);
if ($success) {
$this
->assertEquals('the_return_value', $result);
}
else {
$this
->assertNull($result);
}
}