Commit e0b25fcb authored by alexpott's avatar alexpott

Issue #2211723 followup by yched, Berdir: FieldInstance::__construct() loads...

Issue #2211723 followup by yched, Berdir: FieldInstance::__construct() loads all field_config entities.
parent 47e74965
......@@ -299,9 +299,7 @@ public function toArray() {
// Additionally, include the field type, that is needed to be able to
// generate the field-type-dependant parts of the config schema.
if (isset($this->field->type)) {
$properties['field_type'] = $this->field->type;
}
$properties['field_type'] = $this->getType();
return $properties;
}
......@@ -506,7 +504,7 @@ public function getName() {
* {@inheritdoc}
*/
public function getType() {
return $this->getField()->type;
return $this->getField()->getType();
}
/**
......
......@@ -90,6 +90,9 @@ function testCreateFieldInstance() {
// Check that default settings are set.
$this->assertEqual($config['settings'], $field_type_manager->getDefaultInstanceSettings($this->field_definition['type']) , 'Default instance settings have been written.');
// Check that the denormalized 'field_type' was properly written.
$this->assertEqual($config['field_type'], $this->field_definition['type']);
// Guarantee that the field/bundle combination is unique.
try {
entity_create('field_instance_config', $this->instance_definition)->save();
......
......@@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\Tests\UnitTestCase;
......@@ -73,27 +74,28 @@ public function setUp() {
$container->set('uuid', $this->uuid);
\Drupal::setContainer($container);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
$field = $this->getMock('\Drupal\field\FieldConfigInterface');
// The field name property is public and accessed this way in the field
// instance config entity constructor.
$field->name = 'test_field';
$field->expects($this->once())
->method('getConfigDependencyName')
->will($this->returnValue('field.field.test_entity_type.test_field'));
// Create a mock FieldConfig object.
$this->field = $this->getMock('\Drupal\field\FieldConfigInterface');
$this->field->expects($this->any())
->method('getType')
->will($this->returnValue('test_field'));
$this->field->expects($this->any())
->method('getName')
->will($this->returnValue('field_test'));
// Place the field in the mocked entity manager's field registry.
$this->entityManager->expects($this->any())
->method('getFieldStorageDefinitions')
->with('test_entity_type')
->will($this->returnValue(array(
$field->name => $field,
$this->field->getName() => $this->field,
)));
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
// Mock the interfaces necessary to create a dependency on a bundle entity.
$bundle_entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
$bundle_entity->expects($this->any())
......@@ -101,8 +103,7 @@ public function testCalculateDependencies() {
->will($this->returnValue('test.test_entity_type.id'));
$storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
$storage
->expects($this->any())
$storage->expects($this->any())
->method('load')
->with('test_bundle')
->will($this->returnValue($bundle_entity));
......@@ -122,11 +123,42 @@ public function testCalculateDependencies() {
->with('test_entity_type')
->will($this->returnValue($target_entity_type));
$values = array('field_name' => 'test_field', 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle');
$this->field->expects($this->once())
->method('getConfigDependencyName')
->will($this->returnValue('field.field.test_entity_type.test_field'));
$values = array('field_name' => $this->field->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle');
$entity = new FieldInstanceConfig($values, $this->entityTypeId);
$dependencies = $entity->calculateDependencies();
$this->assertContains('field.field.test_entity_type.test_field', $dependencies['entity']);
$this->assertContains('test.test_entity_type.id', $dependencies['entity']);
}
/**
* @covers ::toArray()
*/
public function testToArray() {
$values = array('field_name' => $this->field->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle');
$instance = new FieldInstanceConfig($values);
$export = $instance->toArray();
$expected = array(
'id' => 'test_entity_type.test_bundle.field_test',
'uuid' => NULL,
'status' => 1,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'field_uuid' => NULL,
'field_name' => 'field_test',
'entity_type' => 'test_entity_type',
'bundle' => 'test_bundle',
'label' => '',
'description' => '',
'required' => FALSE,
'default_value' => array(),
'default_value_function' => '',
'settings' => array(),
'dependencies' => array(),
'field_type' => 'test_field',
);
$this->assertEquals($expected, $export);
}
}
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