You are here

protected function BooleanFormatterSettingsTest::setUp in Drupal 9

Same name in this branch
  1. 9 core/modules/field/tests/src/Functional/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\Functional\Boolean\BooleanFormatterSettingsTest::setUp()
  2. 9 core/modules/field/tests/src/FunctionalJavascript/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\FunctionalJavascript\Boolean\BooleanFormatterSettingsTest::setUp()
Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/FunctionalJavascript/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\FunctionalJavascript\Boolean\BooleanFormatterSettingsTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/field/tests/src/FunctionalJavascript/Boolean/BooleanFormatterSettingsTest.php, line 45

Class

BooleanFormatterSettingsTest
Tests the Boolean field formatter settings.

Namespace

Drupal\Tests\field\FunctionalJavascript\Boolean

Code

protected function setUp() : void {
  parent::setUp();

  // Create a content type. Use Node because it has Field UI pages that work.
  $type_name = mb_strtolower($this
    ->randomMachineName(8)) . '_test';
  $type = $this
    ->drupalCreateContentType([
    'name' => $type_name,
    'type' => $type_name,
  ]);
  $this->bundle = $type
    ->id();
  $admin_user = $this
    ->drupalCreateUser([
    'access content',
    'administer content types',
    'administer node fields',
    'administer node display',
    'bypass node access',
    'administer nodes',
  ]);
  $this
    ->drupalLogin($admin_user);
  $this->fieldName = mb_strtolower($this
    ->randomMachineName(8));
  $field_storage = FieldStorageConfig::create([
    'field_name' => $this->fieldName,
    'entity_type' => 'node',
    'type' => 'boolean',
  ]);
  $field_storage
    ->save();
  $instance = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => $this->bundle,
    'label' => $this
      ->randomMachineName(),
  ]);
  $instance
    ->save();
  $display = \Drupal::service('entity_display.repository')
    ->getViewDisplay('node', $this->bundle)
    ->setComponent($this->fieldName, [
    'type' => 'boolean',
    'settings' => [],
  ]);
  $display
    ->save();
}