function FieldStorageConfigEntityUnitTest::testCalculateDependencies

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

@covers ::calculateDependencies

File

core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php, line 70

Class

FieldStorageConfigEntityUnitTest
@coversDefaultClass \Drupal\field\Entity\FieldStorageConfig[[api-linebreak]]

Namespace

Drupal\Tests\field\Unit

Code

public function testCalculateDependencies() : void {
  // Create a mock entity type for FieldStorageConfig.
  $fieldStorageConfigentityType = $this->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
  $fieldStorageConfigentityType->expects($this->any())
    ->method('getProvider')
    ->willReturn('field');
  // Create a mock entity type to attach the field to.
  $attached_entity_type_id = $this->randomMachineName();
  $attached_entity_type = $this->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
  $attached_entity_type->expects($this->any())
    ->method('getProvider')
    ->willReturn('entity_provider_module');
  // Get definition is called three times. Twice in
  // ConfigEntityBase::addDependency() to get the provider of the field config
  // entity type and once in FieldStorageConfig::calculateDependencies() to
  // get the provider of the entity type that field is attached to.
  $this->entityTypeManager
    ->expects($this->any())
    ->method('getDefinition')
    ->willReturnMap([
    [
      'field_storage_config',
      TRUE,
      $fieldStorageConfigentityType,
    ],
    [
      $attached_entity_type_id,
      TRUE,
      $attached_entity_type,
    ],
  ]);
  $this->fieldTypeManager
    ->expects($this->atLeastOnce())
    ->method('getDefinition')
    ->with('test_field_type', FALSE)
    ->willReturn([
    'class' => TestFieldType::class,
  ]);
  $field_storage = new FieldStorageConfig([
    'entity_type' => $attached_entity_type_id,
    'field_name' => 'test_field',
    'type' => 'test_field_type',
    'module' => 'test_module',
  ]);
  $dependencies = $field_storage->calculateDependencies()
    ->getDependencies();
  $this->assertEquals([
    'entity_provider_module',
    'entity_test',
    'test_module',
  ], $dependencies['module']);
  $this->assertEquals([
    'stark',
  ], $dependencies['theme']);
}

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