Commit 4c97c097 authored by webchick's avatar webchick

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();
......
......@@ -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';
$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();
......@@ -438,13 +438,13 @@ function testNestedFieldForm() {
field_create_instance($this->instance);
// Create two entities.
$entity_1 = field_test_create_stub_entity(1, 1);
$entity_1 = field_test_create_entity(1, 1);
$entity_1->is_new = TRUE;
$entity_1->field_single[LANGUAGE_NOT_SPECIFIED][] = array('value' => 0);
$entity_1->field_unlimited[LANGUAGE_NOT_SPECIFIED][] = array('value' => 1);
field_test_entity_save($entity_1);
$entity_2 = field_test_create_stub_entity(2, 2);
$entity_2 = field_test_create_entity(2, 2);
$entity_2->is_new = TRUE;
$entity_2->field_single[LANGUAGE_NOT_SPECIFIED][] = array('value' => 10);
$entity_2->field_unlimited[LANGUAGE_NOT_SPECIFIED][] = array('value' => 11);
......@@ -468,8 +468,8 @@ function testNestedFieldForm() {
);
$this->drupalPost(NULL, $edit, t('Save'));
field_cache_clear();
$entity_1 = field_test_create_stub_entity(1);
$entity_2 = field_test_create_stub_entity(2);
$entity_1 = field_test_create_entity(1);
$entity_2 = field_test_create_entity(2);
$this->assertFieldValues($entity_1, 'field_single', LANGUAGE_NOT_SPECIFIED, array(1));
$this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NOT_SPECIFIED, array(2, 3));
$this->assertFieldValues($entity_2, 'field_single', LANGUAGE_NOT_SPECIFIED, array(11));
......
......@@ -94,7 +94,7 @@ function testFieldInvoke() {
field_test_entity_info_translatable('test_entity', TRUE);
$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']);
// Populate some extra languages to check if _field_invoke() correctly uses
// the result of field_available_languages().
......@@ -139,7 +139,7 @@ function testFieldInvokeMultiple() {
$available_langcodes = field_available_languages($this->entity_type, $this->field);
for ($id = 1; $id <= $entity_count; ++$id) {
$entity = field_test_create_stub_entity($id, $id, $this->instance['bundle']);
$entity = field_test_create_entity($id, $id, $this->instance['bundle']);
$langcodes = $available_langcodes;
// Populate some extra languages to check whether _field_invoke()
......@@ -210,7 +210,7 @@ function testTranslatableFieldSaveLoad() {
field_test_entity_info_translatable('test_entity', TRUE);
$eid = $evid = 1;
$entity_type = 'test_entity';
$entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']);
$entity = field_test_create_entity($eid, $evid, $this->instance['bundle']);
$field_translations = array();
$available_langcodes = field_available_languages($entity_type, $this->field);
$this->assertTrue(count($available_langcodes) > 1, t('Field is translatable.'));
......@@ -258,7 +258,7 @@ function testFieldDisplayLanguage() {
);
field_create_instance($instance);
$entity = field_test_create_stub_entity(1, 1, $this->instance['bundle']);
$entity = field_test_create_entity(1, 1, $this->instance['bundle']);
$instances = field_info_instances($entity_type, $this->instance['bundle']);
$enabled_langcodes = field_content_languages();
......@@ -337,7 +337,7 @@ function testFieldFormTranslationRevisions() {
// Prepare the field translations.
field_test_entity_info_translatable($this->entity_type, TRUE);
$eid = 1;
$entity = field_test_create_stub_entity($eid, $eid, $this->instance['bundle']);
$entity = field_test_create_entity($eid, $eid, $this->instance['bundle']);
$available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field));
unset($available_langcodes[LANGUAGE_NOT_SPECIFIED]);
$field_name = $this->field['field_name'];
......
......@@ -75,7 +75,7 @@ function testFieldAttachLoad() {
$query->execute();
// Load the "most current revision"
$entity = field_test_create_stub_entity($eid, 0, $this->instance['bundle']);
$entity = field_test_create_entity($eid, 0, $this->instance['bundle']);
field_attach_load($entity_type, array($eid => $entity));
foreach ($values[0] as $delta => $value) {
if ($delta < $this->field['cardinality']) {
......@@ -88,7 +88,7 @@ function testFieldAttachLoad() {
// Load every revision
for ($evid = 0; $evid < 4; ++$evid) {
$entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']);
$entity = field_test_create_entity($eid, $evid, $this->instance['bundle']);
field_attach_load_revision($entity_type, array($eid => $entity));
foreach ($values[$evid] as $delta => $value) {
if ($delta < $this->field['cardinality']) {
......@@ -104,7 +104,7 @@ function testFieldAttachLoad() {
// loaded.
$eid = $evid = 1;
$unavailable_langcode = 'xx';
$entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']);
$entity = field_test_create_entity($eid, $evid, $this->instance['bundle']);
$values = array($entity_type, $eid, $evid, 0, $unavailable_langcode, mt_rand(1, 127));
db_insert($this->table)->fields($columns)->values($values)->execute();
db_insert($this->revision_table)->fields($columns)->values($values)->execute();
......@@ -118,7 +118,7 @@ function testFieldAttachLoad() {
*/
function testFieldAttachInsertAndUpdate() {
$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;
// Test insert.
......@@ -142,7 +142,7 @@ function testFieldAttachInsertAndUpdate() {
}
// Test update.
$entity = field_test_create_stub_entity(0, 1, $this->instance['bundle']);
$entity = field_test_create_entity(0, 1, $this->instance['bundle']);
$values = array();
// Note: we try to update one extra value ('<=' instead of '<').
for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) {
......@@ -199,7 +199,7 @@ function testFieldAttachInsertAndUpdate() {
*/
function testFieldAttachSaveMissingData() {
$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;
// Insert: Field is missing
......@@ -298,7 +298,7 @@ function testUpdateFieldSchemaWithData() {
$field = field_create_field($field);
$instance = array('field_name' => 'decimal52', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle');
$instance = field_create_instance($instance);
$entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
$entity = field_test_create_entity(0, 0, $instance['bundle']);
$entity->decimal52[LANGUAGE_NOT_SPECIFIED][0]['value'] = '1.235';
field_attach_insert('test_entity', $entity);
......@@ -358,7 +358,7 @@ function testFieldUpdateIndexesWithData() {
}
// Add data so the table cannot be dropped.
$entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
$entity = field_test_create_entity(0, 0, $instance['bundle']);
$entity->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['value'] = 'field data';
field_attach_insert('test_entity', $entity);
......@@ -378,7 +378,7 @@ function testFieldUpdateIndexesWithData() {
}
// Verify that the tables were not dropped.
$entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
$entity = field_test_create_entity(0, 0, $instance['bundle']);
field_attach_load('test_entity', array(0 => $entity));
$this->assertEqual($entity->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['value'], 'field data', t("Index changes performed without dropping the tables"));
}
......
......@@ -45,6 +45,6 @@ function setUp() {
'bundle' => 'test_bundle',
'label' => $this->randomName(),
);
$this->entity = call_user_func_array('field_test_create_stub_entity', $this->test);
$this->entity = call_user_func_array('field_test_create_entity', $this->test);
}
}
......@@ -54,7 +54,7 @@ function testUpdateAllowedValues() {
$langcode = LANGUAGE_NOT_SPECIFIED;
// All three options appear.
$entity = field_test_create_stub_entity();
$entity = field_test_create_entity();
$form = drupal_get_form('field_test_entity_form', $entity);
$this->assertTrue(!empty($form[$this->field_name][$langcode][1]), t('Option 1 exists'));
$this->assertTrue(!empty($form[$this->field_name][$langcode][2]), t('Option 2 exists'));
......@@ -62,7 +62,7 @@ function testUpdateAllowedValues() {
// Use one of the values in an actual entity, and check that this value
// cannot be removed from the list.
$entity = field_test_create_stub_entity();
$entity = field_test_create_entity();
$entity->{$this->field_name}[$langcode][0] = array('value' => 1);
field_test_entity_save($entity);
$this->field['settings']['allowed_values'] = array(2 => 'Two');
......@@ -80,7 +80,7 @@ function testUpdateAllowedValues() {
// Removed options do not appear.
$this->field['settings']['allowed_values'] = array(2 => 'Two');
field_update_field($this->field);
$entity = field_test_create_stub_entity();
$entity = field_test_create_entity();
$form = drupal_get_form('field_test_entity_form', $entity);
$this->assertTrue(empty($form[$this->field_name][$langcode][1]), t('Option 1 does not exist'));
$this->assertTrue(!empty($form[$this->field_name][$langcode][2]), t('Option 2 exists'));
......@@ -110,7 +110,7 @@ function testUpdateAllowedValues() {
),
);
$this->instance = field_create_instance($this->instance);
$entity = field_test_create_stub_entity();
$entity = field_test_create_entity();
$form = drupal_get_form('field_test_entity_form', $entity);
$this->assertTrue(!empty($form[$this->field_name][$langcode][1]), t('Option 1 exists'));
$this->assertTrue(!empty($form[$this->field_name][$langcode][2]), t('Option 2 exists'));
......
......@@ -82,7 +82,7 @@ function testRadioButtons() {
$langcode = LANGUAGE_NOT_SPECIFIED;
</