Commit 94bdf61b authored by catch's avatar catch

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

parent 6fe11acd
......@@ -341,6 +341,9 @@ public function calculateDependencies() {
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;
}
......
......@@ -62,36 +62,55 @@ public static function getInfo() {
* {@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']);
}
}
......@@ -14,4 +14,5 @@ indexes:
- format
dependencies:
module:
- entity_test
- text
......@@ -17,3 +17,4 @@ indexes: { }
dependencies:
module:
- options
- taxonomy
......@@ -21,4 +21,5 @@ status: true
langcode: und
dependencies:
module:
- node
- image
......@@ -18,4 +18,5 @@ status: true
langcode: und
dependencies:
module:
- node
- taxonomy
......@@ -22,3 +22,4 @@ indexes:
dependencies:
module:
- image
- user
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment