function EntityDisplayTest::testExtraFieldComponentInitialInvalidConfig

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

Tests the behavior of an extra field component with initial invalid values.

File

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

Class

EntityDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\Tests\field_ui\Kernel

Code

public function testExtraFieldComponentInitialInvalidConfig() {
    entity_test_create_bundle('bundle_with_extra_fields');
    $display = EntityViewDisplay::create([
        'targetEntityType' => 'entity_test',
        'bundle' => 'bundle_with_extra_fields',
        'mode' => 'default',
        // Add the extra field to the initial config, without a 'type'.
'content' => [
            'display_extra_field' => [
                'weight' => 5,
            ],
        ],
    ]);
    // Check that the default visibility taken into account for extra fields
    // unknown in the display that were included in the initial config.
    $this->assertEquals([
        'weight' => 5,
        'region' => 'content',
    ], $display->getComponent('display_extra_field'));
    $this->assertNull($display->getComponent('display_extra_field_hidden'));
    // Check that setting explicit options overrides the defaults.
    $display->removeComponent('display_extra_field');
    $display->setComponent('display_extra_field_hidden', [
        'weight' => 10,
    ]);
    $this->assertNull($display->getComponent('display_extra_field'));
    $this->assertEquals([
        'weight' => 10,
        'settings' => [],
        'third_party_settings' => [],
    ], $display->getComponent('display_extra_field_hidden'));
}

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