Merge branch '8.x' of git.drupal.org:project/drupal into 8.x
commit
56b93e388a
|
@ -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 @@ class EntityFieldQuery {
|
|||
* 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 @@ class EntityFieldQuery {
|
|||
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 @@ class BulkDeleteTest extends FieldTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class BulkDeleteTest extends FieldTestBase {
|
|||
}
|
||||
|
||||
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 @@ class BulkDeleteTest extends FieldTestBase {
|
|||
->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 @@ class BulkDeleteTest extends FieldTestBase {
|
|||
// 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 @@ class BulkDeleteTest extends FieldTestBase {
|
|||
// 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 @@ class BulkDeleteTest extends FieldTestBase {
|
|||
// 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 @@ class CrudTest extends FieldTestBase {
|
|||
$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 @@ class CrudTest extends FieldTestBase {
|
|||
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 @@ class CrudTest extends FieldTestBase {
|
|||
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 @@ class CrudTest extends FieldTestBase {
|
|||
// 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 @@ class DisplayApiTest extends FieldTestBase {
|
|||
|
||||
// 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 @@ class EntityPropertiesTest extends FieldTestBase {
|
|||
'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 @@ class FieldAttachOtherTest extends FieldAttachTestBase {
|
|||
*/
|
||||
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 @@ class FieldAttachOtherTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachOtherTest extends FieldAttachTestBase {
|
|||
*/
|
||||
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 @@ class FieldAttachOtherTest extends FieldAttachTestBase {
|
|||
$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 @@ class FieldAttachOtherTest extends FieldAttachTestBase {
|
|||
*/
|
||||
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 @@ class FieldAttachOtherTest extends FieldAttachTestBase {
|
|||
*/
|
||||
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 @@ class FieldAttachOtherTest extends FieldAttachTestBase {
|
|||
*/
|
||||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
|
||||
// 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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
}
|
||||
|
||||
// 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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
|
||||
// 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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
|
||||
// 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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
}
|
||||
|
||||
// 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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
*/
|
||||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
// 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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
$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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FieldAttachStorageTest extends FieldAttachTestBase {
|
|||
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 @@ class FormTest extends FieldTestBase {
|
|||
$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 @@ class FormTest extends FieldTestBase {
|
|||
// 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 @@ class FormTest extends FieldTestBase {
|
|||
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 @@ class FormTest extends FieldTestBase {
|
|||
);
|
||||
$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 @@ class TranslationTest extends FieldTestBase {
|
|||
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 @@ class TranslationTest extends FieldTestBase {
|
|||
$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 @@ class TranslationTest extends FieldTestBase {
|
|||
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 @@ class TranslationTest extends FieldTestBase {
|
|||
);
|
||||
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 @@ class TranslationTest extends FieldTestBase {
|
|||
// 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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
$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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
|
||||
// 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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
// 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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
*/
|
||||
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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
}
|
||||
|
||||
// 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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
*/
|
||||
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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
$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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
}
|
||||
|
||||
// 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 @@ class FieldSqlStorageTest extends WebTestBase {
|
|||
}
|
||||
|
||||
// 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 @@ class OptionsDynamicValuesTest extends FieldTestBase {
|
|||
'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 @@ class OptionsFieldTest extends FieldTestBase {
|
|||
$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 @@ class OptionsFieldTest extends FieldTestBase {
|
|||
|
||||
// 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 @@ class OptionsFieldTest extends FieldTestBase {
|
|||
// 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 @@ class OptionsFieldTest extends FieldTestBase {
|
|||
),
|
||||
);
|
||||
$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 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$langcode = LANGUAGE_NOT_SPECIFIED;
|
||||
|
||||
// Create an entity.
|
||||
$entity_init = field_test_create_stub_entity();
|
||||
$entity_init = field_test_create_entity();
|
||||
$entity = clone $entity_init;
|
||||
$entity->is_new = TRUE;
|
||||
field_test_entity_save($entity);
|
||||
|
@ -136,7 +136,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$langcode = LANGUAGE_NOT_SPECIFIED;
|
||||
|
||||
// Create an entity.
|
||||
$entity_init = field_test_create_stub_entity();
|
||||
$entity_init = field_test_create_entity();
|
||||
$entity = clone $entity_init;
|
||||
$entity->is_new = TRUE;
|
||||
field_test_entity_save($entity);
|
||||
|
@ -224,7 +224,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$langcode = LANGUAGE_NOT_SPECIFIED;
|
||||
|
||||
// Create an entity.
|
||||
$entity_init = field_test_create_stub_entity();
|
||||
$entity_init = field_test_create_entity();
|
||||
$entity = clone $entity_init;
|
||||
$entity->is_new = TRUE;
|
||||
field_test_entity_save($entity);
|
||||
|
@ -320,7 +320,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$langcode = LANGUAGE_NOT_SPECIFIED;
|
||||
|
||||
// Create an entity.
|
||||
$entity_init = field_test_create_stub_entity();
|
||||
$entity_init = field_test_create_entity();
|
||||
$entity = clone $entity_init;
|
||||
$entity->is_new = TRUE;
|
||||
field_test_entity_save($entity);
|
||||
|
@ -437,7 +437,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$langcode = LANGUAGE_NOT_SPECIFIED;
|
||||
|
||||
// Create an entity.
|
||||
$entity_init = field_test_create_stub_entity();
|
||||
$entity_init = field_test_create_entity();
|
||||
$entity = clone $entity_init;
|
||||
$entity->is_new = TRUE;
|
||||
field_test_entity_save($entity);
|
||||
|
|
|
@ -65,7 +65,7 @@ class TextFieldTest extends WebTestBase {
|
|||
);
|
||||
field_create_instance($this->instance);
|
||||
// Test valid and invalid values with field_attach_validate().
|
||||
$entity = field_test_create_stub_entity();
|
||||
$entity = field_test_create_entity();
|
||||
$langcode = LANGUAGE_NOT_SPECIFIED;
|
||||
for ($i = 0; $i <= $max_length + 2; $i++) {
|
||||
$entity->{$this->field['field_name']}[$langcode][0]['value'] = str_repeat('x', $i);
|
||||
|
|
|
@ -210,8 +210,8 @@ function field_test_delete_bundle($bundle) {
|
|||
/**
|
||||
* Creates a basic test_entity entity.
|
||||
*/
|
||||
function field_test_create_stub_entity($id = 1, $vid = 1, $bundle = 'test_bundle', $label = '') {
|
||||
$entity = new stdClass();
|
||||
function field_test_create_entity($id = 1, $vid = 1, $bundle = 'test_bundle', $label = '') {
|
||||
$entity = entity_create('test_entity', array());
|
||||
// Only set id and vid properties if they don't come as NULL (creation form).
|
||||
if (isset($id)) {
|
||||
$entity->ftid = $id;
|
||||
|
|
|
@ -199,7 +199,7 @@ function field_test_dummy_field_storage_query(EntityFieldQuery $query) {
|
|||
// Return dummy values that will be checked by the test.
|
||||
return array(
|
||||
'user' => array(
|
||||
1 => entity_create_stub_entity('user', array(1, NULL, NULL)),
|
||||
1 => (object) array('entity_id' => 1, 'revision_id' => NULL, 'bundle' => NULL),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -325,7 +325,7 @@ function field_test_field_storage_query($field_id, $conditions, $count, &$cursor
|
|||
$id = ($load_current || empty($entity_type['entity keys']['revision'])) ? $row->entity_id : $row->revision_id;
|
||||
|
||||
if (!isset($return[$row->type][$id])) {
|
||||
$return[$row->type][$id] = entity_create_stub_entity($row->type, array($row->entity_id, $row->revision_id, $row->bundle));
|
||||
$return[$row->type][$id] = (object) array('entity_id' => $row->entity_id, 'revision_id' => $row->revision_id, 'bundle' => $row->bundle);
|
||||
$entity_count++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,10 +25,11 @@ class TermStorageController extends DatabaseStorageController {
|
|||
public function create(array $values) {
|
||||
$entity = parent::create($values);
|
||||
// Ensure the vocabulary machine name is initialized as it is used as the
|
||||
// bundle key.
|
||||
// bundle key. Only attempt to do this if a vocabulary ID is available,
|
||||
// which might not be the case when creating partial entity structures.
|
||||
// @todo Move to Term::bundle() once field API has been converted
|
||||
// to make use of it.
|
||||
if (!isset($entity->vocabulary_machine_name)) {
|
||||
if (!isset($entity->vocabulary_machine_name) && isset($entity->vid)) {
|
||||
$vocabulary = taxonomy_vocabulary_load($entity->vid);
|
||||
$entity->vocabulary_machine_name = $vocabulary->machine_name;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,10 @@ class EfqTest extends TaxonomyTestBase {
|
|||
asort($result);
|
||||
$this->assertEqual(array_keys($terms), array_keys($result), 'Taxonomy terms were retrieved by EntityFieldQuery.');
|
||||
|
||||
$first_result = reset($result);
|
||||
$term = _field_create_entity_from_ids($first_result);
|
||||
$this->assertEqual($term->tid, $first_result->entity_id, 'Taxonomy term can be created based on the IDs');
|
||||
|
||||
// Create a second vocabulary and five more terms.
|
||||
$vocabulary2 = $this->createVocabulary();
|
||||
$terms2 = array();
|
||||
|
|
|
@ -69,7 +69,7 @@ class TermFieldTest extends TaxonomyTestBase {
|
|||
function testTaxonomyTermFieldValidation() {
|
||||
// Test valid and invalid values with field_attach_validate().
|
||||
$langcode = LANGUAGE_NOT_SPECIFIED;
|
||||
$entity = field_test_create_stub_entity();
|
||||
$entity = field_test_create_entity();
|
||||
$term = $this->createTerm($this->vocabulary);
|
||||
$entity->{$this->field_name}[$langcode][0]['tid'] = $term->tid;
|
||||
try {
|
||||
|
@ -80,7 +80,7 @@ class TermFieldTest extends TaxonomyTestBase {
|
|||
$this->fail('Correct term does not cause validation error.');
|
||||
}
|
||||
|
||||
$entity = field_test_create_stub_entity();
|
||||
$entity = field_test_create_entity();
|
||||
$bad_term = $this->createTerm($this->createVocabulary());
|
||||
$entity->{$this->field_name}[$langcode][0]['tid'] = $bad_term->tid;
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue