function EntityReferenceFieldTest::testEntityReferenceFieldDependencies

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php \Drupal\KernelTests\Core\Entity\EntityReferenceFieldTest::testEntityReferenceFieldDependencies()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php \Drupal\KernelTests\Core\Entity\EntityReferenceFieldTest::testEntityReferenceFieldDependencies()
  3. 11.x 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 425

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->assertEquals([
        '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->assertEquals([
        'config' => [
            'field.storage.entity_test.user_reference_field',
        ],
        'module' => [
            'entity_test',
        ],
    ], $field->getDependencies());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.