Commit 4c97c097 authored by webchick's avatar webchick
Browse files

Issue #1551140 by Berdir, fago: Remove stub entities, replace entity_create_stub_entity().

parent c7dc1e85
......@@ -164,36 +164,6 @@ function entity_extract_ids($entity_type, $entity) {
return array($id, $vid, $bundle);
}
/**
* Assembles an object structure with initial IDs.
*
* This function can be seen as reciprocal to entity_extract_ids().
*
* @param $entity_type
* The entity type; e.g. 'node' or 'user'.
* @param $ids
* A numerically indexed array, as returned by entity_extract_ids(),
* containing these elements:
* - 0: Primary ID of the entity.
* - 1: Revision ID of the entity, or NULL if $entity_type is not versioned.
* - 2: Bundle name of the entity, or NULL if $entity_type has no bundles.
*
* @return
* An entity object, initialized with the IDs provided.
*/
function entity_create_stub_entity($entity_type, $ids) {
$entity = new stdClass();
$info = entity_get_info($entity_type);
$entity->{$info['entity keys']['id']} = $ids[0];
if (!empty($info['entity keys']['revision']) && isset($ids[1])) {
$entity->{$info['entity keys']['revision']} = $ids[1];
}
if (!empty($info['entity keys']['bundle']) && isset($ids[2])) {
$entity->{$info['entity keys']['bundle']} = $ids[2];
}
return $entity;
}
/**
* Loads an entity from the database.
*
......
......@@ -710,20 +710,21 @@ public function addMetaData($key, $object) {
* Executes the query.
*
* After executing the query, $this->orderedResults will contain a list of
* the same stub entities in the order returned by the query. This is only
* the same entity ids in the order returned by the query. This is only
* relevant if there are multiple entity types in the returned value and
* a field ordering was requested. In every other case, the returned value
* contains everything necessary for processing.
*
* @return
* Either a number if count() was called or an array of associative arrays
* of stub entities. The outer array keys are entity types, and the inner
* of the entity ids. The outer array keys are entity types, and the inner
* array keys are the relevant ID. (In most cases this will be the entity
* ID. The only exception is when age=FIELD_LOAD_REVISION is used and field
* conditions or sorts are present -- in this case, the key will be the
* revision ID.) The entity type will only exist in the outer array if
* results were found. The inner array values are always stub entities, as
* returned by entity_create_stub_entity(). To traverse the returned array:
* results were found. The inner array values consist of an object with the
* entity_id, revision_id and bundle properties. To traverse the returned
* array:
* @code
* foreach ($query->execute() as $entity_type => $entities) {
* foreach ($entities as $entity_id => $entity) {
......@@ -922,11 +923,12 @@ function finishQuery($select_query, $id_key = 'entity_id') {
return $select_query->countQuery()->execute()->fetchField();
}
$return = array();
foreach ($select_query->execute() as $partial_entity) {
$bundle = isset($partial_entity->bundle) ? $partial_entity->bundle : NULL;
$entity = entity_create_stub_entity($partial_entity->entity_type, array($partial_entity->entity_id, $partial_entity->revision_id, $bundle));
$return[$partial_entity->entity_type][$partial_entity->$id_key] = $entity;
$this->ordered_results[] = $partial_entity;
foreach ($select_query->execute() as $ids) {
if (!isset($ids->bundle)) {
$ids->bundle = NULL;
}
$return[$ids->entity_type][$ids->$id_key] = $ids;
$this->ordered_results[] = $ids;
}
return $return;
}
......
......@@ -867,11 +867,16 @@ function field_purge_batch($batch_size) {
->execute();
if ($results) {
foreach ($results as $entity_type => $stub_entities) {
field_attach_load($entity_type, $stub_entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1));
foreach ($stub_entities as $stub_entity) {
foreach ($results as $entity_type => $ids_array) {
$entities = array();
foreach ($ids_array as $ids) {
$entities[$ids->entity_id] = _field_create_entity_from_ids($ids);
}
field_attach_load($entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1));
foreach ($entities as $entity) {
// Purge the data for the entity.
field_purge_data($entity_type, $stub_entity, $field, $instance);
field_purge_data($entity_type, $entity, $field, $instance);
}
}
}
......
......@@ -1206,3 +1206,29 @@ function theme_field($variables) {
return $output;
}
/**
* Assembles a partial entity structure with initial IDs.
*
* This can be used to create an entity based on the the ids object returned by
* EntityFieldQuery.
*
* @param stdClass $ids
* An object with the properties entity_type (required), entity_id (required),
* revision_id (optional) and bundle (optional).
*
* @return
* An entity, initialized with the provided IDs.
*/
function _field_create_entity_from_ids($ids) {
$id_properties = array();
$info = entity_get_info($ids->entity_type);
$id_properties[$info['entity keys']['id']] = $ids->entity_id;
if (!empty($info['entity keys']['revision']) && isset($ids->revision_id)) {
$id_properties[$info['entity keys']['revision']] = $ids->revision_id;
}
if (!empty($info['entity keys']['bundle']) && isset($ids->bundle)) {
$id_properties[$info['entity keys']['bundle']] = $ids->bundle;
}
return entity_create($ids->entity_type, $id_properties);
}
......@@ -24,33 +24,29 @@ public static function getInfo() {
}
/**
* Convenience function for Field API tests.
* Converts the passed entities to partially created ones.
*
* Given an array of potentially fully-populated entities and an
* optional field name, generate an array of stub entities of the
* same fieldable type which contains the data for the field name
* (if given).
* This replicates the partial entities created in field_purge_data_batch(),
* which only have the ids and the to be deleted field defined.
*
* @param $entity_type
* The entity type of $entities.
* @param $entities
* An array of entities of type $entity_type.
* An array of entities of type test_entity.
* @param $field_name
* Optional; a field name whose data should be copied from
* $entities into the returned stub entities.
* A field name whose data should be copied from $entities into the returned
* partial entities.
* @return
* An array of stub entities corresponding to $entities.
* An array of partial entities corresponding to $entities.
*/
function _generateStubEntities($entity_type, $entities, $field_name = NULL) {
$stubs = array();
protected function convertToPartialEntities($entities, $field_name) {
$partial_entities = array();
foreach ($entities as $id => $entity) {
$stub = entity_create_stub_entity($entity_type, entity_extract_ids($entity_type, $entity));
if (isset($field_name)) {
$stub->{$field_name} = $entity->{$field_name};
}
$stubs[$id] = $stub;
// Re-create the entity with only the required keys, remove label as that
// is not present when using _field_create_entity_from_ids().
$partial_entities[$id] = field_test_create_entity($entity->ftid, $entity->ftvid, $entity->fttype, $entity->ftlabel);
unset($partial_entities[$id]->ftlabel);
$partial_entities[$id]->$field_name = $entity->$field_name;
}
return $stubs;
return $partial_entities;
}
/**
......@@ -122,7 +118,7 @@ function setUp() {
}
for ($i = 0; $i < 10; $i++) {
$entity = field_test_create_stub_entity($id, $id, $bundle);
$entity = field_test_create_entity($id, $id, $bundle);
foreach ($this->fields as $field) {
$entity->{$field['field_name']}[LANGUAGE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field['cardinality']);
}
......@@ -182,9 +178,13 @@ function testDeleteFieldInstance() {
->entityCondition('bundle', $bundle)
->deleted(TRUE)
->execute();
field_attach_load($this->entity_type, $found[$this->entity_type], FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1));
$entities = array();
foreach ($found[$this->entity_type] as $ids) {
$entities[$ids->entity_id] = _field_create_entity_from_ids($ids);
}
field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1));
$this->assertEqual(count($found['test_entity']), 10, 'Correct number of entities found after deleting');
foreach ($found['test_entity'] as $id => $entity) {
foreach ($entities as $id => $entity) {
$this->assertEqual($this->entities[$id]->{$field['field_name']}, $entity->{$field['field_name']}, "Entity $id with deleted data loaded correctly");
}
}
......@@ -230,12 +230,12 @@ function testPurgeInstance() {
// bundle.
$actual_hooks = field_test_memorize();
$hooks = array();
$stubs = $this->_generateStubEntities($this->entity_type, $this->entities_by_bundles[$bundle], $field['field_name']);
foreach (array_chunk($stubs, $batch_size, TRUE) as $chunk) {
$hooks['field_test_field_load'][] = $chunk;
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']);
foreach (array_chunk($entities, $batch_size, TRUE) as $chunk_entity) {
$hooks['field_test_field_load'][] = $chunk_entity;
}
foreach ($stubs as $stub) {
$hooks['field_test_field_delete'][] = $stub;
foreach ($entities as $entity) {
$hooks['field_test_field_delete'][] = $entity;
}
$this->checkHooksInvocations($hooks, $actual_hooks);
......@@ -284,11 +284,9 @@ function testPurgeField() {
// bundle.
$actual_hooks = field_test_memorize();
$hooks = array();
$stubs = $this->_generateStubEntities($this->entity_type, $this->entities_by_bundles[$bundle], $field['field_name']);
$hooks['field_test_field_load'][] = $stubs;
foreach ($stubs as $stub) {
$hooks['field_test_field_delete'][] = $stub;
}
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']);
$hooks['field_test_field_load'][] = $entities;
$hooks['field_test_field_delete'] = $entities;
$this->checkHooksInvocations($hooks, $actual_hooks);
// Purge again to purge the instance.
......@@ -313,11 +311,9 @@ function testPurgeField() {
// Check hooks invocations (same as above, for the 2nd bundle).
$actual_hooks = field_test_memorize();
$hooks = array();
$stubs = $this->_generateStubEntities($this->entity_type, $this->entities_by_bundles[$bundle], $field['field_name']);
$hooks['field_test_field_load'][] = $stubs;
foreach ($stubs as $stub) {
$hooks['field_test_field_delete'][] = $stub;
}
$entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']);
$hooks['field_test_field_load'][] = $entities;
$hooks['field_test_field_delete'] = $entities;
$this->checkHooksInvocations($hooks, $actual_hooks);
// The field still exists, deleted.
......
......@@ -297,7 +297,7 @@ function testDeleteField() {
$this->assertTrue(!empty($instance) && empty($instance['deleted']), t('A new instance for a previously used field name is created.'));
// Save an entity with data for the field
$entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
$entity = field_test_create_entity(0, 0, $instance['bundle']);
$langcode = LANGUAGE_NOT_SPECIFIED;
$values[0]['value'] = mt_rand(1, 127);
$entity->{$field['field_name']}[$langcode] = $values;
......@@ -305,7 +305,7 @@ function testDeleteField() {
field_attach_insert('test_entity', $entity);
// Verify the field is present on load
$entity = field_test_create_stub_entity(0, 0, $this->instance_definition['bundle']);
$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");
foreach ($values as $delta => $value) {
......@@ -362,7 +362,7 @@ function testUpdateField() {
do {
// We need a unique ID for our entity. $cardinality will do.
$id = $cardinality;
$entity = field_test_create_stub_entity($id, $id, $instance['bundle']);
$entity = field_test_create_entity($id, $id, $instance['bundle']);
// Fill in the entity with more values than $cardinality.
for ($i = 0; $i < 20; $i++) {
$entity->field_update[LANGUAGE_NOT_SPECIFIED][$i]['value'] = $i;
......@@ -370,7 +370,7 @@ function testUpdateField() {
// Save the entity.
field_attach_insert('test_entity', $entity);
// Load back and assert there are $cardinality number of values.
$entity = field_test_create_stub_entity($id, $id, $instance['bundle']);
$entity = field_test_create_entity($id, $id, $instance['bundle']);
field_attach_load('test_entity', array($id => $entity));
$this->assertEqual(count($entity->field_update[LANGUAGE_NOT_SPECIFIED]), $field_definition['cardinality'], 'Cardinality is kept');
// Now check the values themselves.
......
......@@ -54,7 +54,7 @@ function setUp() {
// Create an entity with values.
$this->values = $this->_generateTestFieldValues($this->cardinality);
$this->entity = field_test_create_stub_entity();
$this->entity = field_test_create_entity();
$this->is_new = TRUE;
$this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED] = $this->values;
field_test_entity_save($this->entity);
......
......@@ -33,10 +33,14 @@ function testEntityLabel() {
'test_entity_label_callback',
);
$entity = field_test_create_stub_entity();
// @todo Remove once test_entity entity has been merged with entity_test.
$values = array(
'ftlabel' => $this->randomName(),
);
foreach ($entity_types as $entity_type) {
$label = entity_create($entity_type, (array) $entity)->label();
$entity = entity_create($entity_type, $values);
$label = $entity->label();
switch ($entity_type) {
case 'test_entity_no_label':
......
......@@ -26,7 +26,7 @@ public static function getInfo() {
*/
function testFieldAttachView() {
$entity_type = 'test_entity';
$entity_init = field_test_create_stub_entity();
$entity_init = field_test_create_entity();
$langcode = LANGUAGE_NOT_SPECIFIED;
// Populate values to be displayed.
......@@ -172,11 +172,11 @@ function testFieldAttachPrepareViewMultiple() {
field_create_instance($this->instance2);
// Create one entity in each bundle.
$entity1_init = field_test_create_stub_entity(1, 1, 'test_bundle');
$entity1_init = field_test_create_entity(1, 1, 'test_bundle');
$values1 = $this->_generateTestFieldValues($this->field['cardinality']);
$entity1_init->{$this->field_name}[$langcode] = $values1;
$entity2_init = field_test_create_stub_entity(2, 2, 'test_bundle_2');
$entity2_init = field_test_create_entity(2, 2, 'test_bundle_2');
$values2 = $this->_generateTestFieldValues($this->field['cardinality']);
$entity2_init->{$this->field_name}[$langcode] = $values2;
......@@ -200,7 +200,7 @@ function testFieldAttachPrepareViewMultiple() {
*/
function testFieldAttachCache() {
// Initialize random values and a test entity.
$entity_init = field_test_create_stub_entity(1, 1, $this->instance['bundle']);
$entity_init = field_test_create_entity(1, 1, $this->instance['bundle']);
$langcode = LANGUAGE_NOT_SPECIFIED;
$values = $this->_generateTestFieldValues($this->field['cardinality']);
......@@ -265,7 +265,7 @@ function testFieldAttachCache() {
$this->assertEqual($cache->data[$this->field_name][$langcode], $values, t('Cached: correct cache entry on load'));
// Create a new revision, and check that the cache entry is wiped.
$entity_init = field_test_create_stub_entity(1, 2, $this->instance['bundle']);
$entity_init = field_test_create_entity(1, 2, $this->instance['bundle']);
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity = clone($entity_init);
$entity->{$this->field_name}[$langcode] = $values;
......@@ -292,7 +292,7 @@ function testFieldAttachCache() {
*/
function testFieldAttachValidate() {
$entity_type = 'test_entity';
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
$langcode = LANGUAGE_NOT_SPECIFIED;
// Set up values to generate errors
......@@ -343,7 +343,7 @@ function testFieldAttachValidate() {
*/
function testFieldAttachForm() {
$entity_type = 'test_entity';
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
$form = array();
$form_state = form_state_defaults();
......@@ -362,7 +362,7 @@ function testFieldAttachForm() {
*/
function testFieldAttachSubmit() {
$entity_type = 'test_entity';
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
// Build the form.
$form = array();
......
......@@ -42,7 +42,7 @@ function testFieldAttachSaveLoad() {
// Preparation: create three revisions and store them in $revision array.
for ($revision_id = 0; $revision_id < 3; $revision_id++) {
$revision[$revision_id] = field_test_create_stub_entity(0, $revision_id, $this->instance['bundle']);
$revision[$revision_id] = field_test_create_entity(0, $revision_id, $this->instance['bundle']);
// Note: we try to insert one extra value.
$values[$revision_id] = $this->_generateTestFieldValues($this->field['cardinality'] + 1);
$current_revision = $revision_id;
......@@ -59,7 +59,7 @@ function testFieldAttachSaveLoad() {
}
// Confirm current revision loads the correct data.
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
field_attach_load($entity_type, array(0 => $entity));
// Number of values per field loaded equals the field cardinality.
$this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], t('Current revision: expected number of values'));
......@@ -72,7 +72,7 @@ function testFieldAttachSaveLoad() {
// Confirm each revision loads the correct data.
foreach (array_keys($revision) as $revision_id) {
$entity = field_test_create_stub_entity(0, $revision_id, $this->instance['bundle']);
$entity = field_test_create_entity(0, $revision_id, $this->instance['bundle']);
field_attach_load_revision($entity_type, array(0 => $entity));
// Number of values per field loaded equals the field cardinality.
$this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], t('Revision %revision_id: expected number of values.', array('%revision_id' => $revision_id)));
......@@ -130,7 +130,7 @@ function testFieldAttachLoadMultiple() {
// Create one test entity per bundle, with random values.
foreach ($bundles as $index => $bundle) {
$entities[$index] = field_test_create_stub_entity($index, $index, $bundle);
$entities[$index] = field_test_create_entity($index, $index, $bundle);
$entity = clone($entities[$index]);
$instances = field_info_instances('test_entity', $bundle);
foreach ($instances as $field_name => $instance) {
......@@ -153,7 +153,7 @@ function testFieldAttachLoadMultiple() {
}
// Check that the single-field load option works.
$entity = field_test_create_stub_entity(1, 1, $bundles[1]);
$entity = field_test_create_entity(1, 1, $bundles[1]);
field_attach_load($entity_type, array(1 => $entity), FIELD_LOAD_CURRENT, array('field_id' => $field_ids[1]));
$this->assertEqual($entity->{$field_names[1]}[$langcode][0]['value'], $values[1][$field_names[1]], t('Entity %index: expected value was found.', array('%index' => 1)));
$this->assertEqual($entity->{$field_names[1]}[$langcode][0]['additional_key'], 'additional_value', t('Entity %index: extra information was found', array('%index' => 1)));
......@@ -193,7 +193,7 @@ function testFieldAttachSaveLoadDifferentStorage() {
field_create_instance($instance);
}
$entity_init = field_test_create_stub_entity();
$entity_init = field_test_create_entity();
// Create entity and insert random values.
$entity = clone($entity_init);
......@@ -259,7 +259,7 @@ function testFieldStorageDetailsAlter() {
*/
function testFieldAttachSaveMissingData() {
$entity_type = 'test_entity';
$entity_init = field_test_create_stub_entity();
$entity_init = field_test_create_entity();
$langcode = LANGUAGE_NOT_SPECIFIED;
// Insert: Field is missing.
......@@ -341,7 +341,7 @@ function testFieldAttachSaveMissingDataDefaultValue() {
field_update_instance($this->instance);
$entity_type = 'test_entity';
$entity_init = field_test_create_stub_entity();
$entity_init = field_test_create_entity();
$langcode = LANGUAGE_NOT_SPECIFIED;
// Insert: Field is NULL.
......@@ -370,7 +370,7 @@ function testFieldAttachSaveMissingDataDefaultValue() {
function testFieldAttachDelete() {
$entity_type = 'test_entity';
$langcode = LANGUAGE_NOT_SPECIFIED;
$rev[0] = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$rev[0] = field_test_create_entity(0, 0, $this->instance['bundle']);
// Create revision 0
$values = $this->_generateTestFieldValues($this->field['cardinality']);
......@@ -378,18 +378,18 @@ function testFieldAttachDelete() {
field_attach_insert($entity_type, $rev[0]);
// Create revision 1
$rev[1] = field_test_create_stub_entity(0, 1, $this->instance['bundle']);
$rev[1] = field_test_create_entity(0, 1, $this->instance['bundle']);
$rev[1]->{$this->field_name}[$langcode] = $values;
field_attach_update($entity_type, $rev[1]);
// Create revision 2
$rev[2] = field_test_create_stub_entity(0, 2, $this->instance['bundle']);
$rev[2] = field_test_create_entity(0, 2, $this->instance['bundle']);
$rev[2]->{$this->field_name}[$langcode] = $values;
field_attach_update($entity_type, $rev[2]);
// Confirm each revision loads
foreach (array_keys($rev) as $vid) {
$read = field_test_create_stub_entity(0, $vid, $this->instance['bundle']);
$read = field_test_create_entity(0, $vid, $this->instance['bundle']);
field_attach_load_revision($entity_type, array(0 => $read));
$this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values.");
}
......@@ -397,24 +397,24 @@ function testFieldAttachDelete() {
// Delete revision 1, confirm the other two still load.
field_attach_delete_revision($entity_type, $rev[1]);
foreach (array(0, 2) as $vid) {
$read = field_test_create_stub_entity(0, $vid, $this->instance['bundle']);
$read = field_test_create_entity(0, $vid, $this->instance['bundle']);
field_attach_load_revision($entity_type, array(0 => $read));
$this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values.");
}
// Confirm the current revision still loads
$read = field_test_create_stub_entity(0, 2, $this->instance['bundle']);
$read = field_test_create_entity(0, 2, $this->instance['bundle']);
field_attach_load($entity_type, array(0 => $read));
$this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity current revision has {$this->field['cardinality']} values.");
// Delete all field data, confirm nothing loads
field_attach_delete($entity_type, $rev[2]);
foreach (array(0, 1, 2) as $vid) {
$read = field_test_create_stub_entity(0, $vid, $this->instance['bundle']);
$read = field_test_create_entity(0, $vid, $this->instance['bundle']);
field_attach_load_revision($entity_type, array(0 => $read));
$this->assertIdentical($read->{$this->field_name}, array(), "The test entity revision $vid is deleted.");
}
$read = field_test_create_stub_entity(0, 2, $this->instance['bundle']);
$read = field_test_create_entity(0, 2, $this->instance['bundle']);
field_attach_load($entity_type, array(0 => $read));
$this->assertIdentical($read->{$this->field_name}, array(), t('The test entity current revision is deleted.'));
}
......@@ -433,7 +433,7 @@ function testFieldAttachCreateRenameBundle() {
field_create_instance($this->instance);
// Save an entity with data in the field.
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
$langcode = LANGUAGE_NOT_SPECIFIED;
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity->{$this->field_name}[$langcode] = $values;
......@@ -441,7 +441,7 @@ function testFieldAttachCreateRenameBundle() {
field_attach_insert($entity_type, $entity);
// Verify the field data is present on load.
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
field_attach_load($entity_type, array(0 => $entity));
$this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], "Data is retrieved for the new bundle");
......@@ -455,7 +455,7 @@ function testFieldAttachCreateRenameBundle() {
$this->assertIdentical($this->instance['bundle'], $new_bundle, "Bundle name has been updated in the instance.");
// Verify the field data is present on load.
$entity = field_test_create_stub_entity(0, 0, $new_bundle);
$entity = field_test_create_entity(0, 0, $new_bundle);
field_attach_load($entity_type, array(0 => $entity));
$this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], "Bundle name has been updated in the field storage");
}
......@@ -492,7 +492,7 @@ function testFieldAttachDeleteBundle() {
field_create_instance($instance);
// Save an entity with data for both fields
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
$langcode = LANGUAGE_NOT_SPECIFIED;
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity->{$this->field_name}[$langcode] = $values;
......@@ -500,7 +500,7 @@ function testFieldAttachDeleteBundle() {
field_attach_insert('test_entity', $entity);
// Verify the fields are present on load
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
field_attach_load('test_entity', array(0 => $entity));
$this->assertEqual(count($entity->{$this->field_name}[$langcode]), 4, 'First field got loaded');
$this->assertEqual(count($entity->{$field_name}[$langcode]), 1, 'Second field got loaded');
......@@ -510,7 +510,7 @@ function testFieldAttachDeleteBundle() {
field_test_delete_bundle($this->instance['bundle']);
// Verify no data gets loaded
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$entity = field_test_create_entity(0, 0, $this->instance['bundle']);
field_attach_load('test_entity', array(0 => $entity));
$this->assertFalse(isset($entity->{$this->field_name}[$langcode]), 'No data for first field');
$this->assertFalse(isset($entity->{$field_name}[$langcode]), 'No data for second field');
......
......@@ -337,7 +337,7 @@ function testFieldFormMultipleWidget() {
$id = $match[1];
// Check that the values were saved.
$entity_init = field_test_create_stub_entity($id);
$entity_init = field_test_create_entity($id);
$this->assertFieldValues($entity_init, $this->field_name, $langcode, array(1, 2, 3));
// Display the form, check that the values are correctly filled in.
......@@ -384,7 +384,7 @@ function testFieldFormAccess() {
// Test that the form structure includes full information for each delta
// apart from #access.
$entity_type = 'test_entity';