function EntityDisplayBaseTest::testPreSave

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayBaseTest::testPreSave()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php \Drupal\KernelTests\Core\Entity\EntityDisplayBaseTest::testPreSave()
  3. 11.x 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 46

Class

EntityDisplayBaseTest
@coversDefaultClass \Drupal\Core\Entity\EntityDisplayBase

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testPreSave() : void {
    $entity_display = EntityViewDisplay::create([
        'targetEntityType' => 'entity_test',
        'bundle' => 'entity_test',
        'mode' => 'default',
        'status' => TRUE,
        'content' => [
            'foo' => [
                'type' => 'field_no_settings',
            ],
            'bar' => [
                'region' => 'hidden',
            ],
            'name' => [
                'type' => 'field_no_settings',
                '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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.