diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php index bde0b2c..405ffa9 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\entity_reference\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldInstanceConfig; use Drupal\system\Tests\Entity\EntityUnitTestBase; @@ -47,14 +48,14 @@ class EntityReferenceFieldTest extends EntityUnitTestBase { /** * A field array. * - * @var array + * @var \Drupal\field\Entity\FieldConfig */ protected $field; /** * An associative array of field instance data. * - * @var array + * @var \Drupal\field\Entity\FieldInstanceConfig */ protected $instance; @@ -116,4 +117,49 @@ public function testEntityReferenceFieldValidation() { // https://drupal.org/node/2064191 is fixed } + /** + * Tests the property definitions of an entity reference field. + */ + public function testEntityReferencePropertyDefinitions() { + $property_names = array_keys($this->field->getPropertyDefinitions()); + $this->assertEqual(array('entity', 'target_id'), sort($property_names)); + + // Set up a new field with the 'target_revision' setting set to TRUE. + // Setup a field and instance. + /** @var \Drupal\field\FieldConfigInterface $field */ + $field = entity_create('field_config', array( + 'name' => $this->fieldName . '_revision', + 'type' => 'entity_reference', + 'entity_type' => $this->entityType, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, + 'settings' => array( + 'target_type' => $this->referencedEntityType, + 'target_revision' => TRUE, + ), + )); + $field->save(); + $property_names = array_keys($field->getPropertyDefinitions()); + $this->assertEqual(array( + 'entity', + 'target_id', + 'target_revision_id', + ), sort($property_names)); + } + + /** + * Tests the schema of an entity reference field. + */ + public function testEntityReferenceSchema() { + $column_names = array_keys($this->field->getColumns()); + $this->assertEqual(array('target_id'), $column_names); + + $this->instance->settings['target_revision'] = TRUE; + $this->instance->save(); + $column_names = array_keys($this->field->getColumns()); + $this->assertEqual(array( + 'target_id', + 'target_revision_id', + ), sort($column_names)); + } + }