Commit 64625f90 authored by catch's avatar catch

Issue #1184272 by Berdir, corvus_ch, sun: Remove deprecated $conditions...

Issue #1184272 by Berdir, corvus_ch, sun: Remove deprecated $conditions support from entity controller.
parent a1d60148
......@@ -580,27 +580,19 @@ function file_save_htaccess($directory, $private = TRUE) {
/**
* Loads file entities from the database.
*
* @param array|bool $fids
* An array of file IDs, or FALSE to load all files.
* @param array $conditions
* (deprecated) An associative array of conditions on the {file_managed}
* table, where the keys are the database fields and the values are the
* values those fields must have. Instead, it is preferable to use
* Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs
* loadable by this function.
* @param array $fids
* (optional) An array of entity IDs. If omitted, all entities are loaded.
*
* @return array
* An array of file entities, indexed by fid.
*
* @todo Remove $conditions in Drupal 8.
*
* @see hook_file_load()
* @see file_load()
* @see entity_load()
* @see Drupal\entity\EntityFieldQuery
*/
function file_load_multiple($fids = array(), array $conditions = array()) {
return entity_load_multiple('file', $fids, $conditions);
function file_load_multiple(array $fids = NULL) {
return entity_load_multiple('file', $fids);
}
/**
......@@ -616,7 +608,7 @@ function file_load_multiple($fids = array(), array $conditions = array()) {
* @see file_load_multiple()
*/
function file_load($fid) {
$files = file_load_multiple(array($fid), array());
$files = file_load_multiple(array($fid));
return reset($files);
}
......@@ -803,7 +795,7 @@ function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
$file->filename = drupal_basename($uri);
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = file_load_multiple(array(), array('uri' => $uri));
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
$file->fid = $existing->fid;
......@@ -1052,7 +1044,7 @@ function file_move(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
$file->uri = $uri;
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = file_load_multiple(array(), array('uri' => $uri));
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
$delete_source = TRUE;
......@@ -1565,7 +1557,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = file_load_multiple(array(), array('uri' => $file->uri));
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $file->uri));
if (count($existing_files)) {
$existing = reset($existing_files);
$file->fid = $existing->fid;
......@@ -1858,7 +1850,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
));
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = file_load_multiple(array(), array('uri' => $uri));
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
$file->fid = $existing->fid;
......
......@@ -4638,7 +4638,8 @@ function _form_set_class(&$element, $class = array()) {
* // 1 (or no value explicitly set) means the operation is finished
* // and the batch processing can continue to the next operation.
*
* $node = node_load(array('uid' => $uid, 'type' => $type));
* $nodes = entity_load_multiple_by_properties('node', array('uid' => $uid, 'type' => $type));
* $node = reset($nodes);
* $context['results'][] = $node->nid . ' : ' . check_plain($node->label());
* $context['message'] = check_plain($node->label());
* }
......@@ -4658,7 +4659,7 @@ function _form_set_class(&$element, $class = array()) {
* ->range(0, $limit)
* ->execute();
* foreach ($result as $row) {
* $node = node_load($row->nid, NULL, TRUE);
* $node = node_load($row->nid, TRUE);
* $context['results'][] = $node->nid . ' : ' . check_plain($node->label());
* $context['sandbox']['progress']++;
* $context['sandbox']['current_node'] = $node->nid;
......
......@@ -1267,7 +1267,7 @@ function book_export_traverse($tree, $visit_func) {
foreach ($tree as $data) {
// Note- access checking is already performed when building the tree.
if ($node = node_load($data['link']['nid'], FALSE)) {
if ($node = node_load($data['link']['nid'])) {
$children = '';
if ($data['below']) {
......
......@@ -358,7 +358,7 @@ function testBookDelete() {
$this->drupalGet('node/' . $this->book->nid . '/outline/remove');
$this->assertResponse('403', t('Deleting top-level book node properly forbidden.'));
$this->drupalPost('node/' . $nodes[4]->nid . '/outline/remove', $edit, t('Remove'));
$node4 = node_load($nodes[4]->nid, NULL, TRUE);
$node4 = node_load($nodes[4]->nid, TRUE);
$this->assertTrue(empty($node4->book), t('Deleting child book node properly allowed.'));
// Delete all child book nodes and retest top-level node deletion.
......@@ -367,7 +367,7 @@ function testBookDelete() {
}
node_delete_multiple($nids);
$this->drupalPost('node/' . $this->book->nid . '/outline/remove', $edit, t('Remove'));
$node = node_load($this->book->nid, NULL, TRUE);
$node = node_load($this->book->nid, TRUE);
$this->assertTrue(empty($node->book), t('Deleting childless top-level book node properly allowed.'));
}
}
......
......@@ -1443,7 +1443,7 @@ function comment_node_search_result(Node $node) {
function comment_user_cancel($edit, $account, $method) {
switch ($method) {
case 'user_cancel_block_unpublish':
$comments = comment_load_multiple(array(), array('uid' => $account->uid));
$comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid));
foreach ($comments as $comment) {
$comment->status = 0;
comment_save($comment);
......@@ -1451,7 +1451,7 @@ function comment_user_cancel($edit, $account, $method) {
break;
case 'user_cancel_reassign':
$comments = comment_load_multiple(array(), array('uid' => $account->uid));
$comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid));
foreach ($comments as $comment) {
$comment->uid = 0;
comment_save($comment);
......@@ -1526,16 +1526,10 @@ function comment_delete_multiple($cids) {
}
/**
* Loads comments from the database.
* Loads comment entities from the database.
*
* @param array|bool $cids
* An array of comment IDs, or FALSE to load all comments.
* @param array $conditions
* (deprecated) An associative array of conditions on the {comments}
* table, where the keys are the database fields and the values are the
* values those fields must have. Instead, it is preferable to use
* Drupal\entity\EntityFieldQuery to retrieve a list of entity IDs
* loadable by this function.
* @param array $cids
* (optional) An array of entity IDs. If omitted, all entities are loaded.
* @param bool $reset
* Whether to reset the internal static entity cache. Note that the static
* cache is disabled in comment_entity_info() by default.
......@@ -1543,13 +1537,11 @@ function comment_delete_multiple($cids) {
* @return array
* An array of comment objects, indexed by comment ID.
*
* @todo Remove $conditions in Drupal 8.
*
* @see entity_load()
* @see Drupal\entity\EntityFieldQuery
*/
function comment_load_multiple($cids = array(), array $conditions = array(), $reset = FALSE) {
return entity_load_multiple('comment', $cids, $conditions, $reset);
function comment_load_multiple(array $cids = NULL, $reset = FALSE) {
return entity_load_multiple('comment', $cids, $reset);
}
/**
......@@ -1722,9 +1714,9 @@ function comment_preview(Comment $comment) {
if ($comment->pid) {
$build = array();
if ($comments = comment_load_multiple(array($comment->pid), array('status' => COMMENT_PUBLISHED))) {
$parent_comment = $comments[$comment->pid];
$build = comment_view($parent_comment, $node);
$comment = comment_load($comment->pid);
if ($comment && $comment->status == COMMENT_PUBLISHED) {
$build = comment_view($comment, $node);
}
}
else {
......
......@@ -27,8 +27,8 @@ class CommentStorageController extends DatabaseStorageController {
/**
* Overrides Drupal\entity\DatabaseStorageController::buildQuery().
*/
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
$query = parent::buildQuery($ids, $conditions, $revision_id);
protected function buildQuery($ids, $revision_id = FALSE) {
$query = parent::buildQuery($ids, $revision_id);
// Specify additional fields from the user and node tables.
$query->innerJoin('node', 'n', 'base.nid = n.nid');
$query->addField('n', 'type', 'node_type');
......@@ -41,7 +41,7 @@ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE)
/**
* Overrides Drupal\entity\DatabaseStorageController::attachLoad().
*/
protected function attachLoad(&$comments, $revision_id = FALSE) {
protected function attachLoad(&$comments, $load_revision = FALSE) {
// Set up standard comment properties.
foreach ($comments as $key => $comment) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
......@@ -49,7 +49,7 @@ protected function attachLoad(&$comments, $revision_id = FALSE) {
$comment->node_type = 'comment_node_' . $comment->node_type;
$comments[$key] = $comment;
}
parent::attachLoad($comments, $revision_id);
parent::attachLoad($comments, $load_revision);
}
/**
......
......@@ -363,7 +363,7 @@ function testCommentNodeCommentStatistics() {
// Checks the new values of node comment statistics with comment #1.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE);
$node = node_load($this->node->nid, TRUE);
$this->assertEqual($node->last_comment_name, NULL, t('The value of node last_comment_name is NULL.'));
$this->assertEqual($node->last_comment_uid, $this->web_user2->uid, t('The value of node last_comment_uid is the comment #1 uid.'));
$this->assertEqual($node->comment_count, 1, t('The value of node comment_count is 1.'));
......@@ -388,7 +388,7 @@ function testCommentNodeCommentStatistics() {
// Checks the new values of node comment statistics with comment #2 and
// ensure they haven't changed since the comment has not been moderated.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE);
$node = node_load($this->node->nid, TRUE);
$this->assertEqual($node->last_comment_name, NULL, t('The value of node last_comment_name is still NULL.'));
$this->assertEqual($node->last_comment_uid, $this->web_user2->uid, t('The value of node last_comment_uid is still the comment #1 uid.'));
$this->assertEqual($node->comment_count, 1, t('The value of node comment_count is still 1.'));
......@@ -409,7 +409,7 @@ function testCommentNodeCommentStatistics() {
// Checks the new values of node comment statistics with comment #3.
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, NULL, TRUE);
$node = node_load($this->node->nid, TRUE);
$this->assertEqual($node->last_comment_name, $comment_loaded->name, t('The value of node last_comment_name is the name of the anonymous user.'));
$this->assertEqual($node->last_comment_uid, 0, t('The value of node last_comment_uid is zero.'));
$this->assertEqual($node->comment_count, 2, t('The value of node comment_count is 2.'));
......
......@@ -141,7 +141,7 @@ function entity_info_cache_clear() {
* @param bool $reset
* Whether to reset the internal cache for the requested entity type.
*
* @return object
* @return Drupal\entity\EntityInterface
* The entity object, or FALSE if there is no entity with the given id.
*
* @see hook_entity_info()
......@@ -151,10 +151,30 @@ function entity_info_cache_clear() {
* @see Drupal\entity\EntityFieldQuery
*/
function entity_load($entity_type, $id, $reset = FALSE) {
$entities = entity_load_multiple($entity_type, array($id), array(), $reset);
$entities = entity_load_multiple($entity_type, array($id), $reset);
return isset($entities[$id]) ? $entities[$id] : FALSE;
}
/**
* Loads an entity from the database.
*
* @param string $entity_type
* The entity type to load, e.g. node or user.
* @param int $revision_id
* The id of the entity to load.
*
* @return Drupal\entity\EntityInterface
* The entity object, or FALSE if there is no entity with the given revision
* id.
*
* @see hook_entity_info()
* @see Drupal\entity\EntityStorageControllerInterface
* @see Drupal\entity\DatabaseStorageController
*/
function entity_revision_load($entity_type, $revision_id) {
return entity_get_controller($entity_type)->loadRevision($revision_id);
}
/**
* Loads an entity by UUID.
*
......@@ -174,9 +194,6 @@ function entity_load($entity_type, $id, $reset = FALSE) {
* Thrown in case the requested entity type does not support UUIDs.
*
* @see hook_entity_info()
*
* @todo D8: Make it easier to query entities by property; e.g., enhance
* EntityStorageControllerInterface with a ::loadByProperty() method.
*/
function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
$entity_info = entity_get_info($entity_type);
......@@ -185,25 +202,12 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
}
$uuid_key = $entity_info['entity keys']['uuid'];
// Look up the entity ID for the given UUID.
$entity_query = new EntityFieldQuery();
$result = $entity_query
->entityCondition('entity_type', $entity_type)
->propertyCondition($uuid_key, $uuid)
->range(0, 1)
->execute();
if (empty($result[$entity_type])) {
return FALSE;
}
$controller = entity_get_controller($entity_type);
if ($reset) {
$controller->resetCache();
}
$id = key($result[$entity_type]);
$entities = $controller->load(array($id));
return isset($entities[$id]) ? $entities[$id] : FALSE;
$entities = $controller->loadByProperties(array($uuid_key => $uuid));
return reset($entities);
}
/**
......@@ -225,31 +229,40 @@ function entity_load_by_uuid($entity_type, $uuid, $reset = FALSE) {
*
* @param string $entity_type
* The entity type to load, e.g. node or user.
* @param array|bool $ids
* An array of entity IDs, or FALSE to load all entities.
* @param array $conditions
* (deprecated) An associative array of conditions on the base table, where
* the keys are the database fields and the values are the values those
* fields must have. Instead, it is preferable to use EntityFieldQuery to
* retrieve a list of entity IDs loadable by this function.
* @param array $ids
* (optional) An array of entity IDs. If omitted, all entities are loaded.
* @param bool $reset
* Whether to reset the internal cache for the requested entity type.
*
* @return array
* An array of entity objects indexed by their ids.
*
* @todo Remove $conditions in Drupal 8.
*
* @see hook_entity_info()
* @see Drupal\entity\EntityStorageControllerInterface
* @see Drupal\entity\DatabaseStorageController
* @see Drupal\entity\EntityFieldQuery
*/
function entity_load_multiple($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) {
function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) {
if ($reset) {
entity_get_controller($entity_type)->resetCache();
}
return entity_get_controller($entity_type)->load($ids, $conditions);
return entity_get_controller($entity_type)->load($ids);
}
/**
* Load entities by their property values.
*
* @param string $entity_type
* The entity type to load, e.g. node or user.
* @param array $values
* An associative array where the keys are the property names and the
* values are the values those properties must have.
*
* @return array
* An array of entity objects indexed by their ids.
*/
function entity_load_multiple_by_properties($entity_type, array $values) {
return entity_get_controller($entity_type)->loadByProperties($values);
}
/**
......
......@@ -144,19 +144,9 @@ public function resetCache(array $ids = NULL) {
/**
* Implements Drupal\entity\EntityStorageControllerInterface::load().
*/
public function load($ids = array(), $conditions = array()) {
public function load(array $ids = NULL) {
$entities = array();
// Revisions are not statically cached, and require a different query to
// other conditions, so separate the revision id into its own variable.
if ($this->revisionKey && isset($conditions[$this->revisionKey])) {
$revision_id = $conditions[$this->revisionKey];
unset($conditions[$this->revisionKey]);
}
else {
$revision_id = FALSE;
}
// Create a new variable which is either a prepared version of the $ids
// array for later comparison with the entity cache, or FALSE if no $ids
// were passed. The $ids array is reduced as items are loaded from cache,
......@@ -165,8 +155,8 @@ public function load($ids = array(), $conditions = array()) {
$passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
// Try to load entities from the static cache, if the entity type supports
// static caching.
if ($this->cache && !$revision_id) {
$entities += $this->cacheGet($ids, $conditions);
if ($this->cache && $ids) {
$entities += $this->cacheGet($ids);
// If any entities were loaded, remove them from the ids still to load.
if ($passed_ids) {
$ids = array_keys(array_diff_key($passed_ids, $entities));
......@@ -174,11 +164,11 @@ public function load($ids = array(), $conditions = array()) {
}
// Load any remaining entities from the database. This is the case if $ids
// is set to FALSE (so we load all entities), if there are any ids left to
// load, if loading a revision, or if $conditions was passed without $ids.
if ($ids === FALSE || $ids || $revision_id || ($conditions && !$passed_ids)) {
// is set to NULL (so we load all entities) or if there are any ids left to
// load.
if ($ids === NULL || $ids) {
// Build and execute the query.
$query_result = $this->buildQuery($ids, $conditions, $revision_id)->execute();
$query_result = $this->buildQuery($ids)->execute();
if (!empty($this->entityInfo['entity class'])) {
// We provide the necessary arguments for PDO to create objects of the
......@@ -193,13 +183,13 @@ public function load($ids = array(), $conditions = array()) {
// which attaches fields (if supported by the entity type) and calls the
// entity type specific load callback, for example hook_node_load().
if (!empty($queried_entities)) {
$this->attachLoad($queried_entities, $revision_id);
$this->attachLoad($queried_entities);
$entities += $queried_entities;
}
if ($this->cache) {
// Add entities to the cache if we are not loading a revision.
if (!empty($queried_entities) && !$revision_id) {
// Add entities to the cache.
if (!empty($queried_entities)) {
$this->cacheSet($queried_entities);
}
}
......@@ -218,6 +208,62 @@ public function load($ids = array(), $conditions = array()) {
return $entities;
}
/**
* Implements Drupal\entity\EntityStorageControllerInterface::loadRevision().
*/
public function loadRevision($revision_id) {
// Build and execute the query.
$query_result = $this->buildQuery(array(), $revision_id)->execute();
if (!empty($this->entityInfo['entity class'])) {
// We provide the necessary arguments for PDO to create objects of the
// specified entity class.
// @see Drupal\entity\EntityInterface::__construct()
$query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['entity class'], array(array(), $this->entityType));
}
$queried_entities = $query_result->fetchAllAssoc($this->idKey);
// Pass the loaded entities from the database through $this->attachLoad(),
// which attaches fields (if supported by the entity type) and calls the
// entity type specific load callback, for example hook_node_load().
if (!empty($queried_entities)) {
$this->attachLoad($queried_entities, TRUE);
}
return reset($queried_entities);
}
/**
* Implements Drupal\entity\EntityStorageControllerInterface::loadByProperties().
*/
public function loadByProperties(array $values = array()) {
// Build a query to fetch the entity IDs.
$entity_query = new EntityFieldQuery();
$entity_query->entityCondition('entity_type', $this->entityType);
$this->buildPropertyQuery($entity_query, $values);
$result = $entity_query->execute();
if (empty($result[$this->entityType])) {
return array();
}
// Load and return the found entities.
return $this->load(array_keys($result[$this->entityType]));
}
/**
* Builds an entity query.
*
* @param Drupal\entity\EntityFieldQuery $entity_query
* EntityFieldQuery instance.
* @param array $values
* An associative array of properties of the entity, where the keys are the
* property names and the values are the values those properties must have.
*/
protected function buildPropertyQuery(EntityFieldQuery $entity_query, array $values) {
foreach ($values as $name => $value) {
$entity_query->propertyCondition($name, $value);
}
}
/**
* Builds the query to load the entity.
*
......@@ -230,10 +276,8 @@ public function load($ids = array(), $conditions = array()) {
* See Drupal\comment\CommentStorageController::buildQuery() or
* Drupal\taxonomy\TermStorageController::buildQuery() for examples.
*
* @param $ids
* An array of entity IDs, or FALSE to load all entities.
* @param $conditions
* An array of conditions in the form 'field' => $value.
* @param array|null $ids
* An array of entity IDs, or NULL to load all entities.
* @param $revision_id
* The ID of the revision to load, or FALSE if this query is asking for the
* most current revision(s).
......@@ -241,7 +285,7 @@ public function load($ids = array(), $conditions = array()) {
* @return SelectQuery
* A SelectQuery object for loading the entity.
*/
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
protected function buildQuery($ids, $revision_id = FALSE) {
$query = db_select($this->entityInfo['base table'], 'base');
$query->addTag($this->entityType . '_load_multiple');
......@@ -282,11 +326,6 @@ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE)
if ($ids) {
$query->condition("base.{$this->idKey}", $ids, 'IN');
}
if ($conditions) {
foreach ($conditions as $field => $value) {
$query->condition('base.' . $field, $value);
}
}
return $query;
}
......@@ -303,14 +342,13 @@ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE)
*
* @param $queried_entities
* Associative array of query results, keyed on the entity ID.
* @param $revision_id
* ID of the revision that was loaded, or FALSE if the most current revision
* was loaded.
* @param $load_revision
* (optional) TRUE if the revision should be loaded, defaults to FALSE.
*/
protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
// Attach fields.
if ($this->entityInfo['fieldable']) {
if ($revision_id) {
if ($load_revision) {
field_attach_load_revision($this->entityType, $queried_entities);
}
else {
......@@ -337,35 +375,15 @@ protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
*
* @param $ids
* If not empty, return entities that match these IDs.
* @param $conditions
* If set, return entities that match all of these conditions.
*
* @return
* Array of entities from the entity cache.
*/
protected function cacheGet($ids, $conditions = array()) {
protected function cacheGet($ids) {
$entities = array();
// Load any available entities from the internal cache.
if (!empty($this->entityCache)) {
if ($ids) {
$entities += array_intersect_key($this->entityCache, array_flip($ids));
}
// If loading entities only by conditions, fetch all available entities
// from the cache. Entities which don't match are removed later.
elseif ($conditions) {
$entities = $this->entityCache;
}
}
// Exclude any entities loaded from cache if they don't match $conditions.
// This ensures the same behavior whether loading from memory or database.
if ($conditions) {
foreach ($entities as $entity) {
$entity_values = (array) $entity;
if (array_diff_assoc($conditions, $entity_values)) {
unset($entities[$entity->{$this->idKey}]);
}
}
$entities += array_intersect_key($this->entityCache, array_flip($ids));
}
return $entities;
}
......
......@@ -42,13 +42,34 @@ public function resetCache(array $ids = NULL);
*
* @param $ids
* An array of entity IDs, or FALSE to load all entities.
* @param $conditions
* An array of conditions in the form 'field' => $value.
*
* @return
* An array of entity objects indexed by their ids.
*/
public function load($ids = array(), $conditions = array());
public function load(array $ids = NULL);
/**
* Load a specific entity revision.
*
* @param int $revision_id
* The revision id.
*
* @return Drupal\entity\EntityInterface|false
* The specified entity revision or FALSE if not found.
*/
public function loadRevision($revision_id);
/**
* Load entities by their property values.
*
* @param array $values
* An associative array where the keys are the property names and the
* values are the values those properties must have.
*
* @return array
* An array of entity objects indexed by their ids.
*/
public function loadByProperties(array $values);
/**
* Constructs a new entity object, without permanently saving it.
......
......@@ -43,7 +43,7 @@ function testCRUD() {
$entity = entity_create('entity_test', array('name' => 'test', 'uid' => NULL));
$entity->save();
$entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test')));
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test')));
$this->assertEqual($entities[0]->get('name'), 'test', 'Created and loaded entity.');
$this->assertEqual($entities[1]->get('name'), 'test', 'Created and loaded entity.');
......@@ -53,23 +53,23 @@ function testCRUD() {
$this->assertEqual($loaded_entity->id, $entity->id, 'Loaded a single entity by id.');
// Test deleting an entity.
$entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test2')));
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test2')));
$entities[0]->delete();
$entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test2')));
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test2')));
$this->assertEqual($entities, array(), 'Entity deleted.');
// Test updating an entity.
$entities = array_values(entity_test_load_multiple(FALSE, array('name' => 'test')));
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test')));
$entities[0]->set('name', 'test3');
$entities[0]->save();
$entity = entity_test_load($entities[0]->id);
$this->assertEqual($entity->get('name'), 'test3', 'Entity updated.');
// Try deleting multiple test entities by deleting all.
$ids = array_keys(entity_test_load_multiple(FALSE));
$ids = array_keys(entity_test_load_multiple());
entity_test_delete_multiple($ids);
$all = entity_test_load_multiple(FALSE);
$all = entity_test_load_multiple();
$this->assertTrue(empty($all), 'Deleted all entities.');
}
......
......@@ -211,23 +211,23 @@ function testMultilingualProperties() {
// original language is the same of one used for a translation.
$langcode = $this->langcodes[1];
entity_create('entity_test', array('uid' => $properties[$langcode]['uid']))->save();
$entities = entity_test_load_multiple(FALSE, array(), TRUE);
$entities = entity_test_load_multiple();
$this->assertEqual(count($entities), 3, 'Three entities were created.');
$entities = entity_test_load_multiple(array($translated_id), array(), TRUE);
$entities = entity_test_load_multiple(array($translated_id));
$this->assertEqual(count($entities), 1, 'One entity correctly loaded by id.');
$entities = entity_test_load_multiple(array(), array('name' => $name), TRUE);
$entities = entity_load_multiple_by_properties('entity_test', array('name' => $name));
$this->assertEqual(count($entities), 2, 'Two entities correctly loaded by name.');
// @todo The default language condition should go away in favor of an