You are here

public function EntityReferenceFieldTest::testEntityReferenceFieldDependencies in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php \Drupal\KernelTests\Core\Entity\EntityReferenceFieldTest::testEntityReferenceFieldDependencies()

Tests the dependencies entity reference fields are created with.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php, line 427

Class

EntityReferenceFieldTest
Tests for the entity reference field.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityReferenceFieldDependencies() {
  $field_name = 'user_reference_field';
  $entity_type = 'entity_test';
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'type' => 'entity_reference',
    'entity_type' => $entity_type,
    'settings' => [
      'target_type' => 'user',
    ],
  ]);
  $field_storage
    ->save();
  $this
    ->assertEqual([
    'module' => [
      'entity_test',
      'user',
    ],
  ], $field_storage
    ->getDependencies());
  $field = FieldConfig::create([
    'field_name' => $field_name,
    'entity_type' => $entity_type,
    'bundle' => 'entity_test',
    'label' => $field_name,
    'settings' => [
      'handler' => 'default',
    ],
  ]);
  $field
    ->save();
  $this
    ->assertEqual([
    'config' => [
      'field.storage.entity_test.user_reference_field',
    ],
    'module' => [
      'entity_test',
    ],
  ], $field
    ->getDependencies());
}