You are here

protected function BooleanFormatterTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/Boolean/BooleanFormatterTest.php \Drupal\Tests\field\Kernel\Boolean\BooleanFormatterTest::setUp()
  2. 9 core/modules/field/tests/src/Kernel/Boolean/BooleanFormatterTest.php \Drupal\Tests\field\Kernel\Boolean\BooleanFormatterTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/field/tests/src/Kernel/Boolean/BooleanFormatterTest.php, line 55

Class

BooleanFormatterTest
Tests the boolean formatter.

Namespace

Drupal\Tests\field\Kernel\Boolean

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installConfig([
    'field',
  ]);
  $this
    ->installEntitySchema('entity_test');
  $this->entityType = 'entity_test';
  $this->bundle = $this->entityType;
  $this->fieldName = mb_strtolower($this
    ->randomMachineName());
  $field_storage = FieldStorageConfig::create([
    'field_name' => $this->fieldName,
    'entity_type' => $this->entityType,
    'type' => 'boolean',
  ]);
  $field_storage
    ->save();
  $instance = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => $this->bundle,
    'label' => $this
      ->randomMachineName(),
  ]);
  $instance
    ->save();
  $this->display = \Drupal::service('entity_display.repository')
    ->getViewDisplay($this->entityType, $this->bundle)
    ->setComponent($this->fieldName, [
    'type' => 'boolean',
    'settings' => [],
  ]);
  $this->display
    ->save();
}