function FieldConfigEntityUnitTest::testCalculateDependencies

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependencies()
  2. 10 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependencies()
  3. 11.x core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testCalculateDependencies()

@covers ::calculateDependencies

File

core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php, line 117

Class

FieldConfigEntityUnitTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21field%21src%21Entity%21FieldConfig.php/class/FieldConfig/8.9.x" title="Defines the Field entity." class="local">\Drupal\field\Entity\FieldConfig</a> @group field

Namespace

Drupal\Tests\field\Unit

Code

public function testCalculateDependencies() {
    // Mock the interfaces necessary to create a dependency on a bundle entity.
    $target_entity_type = $this->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
    $target_entity_type->expects($this->any())
        ->method('getBundleConfigDependency')
        ->will($this->returnValue([
        'type' => 'config',
        'name' => 'test.test_entity_type.id',
    ]));
    $this->entityTypeManager
        ->expects($this->at(0))
        ->method('getDefinition')
        ->with($this->entityTypeId)
        ->willReturn($this->entityType);
    $this->entityTypeManager
        ->expects($this->at(1))
        ->method('getDefinition')
        ->with($this->entityTypeId)
        ->willReturn($this->entityType);
    $this->entityTypeManager
        ->expects($this->at(2))
        ->method('getDefinition')
        ->with($this->entityTypeId)
        ->willReturn($this->entityType);
    $this->entityTypeManager
        ->expects($this->at(3))
        ->method('getDefinition')
        ->with('test_entity_type')
        ->willReturn($target_entity_type);
    $this->fieldTypePluginManager
        ->expects($this->any())
        ->method('getDefinition')
        ->with('test_field')
        ->willReturn([
        'provider' => 'test_module',
        'config_dependencies' => [
            'module' => [
                'test_module2',
            ],
        ],
        'class' => '\\Drupal\\Tests\\field\\Unit\\DependencyFieldItem',
    ]);
    $this->fieldStorage
        ->expects($this->once())
        ->method('getConfigDependencyName')
        ->will($this->returnValue('field.storage.test_entity_type.test_field'));
    $field = new FieldConfig([
        'field_name' => $this->fieldStorage
            ->getName(),
        'entity_type' => 'test_entity_type',
        'bundle' => 'test_bundle',
        'field_type' => 'test_field',
    ], $this->entityTypeId);
    $dependencies = $field->calculateDependencies()
        ->getDependencies();
    $this->assertContains('field.storage.test_entity_type.test_field', $dependencies['config']);
    $this->assertContains('test.test_entity_type.id', $dependencies['config']);
    $this->assertEquals([
        'test_module',
        'test_module2',
        'test_module3',
    ], $dependencies['module']);
}

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