function FieldDisplayTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/FieldDisplayTest.php \Drupal\Tests\field\Kernel\FieldDisplayTest::setUp()
  2. 10 core/modules/field/tests/src/Kernel/FieldDisplayTest.php \Drupal\Tests\field\Kernel\FieldDisplayTest::setUp()
  3. 11.x core/modules/field/tests/src/Kernel/FieldDisplayTest.php \Drupal\Tests\field\Kernel\FieldDisplayTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/field/tests/src/Kernel/FieldDisplayTest.php, line 61

Class

FieldDisplayTest
Tests Field display.

Namespace

Drupal\Tests\field\Kernel

Code

protected function setUp() {
    parent::setUp();
    // Configure the theme system.
    $this->installConfig([
        'system',
        'field',
    ]);
    $this->installEntitySchema('entity_test_rev');
    $this->entityType = 'entity_test_rev';
    $this->bundle = $this->entityType;
    $this->fieldName = mb_strtolower($this->randomMachineName());
    $field_storage = FieldStorageConfig::create([
        'field_name' => $this->fieldName,
        'entity_type' => $this->entityType,
        'type' => 'string',
    ]);
    $field_storage->save();
    $instance = FieldConfig::create([
        'field_storage' => $field_storage,
        'bundle' => $this->bundle,
        'label' => $this->randomMachineName(),
    ]);
    $instance->save();
    $values = [
        'targetEntityType' => $this->entityType,
        'bundle' => $this->bundle,
        'mode' => 'default',
        'status' => TRUE,
    ];
    $this->display = \Drupal::entityTypeManager()->getStorage('entity_view_display')
        ->create($values);
    $this->display
        ->save();
}

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