Issue #2232597 by alexpott: FieldConfig does not depend on the module the provides the entity type.

8.0.x
Nathaniel Catchpole 2014-04-08 11:31:29 +01:00
parent 6fe11acd22
commit 94bdf61be3
10 changed files with 46 additions and 16 deletions

View File

@ -341,6 +341,9 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
parent::calculateDependencies();
// Ensure the field is dependent on the providing module.
$this->addDependency('module', $this->module);
// Ensure the field is dependent on the provider of the entity type.
$entity_type = \Drupal::entityManager()->getDefinition($this->entity_type);
$this->addDependency('module', $entity_type->getProvider());
return $this->dependencies;
}

View File

@ -62,36 +62,55 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
* {@inheritdoc}
*/
public function setUp() {
$this->entityTypeId = $this->randomName();
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$this->entityType->expects($this->any())
->method('getProvider')
->will($this->returnValue('entity'));
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$this->entityManager->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('uuid', $this->uuid);
\Drupal::setContainer($container);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
$values = array('name' => 'test_field', 'type' => 'test_field_type', 'entity_type' => 'test_entity_type', 'module' => 'test_module');
$entity = new FieldConfig($values, $this->entityTypeId);
$dependencies = $entity->calculateDependencies();
// Create a mock entity type for fieldConfig.
$fieldConfigentityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$fieldConfigentityType->expects($this->any())
->method('getProvider')
->will($this->returnValue('field'));
// Create a mock entity type to attach the field to.
$attached_entity_type_id = $this->randomName();
$attached_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$attached_entity_type->expects($this->any())
->method('getProvider')
->will($this->returnValue('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 FieldConfig::calculateDependencies() to get the
// provider of the entity type that field is attached to.
$this->entityManager->expects($this->at(0))
->method('getDefinition')
->with('fieldConfig')
->will($this->returnValue($fieldConfigentityType));
$this->entityManager->expects($this->at(1))
->method('getDefinition')
->with($attached_entity_type_id)
->will($this->returnValue($attached_entity_type));
$this->entityManager->expects($this->at(2))
->method('getDefinition')
->with('fieldConfig')
->will($this->returnValue($fieldConfigentityType));
$values = array('name' => 'test_field', 'type' => 'test_field_type', 'entity_type' => $attached_entity_type_id, 'module' => 'test_module');
$field = new FieldConfig($values, 'fieldConfig');
$dependencies = $field->calculateDependencies();
$this->assertContains('test_module', $dependencies['module']);
$this->assertContains('entity_provider_module', $dependencies['module']);
}
}

View File

@ -14,4 +14,5 @@ indexes:
- format
dependencies:
module:
- entity_test
- text

View File

@ -14,4 +14,5 @@ indexes:
- format
dependencies:
module:
- entity_test
- text

View File

@ -15,4 +15,5 @@ indexes:
- format
dependencies:
module:
- entity_test
- text

View File

@ -15,4 +15,5 @@ indexes:
- format
dependencies:
module:
- entity_test
- text

View File

@ -17,3 +17,4 @@ indexes: { }
dependencies:
module:
- options
- taxonomy

View File

@ -21,4 +21,5 @@ status: true
langcode: und
dependencies:
module:
- node
- image

View File

@ -18,4 +18,5 @@ status: true
langcode: und
dependencies:
module:
- node
- taxonomy

View File

@ -22,3 +22,4 @@ indexes:
dependencies:
module:
- image
- user