function EntityFormDisplayTest::testEntityGetFromDisplay

Same name and namespace in other branches
  1. 9 core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityFormDisplayTest::testEntityGetFromDisplay()
  2. 10 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 40

Class

EntityFormDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\Tests\field_ui\Kernel

Code

public function testEntityGetFromDisplay() {
    
    /** @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->assertEqual($form_display->id(), 'entity_test.entity_test.default');
    $this->assertEqual($form_display->getComponent('component_1'), [
        'weight' => 10,
        'settings' => [],
        'third_party_settings' => [],
        'region' => 'content',
    ]);
}

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