function BooleanFormatterSettingsTest::setUp

Same name in this branch
  1. 11.x core/modules/field/tests/src/Functional/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\Functional\Boolean\BooleanFormatterSettingsTest::setUp()
Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/FunctionalJavascript/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\FunctionalJavascript\Boolean\BooleanFormatterSettingsTest::setUp()
  2. 9 core/modules/field/tests/src/Functional/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\Functional\Boolean\BooleanFormatterSettingsTest::setUp()
  3. 8.9.x core/modules/field/tests/src/FunctionalJavascript/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\FunctionalJavascript\Boolean\BooleanFormatterSettingsTest::setUp()
  4. 8.9.x core/modules/field/tests/src/Functional/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\Functional\Boolean\BooleanFormatterSettingsTest::setUp()
  5. 10 core/modules/field/tests/src/FunctionalJavascript/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\FunctionalJavascript\Boolean\BooleanFormatterSettingsTest::setUp()
  6. 10 core/modules/field/tests/src/Functional/Boolean/BooleanFormatterSettingsTest.php \Drupal\Tests\field\Functional\Boolean\BooleanFormatterSettingsTest::setUp()

Overrides BrowserTestBase::setUp

File

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

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 = $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 = $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();
}

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