function EntityFormDisplayTest::testEntityGetFromDisplay

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

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

File

core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php, line 46

Class

EntityFormDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\Tests\field_ui\Kernel

Code

public function testEntityGetFromDisplay() : void {
    
    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    // Check that EntityDisplayRepositoryInterface::getFormDisplay() returns a
    // fresh object when no configuration entry exists.
    $form_display = $display_repository->getFormDisplay('entity_test', 'entity_test');
    $this->assertTrue($form_display->isNew());
    // Add some components and save the display.
    $form_display->setComponent('component_1', [
        'weight' => 10,
    ])
        ->save();
    // Check that EntityDisplayRepositoryInterface::getFormDisplay() returns the
    // correct object.
    $form_display = $display_repository->getFormDisplay('entity_test', 'entity_test');
    $this->assertFalse($form_display->isNew());
    $this->assertEquals('entity_test.entity_test.default', $form_display->id());
    $this->assertEquals([
        'weight' => 10,
        'settings' => [],
        'third_party_settings' => [],
        'region' => 'content',
    ], $form_display->getComponent('component_1'));
}

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