You are here

protected function EntityLanguageTestBase::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php \Drupal\system\Tests\Entity\EntityLanguageTestBase::setUp()

Performs setup tasks before each individual test method is run.

Overrides EntityUnitTestBase::setUp

1 call to EntityLanguageTestBase::setUp()
EntityAccessControlHandlerTest::setUp in core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php
Performs setup tasks before each individual test method is run.
1 method overrides EntityLanguageTestBase::setUp()
EntityAccessControlHandlerTest::setUp in core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php
Performs setup tasks before each individual test method is run.

File

core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php, line 49
Contains \Drupal\system\Tests\Entity\EntityLanguageTestBase.

Class

EntityLanguageTestBase
Base class for language-aware entity tests.

Namespace

Drupal\system\Tests\Entity

Code

protected function setUp() {
  parent::setUp();
  $this->languageManager = $this->container
    ->get('language_manager');
  foreach (entity_test_entity_types() as $entity_type_id) {

    // The entity_test schema is installed by the parent.
    if ($entity_type_id != 'entity_test') {
      $this
        ->installEntitySchema($entity_type_id);
    }
  }
  $this
    ->installConfig(array(
    'language',
  ));

  // Create the test field.
  module_load_install('entity_test');
  entity_test_install();

  // Enable translations for the test entity type.
  $this->state
    ->set('entity_test.translation', TRUE);

  // Create a translatable test field.
  $this->fieldName = Unicode::strtolower($this
    ->randomMachineName() . '_field_name');

  // Create an untranslatable test field.
  $this->untranslatableFieldName = Unicode::strtolower($this
    ->randomMachineName() . '_field_name');

  // Create field fields in all entity variations.
  foreach (entity_test_entity_types() as $entity_type) {
    entity_create('field_storage_config', array(
      'field_name' => $this->fieldName,
      'entity_type' => $entity_type,
      'type' => 'text',
      'cardinality' => 4,
    ))
      ->save();
    entity_create('field_config', array(
      'field_name' => $this->fieldName,
      'entity_type' => $entity_type,
      'bundle' => $entity_type,
      'translatable' => TRUE,
    ))
      ->save();
    $this->field[$entity_type] = FieldConfig::load($entity_type . '.' . $entity_type . '.' . $this->fieldName);
    entity_create('field_storage_config', array(
      'field_name' => $this->untranslatableFieldName,
      'entity_type' => $entity_type,
      'type' => 'text',
      'cardinality' => 4,
    ))
      ->save();
    entity_create('field_config', array(
      'field_name' => $this->untranslatableFieldName,
      'entity_type' => $entity_type,
      'bundle' => $entity_type,
      'translatable' => FALSE,
    ))
      ->save();
  }

  // Create the default languages.
  $this
    ->installConfig(array(
    'language',
  ));

  // Create test languages.
  $this->langcodes = array();
  for ($i = 0; $i < 3; ++$i) {
    $language = ConfigurableLanguage::create(array(
      'id' => 'l' . $i,
      'label' => $this
        ->randomString(),
      'weight' => $i,
    ));
    $this->langcodes[$i] = $language
      ->getId();
    $language
      ->save();
  }
}