Convenience function for Field API tests.

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).

Parameters

$entity_type: The entity type of $entities.

$entities: An array of entities of type $entity_type.

$field_name: Optional; a field name whose data should be copied from $entities into the returned stub entities.

Return value

An array of stub entities corresponding to $entities.

2 calls to FieldBulkDeleteTestCase::_generateStubEntities()
FieldBulkDeleteTestCase::testPurgeField in modules/field/tests/field.test
Verify that fields are preserved and purged correctly as multiple instances are deleted and purged.
FieldBulkDeleteTestCase::testPurgeInstance in modules/field/tests/field.test
Verify that field data items and instances are purged when an instance is deleted.

File

modules/field/tests/field.test, line 3541
Tests for field.module.

Class

FieldBulkDeleteTestCase
Unit test class for field bulk delete and batch purge functionality.

Code

function _generateStubEntities($entity_type, $entities, $field_name = NULL) {
  $stubs = 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;
  }
  return $stubs;
}