You are here

public function EntityDisplayTest::testExtraFieldComponent in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testExtraFieldComponent()
  2. 10 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testExtraFieldComponent()

Tests the behavior of a field component within an entity display object.

File

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

Class

EntityDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\Tests\field_ui\Kernel

Code

public function testExtraFieldComponent() {
  entity_test_create_bundle('bundle_with_extra_fields');
  $display = EntityViewDisplay::create([
    'targetEntityType' => 'entity_test',
    'bundle' => 'bundle_with_extra_fields',
    'mode' => 'default',
  ]);

  // Check that the default visibility taken into account for extra fields
  // unknown in the display.
  $this
    ->assertEqual($display
    ->getComponent('display_extra_field'), [
    'weight' => 5,
    'region' => 'content',
    'settings' => [],
    'third_party_settings' => [],
  ]);
  $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
    ->assertEqual($display
    ->getComponent('display_extra_field_hidden'), [
    'weight' => 10,
    'settings' => [],
    'third_party_settings' => [],
  ]);
}