You are here

protected function TranslationWebTest::setUp in Drupal 8

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()

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