Commit d0d18177 authored by alexpott's avatar alexpott

Issue #1822000 by Berdir, plach, amateescu, yched: Remove...

Issue #1822000 by Berdir, plach, amateescu, yched: Remove Drupal\field_test\Plugin\Entity\Type\TestEntity in favor of EntityTest.
parent 760292ee
......@@ -235,6 +235,13 @@ protected function getTranslatedField($property_name, $langcode) {
if (isset($this->values[$property_name][$langcode])) {
$value = $this->values[$property_name][$langcode];
}
// @todo Remove this once the BC decorator is gone.
elseif ($property_name != 'langcode') {
$default_langcode = $this->language()->langcode;
if ($langcode == Language::LANGCODE_DEFAULT && isset($this->values[$property_name][$default_langcode])) {
$value = $this->values[$property_name][$default_langcode];
}
}
$this->fields[$property_name][$langcode] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
}
}
......
......@@ -900,16 +900,9 @@ function field_attach_update(EntityInterface $entity) {
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['uuid'];
$field_name = $field['field_name'];
// Leave the field untouched if $entity comes with no $field_name property,
// but empty the field if it comes as a NULL value or an empty array.
// Function property_exists() is slower, so we catch the more frequent
// cases where it's an empty array with the faster isset().
if (isset($entity->$field_name) || property_exists($entity, $field_name)) {
// Collect the storage backend if the field has not been written yet.
if (!isset($skip_fields[$field_id])) {
$storages[$field['storage']['type']][$field_id] = $field_id;
}
// Collect the storage backend if the field has not been written yet.
if (!isset($skip_fields[$field_id])) {
$storages[$field['storage']['type']][$field_id] = $field_id;
}
}
......
......@@ -657,6 +657,9 @@ function _field_filter_xss_display_allowed_tags() {
function field_view_value(EntityInterface $entity, $field_name, $item, $display = array(), $langcode = NULL) {
$output = array();
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
if ($field = field_info_field($field_name)) {
// Determine the langcode that will be used by language fallback.
$langcode = field_language($entity, $field_name, $langcode);
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
......@@ -59,36 +60,6 @@ public static function getInfo() {
);
}
/**
* Converts the passed entities to partially created ones.
*
* This replicates the partial entities created in field_purge_data_batch(),
* which only have the ids and the to be deleted field defined.
*
* @param $entities
* An array of entities of type test_entity.
* @param $field_name
* A field name whose data should be copied from $entities into the returned
* partial entities.
* @return array An array of partial entities corresponding to $entities.
*/
protected function convertToPartialEntities($entities, $field_name) {
$partial_entities = array();
foreach ($entities as $id => $entity) {
// Re-create the entity to match what is expected
// _field_create_entity_from_ids().
$ids = (object) array(
'entity_id' => $entity->ftid,
'revision_id' => $entity->ftvid,
'bundle' => $entity->fttype,
'entity_type' => 'test_entity',
);
$partial_entities[$id] = _field_create_entity_from_ids($ids);
$partial_entities[$id]->$field_name = $entity->$field_name;
}
return $partial_entities;
}
/**
* Tests that the expected hooks have been invoked on the expected entities.
*
......@@ -110,8 +81,15 @@ function checkHooksInvocations($expected_hooks, $actual_hooks) {
foreach ($invocations as $argument) {
$found = FALSE;
foreach ($actual_invocations as $actual_arguments) {
// $entity is sometimes the first and sometimes the second argument.
if ($actual_arguments[0] == $argument || $actual_arguments[1] == $argument) {
// The argument we are looking for is either an array of entities as
// the second argument or a single entity object as the first.
if ($argument instanceof EntityInterface && $actual_arguments[0]->id() == $argument->id()) {
$found = TRUE;
break;
}
// In case of an array, compare the array size and make sure it
// contains the same elements.
elseif (is_array($argument) && count($actual_arguments[1]) == count($argument) && count(array_diff_key($actual_arguments[1], $argument)) == 0) {
$found = TRUE;
break;
}
......@@ -131,7 +109,7 @@ function setUp() {
// Create two bundles.
$this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2');
foreach ($this->bundles as $name => $desc) {
field_test_create_bundle($name, $desc);
entity_test_create_bundle($name, $desc);
}
// Create two fields.
......@@ -152,7 +130,7 @@ function setUp() {
// For each bundle, create an instance of each field, and 10
// entities with values for each field.
$id = 1;
$this->entity_type = 'entity_test';
foreach ($this->bundles as $bundle) {
foreach ($this->fields as $field) {
entity_create('field_instance', array(
......@@ -161,20 +139,18 @@ function setUp() {
'bundle' => $bundle,
))->save();
}
for ($i = 0; $i < 10; $i++) {
$entity = field_test_create_entity($id, $id, $bundle);
$entity = entity_create($this->entity_type, array('type' => $bundle));
foreach ($this->fields as $field) {
$entity->{$field->id()}[Language::LANGCODE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field->cardinality);
$entity->{$field['field_name']}->setValue($this->_generateTestFieldValues($field->cardinality));
}
$entity->save();
$id++;
}
}
$this->entities = entity_load_multiple($this->entity_type, range(1, $id));
$this->entities = entity_load_multiple($this->entity_type);
foreach ($this->entities as $entity) {
// Also keep track of the entities per bundle.
$this->entities_by_bundles[$entity->fttype][$entity->ftid] = $entity;
$this->entities_by_bundles[$entity->bundle()][$entity->id()] = $entity;
}
}
......@@ -193,8 +169,8 @@ function testDeleteFieldInstance() {
$factory = \Drupal::service('entity.query');
// There are 10 entities of this bundle.
$found = $factory->get('test_entity')
->condition('fttype', $bundle)
$found = $factory->get('entity_test')
->condition('type', $bundle)
->execute();
$this->assertEqual(count($found), 10, 'Correct number of entities found before deleting');
......@@ -209,21 +185,21 @@ function testDeleteFieldInstance() {
$this->assertEqual($instance['bundle'], $bundle, 'The deleted instance is for the correct bundle');
// There are 0 entities of this bundle with non-deleted data.
$found = $factory->get('test_entity')
->condition('fttype', $bundle)
$found = $factory->get('entity_test')
->condition('type', $bundle)
->condition("$field_name.deleted", 0)
->execute();
$this->assertFalse($found, 'No entities found after deleting');
// There are 10 entities of this bundle when deleted fields are allowed, and
// their values are correct.
$found = $factory->get('test_entity')
->condition('fttype', $bundle)
$found = $factory->get('entity_test')
->condition('type', $bundle)
->condition("$field_name.deleted", 1)
->sort('ftid')
->sort('id')
->execute();
$ids = (object) array(
'entity_type' => 'test_entity',
'entity_type' => 'entity_test',
'bundle' => $bundle,
);
$entities = array();
......@@ -234,7 +210,7 @@ function testDeleteFieldInstance() {
field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('instance' => $instance));
$this->assertEqual(count($found), 10, 'Correct number of entities found after deleting');
foreach ($entities as $id => $entity) {
$this->assertEqual($this->entities[$id]->{$field->id()}, $entity->{$field->id()}, "Entity $id with deleted data loaded correctly");
$this->assertEqual($this->entities[$id]->{$field->id()}->value, $entity->{$field->id()}[Language::LANGCODE_NOT_SPECIFIED][0]['value'], "Entity $id with deleted data loaded correctly");
}
}
......@@ -263,8 +239,8 @@ function testPurgeInstance() {
field_purge_batch($batch_size);
// There are $count deleted entities left.
$found = \Drupal::entityQuery('test_entity')
->condition('fttype', $bundle)
$found = \Drupal::entityQuery('entity_test')
->condition('type', $bundle)
->condition($field->id() . '.deleted', 1)
->execute();
$this->assertEqual(count($found), $count, 'Correct number of entities found after purging 2');
......@@ -275,7 +251,7 @@ function testPurgeInstance() {
// for each entity in the bundle.
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id());
$entities = $this->entities_by_bundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_load'][] = array($id => $entity);
$hooks['field_test_field_delete'][] = $entity;
......@@ -325,7 +301,7 @@ function testPurgeField() {
// for each entity in the bundle.
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id());
$entities = $this->entities_by_bundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_load'][] = array($id => $entity);
$hooks['field_test_field_delete'][] = $entity;
......@@ -354,7 +330,7 @@ function testPurgeField() {
// Check hooks invocations (same as above, for the 2nd bundle).
$actual_hooks = field_test_memorize();
$hooks = array();
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->id());
$entities = $this->entities_by_bundles[$bundle];
foreach ($entities as $id => $entity) {
$hooks['field_test_field_load'][] = array($id => $entity);
$hooks['field_test_field_delete'][] = $entity;
......
......@@ -139,11 +139,11 @@ function testCreateField() {
}
// Check that field name can not be an entity key.
// "ftvid" is known as an entity key from the "test_entity" type.
// "id" is known as an entity key from the "entity_test" type.
try {
$field_definition = array(
'type' => 'test_field',
'field_name' => 'ftvid',
'field_name' => 'id',
);
entity_create('field_entity', $field_definition)->save();
$this->fail(t('Cannot create a field bearing the name of an entity key.'));
......@@ -216,8 +216,8 @@ function testReadFields() {
// Create an instance of the field.
$instance_definition = array(
'field_name' => $field_definition['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
entity_create('field_instance', $instance_definition)->save();
}
......@@ -283,8 +283,8 @@ function testDeleteField() {
// Create instances for each.
$this->instance_definition = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
entity_create('field_instance', $this->instance_definition)->save();
$another_instance_definition = $this->instance_definition;
......@@ -303,7 +303,7 @@ function testDeleteField() {
// Make sure that this field's instance is marked as deleted when it is
// specifically loaded.
$instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
$this->assertTrue(!empty($instance['deleted']), 'An instance for a deleted field is marked for deletion.');
// Try to load the field normally and make sure it does not show up.
......@@ -311,13 +311,13 @@ function testDeleteField() {
$this->assertTrue(empty($field), 'A deleted field is not loaded by default.');
// Try to load the instance normally and make sure it does not show up.
$instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue(empty($instance), 'An instance for a deleted field is not loaded by default.');
// Make sure the other field (and its field instance) are not deleted.
$another_field = field_read_field($this->another_field['field_name']);
$this->assertTrue(!empty($another_field) && empty($another_field['deleted']), 'A non-deleted field is not marked for deletion.');
$another_instance = field_read_instance('test_entity', $another_instance_definition['field_name'], $another_instance_definition['bundle']);
$another_instance = field_read_instance('entity_test', $another_instance_definition['field_name'], $another_instance_definition['bundle']);
$this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), 'An instance of a non-deleted field is not marked for deletion.');
// Try to create a new field the same name as a deleted field and
......@@ -326,23 +326,22 @@ function testDeleteField() {
entity_create('field_instance', $this->instance_definition)->save();
$field = field_read_field($this->field['field_name']);
$this->assertTrue(!empty($field) && empty($field['deleted']), 'A new field with a previously used name is created.');
$instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue(!empty($instance) && empty($instance['deleted']), 'A new instance for a previously used field name is created.');
// Save an entity with data for the field
$entity = field_test_create_entity(0, 0, $instance['bundle']);
$entity = entity_create('entity_test', array('id' => 0, 'revision_id' => 0));
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$values[0]['value'] = mt_rand(1, 127);
$entity->{$field['field_name']}[$langcode] = $values;
$entity_type = 'test_entity';
$entity->{$field['field_name']}->value = $values[0]['value'];
field_attach_insert($entity);
// Verify the field is present on load
$entity = field_test_create_entity(0, 0, $this->instance_definition['bundle']);
field_attach_load($entity_type, array(0 => $entity));
$this->assertIdentical(count($entity->{$field['field_name']}[$langcode]), count($values), "Data in previously deleted field saves and loads correctly");
$entity = entity_create('entity_test', array('id' => 0, 'revision_id' => 0));
field_attach_load('entity_test', array(0 => $entity));
$this->assertIdentical(count($entity->{$field['field_name']}), count($values), "Data in previously deleted field saves and loads correctly");
foreach ($values as $delta => $value) {
$this->assertEqual($entity->{$field['field_name']}[$langcode][$delta]['value'], $values[$delta]['value'], "Data in previously deleted field saves and loads correctly");
$this->assertEqual($entity->{$field['field_name']}[$delta]->value, $values[$delta]['value'], "Data in previously deleted field saves and loads correctly");
}
}
......@@ -377,28 +376,28 @@ function testUpdateField() {
$field->save();
$instance = entity_create('field_instance', array(
'field_name' => 'field_update',
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
));
$instance->save();
do {
// We need a unique ID for our entity. $cardinality will do.
$id = $cardinality;
$entity = field_test_create_entity($id, $id, $instance->bundle);
$entity = entity_create('entity_test', array('id' => $id, 'revision_id' => $id));
// Fill in the entity with more values than $cardinality.
for ($i = 0; $i < 20; $i++) {
$entity->field_update[Language::LANGCODE_NOT_SPECIFIED][$i]['value'] = $i;
$entity->field_update[$i]->value = $i;
}
// Save the entity.
field_attach_insert($entity);
// Load back and assert there are $cardinality number of values.
$entity = field_test_create_entity($id, $id, $instance->bundle);
field_attach_load('test_entity', array($id => $entity));
$this->assertEqual(count($entity->field_update[Language::LANGCODE_NOT_SPECIFIED]), $field->cardinality, 'Cardinality is kept');
$entity = entity_create('entity_test', array('id' => $id, 'revision_id' => $id));
field_attach_load('entity_test', array($id => $entity));
$this->assertEqual(count($entity->field_update), $field->cardinality, 'Cardinality is kept');
// Now check the values themselves.
for ($delta = 0; $delta < $cardinality; $delta++) {
$this->assertEqual($entity->field_update[Language::LANGCODE_NOT_SPECIFIED][$delta]['value'], $delta, 'Value is kept');
$this->assertEqual($entity->field_update[$delta]->value, $delta, 'Value is kept');
}
// Increase $cardinality and set the field cardinality to the new value.
$field->cardinality = ++$cardinality;
......
......@@ -40,7 +40,7 @@ class DisplayApiTest extends FieldUnitTestBase {
protected $display_options;
/**
* The field display options to use in this test.
* The test entity.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
......@@ -76,8 +76,8 @@ function setUp() {
);
$instance = array(
'field_name' => $this->field_name,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $this->label,
);
......@@ -109,10 +109,9 @@ function setUp() {
// Create an entity with values.
$this->values = $this->_generateTestFieldValues($this->cardinality);
$this->entity = field_test_create_entity();
$this->is_new = TRUE;
$this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED] = $this->values;
field_test_entity_save($this->entity);
$this->entity = entity_create('entity_test', array());
$this->entity->{$this->field_name}->setValue($this->values);
$this->entity->save();
}
/**
......@@ -197,7 +196,7 @@ function testFieldViewValue() {
$settings = field_info_formatter_settings('field_test_default');
$setting = $settings['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item);
$this->content = drupal_render($output);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -213,7 +212,7 @@ function testFieldViewValue() {
$setting = $display['settings']['test_formatter_setting_multiple'];
$array = array();
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item, $display);
$this->content = drupal_render($output);
$this->assertText($setting . '|0:' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -229,7 +228,7 @@ function testFieldViewValue() {
$setting = $display['settings']['test_formatter_setting_additional'];
$array = array();
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item, $display);
$this->content = drupal_render($output);
$this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -239,7 +238,7 @@ function testFieldViewValue() {
// used.
$setting = $this->display_options['teaser']['settings']['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item, 'teaser');
$this->content = drupal_render($output);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -249,7 +248,7 @@ function testFieldViewValue() {
// are used.
$setting = $this->display_options['default']['settings']['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta];
$item = $this->entity->{$this->field_name}[$delta]->getValue();
$output = field_view_value($this->entity, $this->field_name, $item, 'unknown_view_mode');
$this->content = drupal_render($output);
$this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
......@@ -278,8 +277,8 @@ function testFieldEmpty() {
$this->assertNoText($display['settings']['test_empty_string']);
// Now remove the values from the test field and retest.
$this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED] = array();
field_test_entity_save($this->entity);
$this->entity->{$this->field_name} = array();
$this->entity->save();
$output = field_view_field($this->entity, $this->field_name, $display);
$view = drupal_render($output);
$this->content = $view;
......
......@@ -32,7 +32,7 @@ public static function getInfo() {
*/
function testImportChange() {
$field_id = 'field_test_import';
$instance_id = "test_entity.test_bundle.$field_id";
$instance_id = "entity_test.entity_test.$field_id";
$instance_config_name = "field.instance.$instance_id";
// Import default config.
......
......@@ -27,10 +27,10 @@ public static function getInfo() {
*/
function testImportCreateDefault() {
$field_id = 'field_test_import';
$instance_id = "test_entity.test_bundle.$field_id";
$instance_id = "entity_test.entity_test.$field_id";
$field_id_2 = 'field_test_import_2';
$instance_id_2a = "test_entity.test_bundle.$field_id_2";
$instance_id_2b = "test_entity.test_bundle_2.$field_id_2";
$instance_id_2a = "entity_test.entity_test.$field_id_2";
$instance_id_2b = "entity_test.entity_test.$field_id_2";
// Check that the fields and instances do not exist yet.
$this->assertFalse(entity_load('field_entity', $field_id));
......@@ -40,7 +40,7 @@ function testImportCreateDefault() {
$this->assertFalse(entity_load('field_instance', $instance_id_2b));
// Create a second bundle for the 'Entity test' entity type.
entity_test_create_bundle('test_bundle_2');
entity_test_create_bundle('test_bundle');
// Enable field_test_config module and check that the field and instance
// shipped in the module's default config were created.
......@@ -61,12 +61,12 @@ function testImportCreateDefault() {
$this->assertTrue($instance->bundle, 'test_bundle_2', 'The second field instance was created on bundle test_bundle_2.');
// Tests field info contains the right data.
$instances = Field::fieldInfo()->getInstances('test_entity');
$this->assertEqual(count($instances['test_bundle']), 2);
$this->assertTrue(isset($instances['test_bundle']['field_test_import']));
$instances = Field::fieldInfo()->getInstances('entity_test');
$this->assertEqual(count($instances['entity_test']), 2);
$this->assertTrue(isset($instances['entity_test']['field_test_import']));
$this->assertTrue(isset($instances['entity_test']['field_test_import_2']));
$this->assertEqual(count($instances['test_bundle']), 1);
$this->assertTrue(isset($instances['test_bundle']['field_test_import_2']));
$this->assertEqual(count($instances['test_bundle_2']), 1);
$this->assertTrue(isset($instances['test_bundle_2']['field_test_import_2']));
}
/**
......@@ -75,14 +75,14 @@ function testImportCreateDefault() {
function testImportCreate() {
// One field with one field instance.
$field_id = 'field_test_import_staging';
$instance_id = "test_entity.test_bundle.$field_id";
$instance_id = "entity_test.entity_test.$field_id";
$field_config_name = "field.field.$field_id";
$instance_config_name = "field.instance.$instance_id";
// One field with two field instances.
$field_id_2 = 'field_test_import_staging_2';
$instance_id_2a = "test_entity.test_bundle.$field_id_2";
$instance_id_2b = "test_entity.test_bundle_2.$field_id_2";
$instance_id_2a = "entity_test.test_bundle.$field_id_2";
$instance_id_2b = "entity_test.test_bundle_2.$field_id_2";
$field_config_name_2 = "field.field.$field_id_2";
$instance_config_name_2a = "field.instance.$instance_id_2a";
$instance_config_name_2b = "field.instance.$instance_id_2b";
......
......@@ -33,9 +33,9 @@ public static function getInfo() {
public function testImportDelete() {
$field_id = 'field_test_import';
$field_id_2 = 'field_test_import_2';
$instance_id = "test_entity.test_bundle.$field_id";
$instance_id_2a = "test_entity.test_bundle.$field_id_2";
$instance_id_2b = "test_entity.test_bundle_2.$field_id_2";
$instance_id = "entity_test.test_bundle.$field_id";
$instance_id_2a = "entity_test.test_bundle.$field_id_2";
$instance_id_2b = "entity_test.test_bundle_2.$field_id_2";
$field_config_name = "field.field.$field_id";
$field_config_name_2 = "field.field.$field_id_2";
$instance_config_name = "field.instance.$instance_id";
......
......@@ -46,11 +46,11 @@ function testFieldInfo() {
}
// Verify that no unexpected instances exist.
$instances = field_info_instances('test_entity');
$instances = field_info_instances('entity_test');
$expected = array();
$this->assertIdentical($instances, $expected, format_string("field_info_instances('test_entity') returns %expected.", array('%expected' => var_export($expected, TRUE))));
$instances = field_info_instances('test_entity', 'test_bundle');
$this->assertIdentical($instances, array(), "field_info_instances('test_entity', 'test_bundle') returns an empty array.");
$this->assertIdentical($instances, $expected, format_string("field_info_instances('entity_test') returns %expected.", array('%expected' => var_export($expected, TRUE))));
$instances = field_info_instances('entity_test', 'entity_test');
$this->assertIdentical($instances, array(), "field_info_instances('entity_test', 'entity_test') returns an empty array.");
// Create a field, verify it shows up.
$core_fields = field_info_fields();
......@@ -74,8 +74,8 @@ function testFieldInfo() {
// Create an instance, verify that it shows up
$instance_definition = array(
'field_name' => $field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $this->randomName(),
'description' => $this->randomName(),
'weight' => mt_rand(0, 127),
......@@ -83,20 +83,20 @@ function testFieldInfo() {
$instance = entity_create('field_instance', $instance_definition);
$instance->save();
$info = entity_get_info('test_entity');
$instances = field_info_instances('test_entity', $instance['bundle']);
$info = entity_get_info('entity_test');
$instances = field_info_instances('entity_test', $instance['bundle']);
$this->assertEqual(count($instances), 1, format_string('One instance shows up in info when attached to a bundle on a @label.', array(
'@label' => $info['label']
)));
$this->assertTrue($instance_definition < $instances[$instance['field_name']], 'Instance appears in info correctly');
// Test a valid entity type but an invalid bundle.
$instances = field_info_instances('test_entity', 'invalid_bundle');
$this->assertIdentical($instances, array(), "field_info_instances('test_entity', 'invalid_bundle') returns an empty array.");
$instances = field_info_instances('entity_test', 'invalid_bundle');
$this->assertIdentical($instances, array(), "field_info_instances('entity_test', 'invalid_bundle') returns an empty array.");
// Test invalid entity type and bundle.
$instances = field_info_instances('invalid_entity', $instance['bundle']);
$this->assertIdentical($instances, array(), "field_info_instances('invalid_entity', 'test_bundle') returns an empty array.");
$this->assertIdentical($instances, array(), "field_info_instances('invalid_entity', 'entity_test') returns an empty array.");
// Test invalid entity type, no bundle provided.
$instances = field_info_instances('invalid_entity');
......@@ -158,8 +158,8 @@ function testInstancePrepare() {
entity_create('field_entity', $field_definition)->save();
$instance_definition = array(
'field_name' => $field_definition['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
$instance = entity_create('field_instance', $instance_definition);
$instance->save();
......@@ -212,8 +212,8 @@ function testFieldMap() {
// We will overlook fields created by the 'standard' installation profile.
$exclude = field_info_field_map();
// Create a new bundle for 'test_entity' entity type.
field_test_create_bundle('test_bundle_2');
// Create a new bundle for 'entity_test' entity type.
entity_test_create_bundle('test_bundle_2');
// Create a couple fields.
$fields = array(
......@@ -234,23 +234,23 @@ function testFieldMap() {
$instances = array(
array(
'field_name' => 'field_1',
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
),
array(
'field_name' => 'field_1',
'entity_type' => 'test_entity',
'entity_type' => 'entity_test',
'bundle' => 'test_bundle_2',
),
array(