function EntityDisplayTest::testEntityGetDisplay

Same name in other branches
  1. 8.9.x core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testEntityGetDisplay()
  2. 10 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testEntityGetDisplay()
  3. 11.x core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testEntityGetDisplay()

@covers \Drupal\Core\Entity\EntityDisplayRepository::getViewDisplay

File

core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php, line 151

Class

EntityDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\Tests\field_ui\Kernel

Code

public function testEntityGetDisplay() {
    $display_repository = $this->container
        ->get('entity_display.repository');
    // Check that getViewDisplay() returns a fresh object when no configuration
    // entry exists.
    $display = $display_repository->getViewDisplay('entity_test', 'entity_test');
    $this->assertTrue($display->isNew());
    // Add some components and save the display.
    $display->setComponent('component_1', [
        'weight' => 10,
        'settings' => [],
    ])
        ->save();
    // Check that getViewDisplay() returns the correct object.
    $display = $display_repository->getViewDisplay('entity_test', 'entity_test');
    $this->assertFalse($display->isNew());
    $this->assertEquals('entity_test.entity_test.default', $display->id());
    $this->assertEquals([
        'weight' => 10,
        'settings' => [],
        'third_party_settings' => [],
        'region' => 'content',
    ], $display->getComponent('component_1'));
}

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