You are here

protected function DynamicEntityReferenceItemTest::setUp in Dynamic Entity Reference 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/DynamicEntityReferenceItemTest.php \Drupal\Tests\dynamic_entity_reference\Kernel\DynamicEntityReferenceItemTest::setUp()

Sets up the test.

Overrides FieldKernelTestBase::setUp

File

tests/src/Kernel/DynamicEntityReferenceItemTest.php, line 52

Class

DynamicEntityReferenceItemTest
Tests the new entity API for the dynamic entity reference field type.

Namespace

Drupal\Tests\dynamic_entity_reference\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('taxonomy_term');
  $this->vocabulary = Vocabulary::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => mb_strtolower($this
      ->randomMachineName()),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $this->vocabulary
    ->save();
  $this->term = Term::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => $this->vocabulary
      ->id(),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]);
  $this->term
    ->save();

  // Use the util to create a field.
  FieldStorageConfig::create([
    'field_name' => 'field_der',
    'type' => 'dynamic_entity_reference',
    'entity_type' => 'entity_test',
    'cardinality' => 1,
    'settings' => [
      'exclude_entity_types' => FALSE,
      'entity_type_ids' => [
        'taxonomy_term',
      ],
    ],
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_der',
    'entity_type' => 'entity_test',
    'bundle' => 'entity_test',
    'label' => 'Foo Bar',
    'settings' => [
      'taxonomy_term' => [
        'handler' => 'default:taxonomy_term',
        'handler_settings' => [
          'target_bundles' => NULL,
        ],
      ],
    ],
  ])
    ->save();
}