You are here

protected function FieldItemTest::setUp in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Field/FieldItemTest.php \Drupal\system\Tests\Field\FieldItemTest::setUp()

Performs setup tasks before each individual test method is run.

Overrides EntityUnitTestBase::setUp

File

core/modules/system/src/Tests/Field/FieldItemTest.php, line 32
Contains \Drupal\system\Tests\Field\FieldItemTest.

Class

FieldItemTest
Test field item methods.

Namespace

Drupal\system\Tests\Field

Code

protected function setUp() {
  parent::setUp();
  $this->container
    ->get('state')
    ->set('entity_test.field_test_item', TRUE);
  $this->entityManager
    ->clearCachedDefinitions();
  $entity_type_id = 'entity_test_mulrev';
  $this
    ->installEntitySchema($entity_type_id);
  $this->fieldName = Unicode::strtolower($this
    ->randomMachineName());

  /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
  FieldStorageConfig::create([
    'field_name' => $this->fieldName,
    'type' => 'field_test',
    'entity_type' => $entity_type_id,
    'cardinality' => 1,
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => $entity_type_id,
    'field_name' => $this->fieldName,
    'bundle' => $entity_type_id,
    'label' => 'Test field',
  ])
    ->save();
  $this->entityManager
    ->clearCachedDefinitions();
  $definitions = $this->entityManager
    ->getFieldStorageDefinitions($entity_type_id);
  $this
    ->assertTrue(!empty($definitions[$this->fieldName]));
}