function FieldFormatterTest::setUp

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

Overrides KernelTestBase::setUp

File

core/modules/field/tests/src/Kernel/FieldFormatterTest.php, line 50

Class

FieldFormatterTest
Tests for field formatters.

Namespace

Drupal\Tests\field\Kernel

Code

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

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