public function EntityDisplayBaseTest::testPreSave in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayBaseTest::testPreSave()
@covers ::preSave
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDisplayBaseTest.php, line 43
Class
- EntityDisplayBaseTest
- @coversDefaultClass \Drupal\Core\Entity\EntityDisplayBase
Namespace
Drupal\KernelTests\Core\EntityCode
public function testPreSave() {
$entity_display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
'content' => [
'foo' => [
'type' => 'visible',
],
'bar' => [
'region' => 'hidden',
],
'name' => [
'type' => 'hidden',
'region' => 'content',
],
],
]);
// Ensure that no region is set on the component.
$this
->assertArrayNotHasKey('region', $entity_display
->getComponent('foo'));
// Ensure that a region is set on the component after saving.
$entity_display
->save();
// The component with a visible type has been assigned a region.
$component = $entity_display
->getComponent('foo');
$this
->assertArrayHasKey('region', $component);
$this
->assertSame('content', $component['region']);
$component = $entity_display
->getComponent('bar');
$this
->assertArrayHasKey('region', $component);
$this
->assertSame('hidden', $component['region']);
// The component with a valid region and hidden type is unchanged.
$component = $entity_display
->getComponent('name');
$this
->assertArrayHasKey('region', $component);
$this
->assertSame('content', $component['region']);
}