Commit 1ffac675 authored by alexpott's avatar alexpott

Issue #2384665 by benjy, penyaskito: Follow-up:...

Issue #2384665 by benjy, penyaskito: Follow-up: FieldConfigBase::calculateDependencies() fatal error is unhelpful
parent aec18afb
......@@ -250,7 +250,7 @@ public function calculateDependencies() {
$bundle_entity_type_id = $this->entityManager()->getDefinition($this->entity_type)->getBundleEntityType();
if ($bundle_entity_type_id != 'bundle') {
if (!$bundle_entity = $this->entityManager()->getStorage($bundle_entity_type_id)->load($this->bundle)) {
throw new \LogicException(String::format('Missing bundle entity, entity type %type, entity id %bundle.', array('%type' => $bundle_entity_type_id, '%id' => $this->bundle)));
throw new \LogicException(String::format('Missing bundle entity, entity type %type, entity id %bundle.', array('%type' => $bundle_entity_type_id, '%bundle' => $this->bundle)));
}
$this->addDependency('config', $bundle_entity->getConfigDependencyName());
}
......
......@@ -174,6 +174,60 @@ public function testCalculateDependencies() {
$this->assertEquals(['test_module', 'test_module2', 'test_module3'], $dependencies['module']);
}
/**
* Test that invalid bundles are handled.
*
* @expectedException \LogicException
* @expectedExceptionMessage Missing bundle entity, entity type <em class="placeholder">bundle_entity_type</em>, entity id <em class="placeholder">test_bundle_not_exists</em>.
*/
public function testCalculateDependenciesIncorrectBundle() {
$storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
$storage->expects($this->any())
->method('load')
->with('test_bundle_not_exists')
->will($this->returnValue(NULL));
$this->entityManager->expects($this->any())
->method('getStorage')
->with('bundle_entity_type')
->will($this->returnValue($storage));
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$target_entity_type->expects($this->any())
->method('getBundleEntityType')
->will($this->returnValue('bundle_entity_type'));
$this->entityManager->expects($this->at(0))
->method('getDefinition')
->with($this->entityTypeId)
->willReturn($this->entityType);
$this->entityManager->expects($this->at(1))
->method('getDefinition')
->with($this->entityTypeId)
->willReturn($this->entityType);
$this->entityManager->expects($this->at(2))
->method('getDefinition')
->with($this->entityTypeId)
->willReturn($this->entityType);
$this->entityManager->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']);
$field = new FieldConfig(array(
'field_name' => $this->fieldStorage->getName(),
'entity_type' => 'test_entity_type',
'bundle' => 'test_bundle_not_exists',
'field_type' => 'test_field',
), $this->entityTypeId);
$field->calculateDependencies();
}
/**
* @covers ::toArray
*/
......
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