function TranslationWebTest::setUp

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

Overrides BrowserTestBase::setUp

File

core/modules/field/tests/src/Functional/TranslationWebTest.php, line 57

Class

TranslationWebTest
Tests multilanguage fields logic that require a full environment.

Namespace

Drupal\Tests\field\Functional

Code

protected function setUp() {
    parent::setUp();
    $this->fieldName = mb_strtolower($this->randomMachineName() . '_field_name');
    $field_storage = [
        'field_name' => $this->fieldName,
        'entity_type' => $this->entityTypeId,
        'type' => 'test_field',
        'cardinality' => 4,
    ];
    FieldStorageConfig::create($field_storage)->save();
    $this->fieldStorage = FieldStorageConfig::load($this->entityTypeId . '.' . $this->fieldName);
    $field = [
        'field_storage' => $this->fieldStorage,
        'bundle' => $this->entityTypeId,
    ];
    FieldConfig::create($field)->save();
    $this->field = FieldConfig::load($this->entityTypeId . '.' . $field['bundle'] . '.' . $this->fieldName);
    \Drupal::service('entity_display.repository')->getFormDisplay($this->entityTypeId, $this->entityTypeId)
        ->setComponent($this->fieldName)
        ->save();
    for ($i = 0; $i < 3; ++$i) {
        ConfigurableLanguage::create([
            'id' => 'l' . $i,
            'label' => $this->randomString(),
        ])
            ->save();
    }
}

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