View source
<?php
namespace Drupal\KernelTests\Core\Entity;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\KernelTests\KernelTestBase;
class LegacyEntityDisplayBaseTest extends KernelTestBase {
public static $modules = [
'entity_test',
'entity_test_third_party',
'field',
'system',
'comment',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('comment');
$this
->installEntitySchema('entity_test');
$this
->installSchema('user', [
'users_data',
]);
}
public function testLegacyPreSave() {
$entity_display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
'content' => [
'foo' => [
'type' => 'visible',
],
'bar' => [
'type' => 'hidden',
],
'name' => [
'type' => 'hidden',
'region' => 'content',
],
],
]);
$this
->assertArrayNotHasKey('region', $entity_display
->getComponent('foo'));
$this
->assertArrayNotHasKey('region', $entity_display
->getComponent('bar'));
$entity_display
->save();
$component = $entity_display
->getComponent('foo');
$this
->assertArrayHasKey('region', $component);
$this
->assertSame('content', $component['region']);
$this
->assertNull($entity_display
->getComponent('bar'));
$component = $entity_display
->getComponent('name');
$this
->assertArrayHasKey('region', $component);
$this
->assertSame('content', $component['region']);
}
public function testHandleHiddenType() {
$entity_display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
'content' => [
'foo' => [
'type' => 'visible',
],
'bar' => [
'type' => 'hidden',
],
'name' => [
'type' => 'hidden',
'region' => 'content',
],
],
]);
$method = new \ReflectionMethod($entity_display, 'handleHiddenType');
$method
->setAccessible(TRUE);
$this
->assertSame([
'type' => 'hidden',
], $entity_display
->getComponent('bar'));
$method
->invoke($entity_display, 'bar', [
'type' => 'hidden',
]);
$this
->assertNull($entity_display
->getComponent('bar'));
}
}