Fetches the results of an EntityFieldQuery and compares.
$query: An EntityFieldQuery to run.
$intended_results: A list of results, every entry is again a list, first being the entity type, the second being the entity_id.
$message: The message to be displayed as the result of this test.
$ordered: If FALSE then the result of EntityFieldQuery will match $intended_results even if the order is not the same. If TRUE then order should match too.
function assertEntityFieldQuery($query, $intended_results, $message, $ordered = FALSE) {
$results = array();
try {
foreach ($query
->execute() as $entity_type => $entity_ids) {
foreach ($entity_ids as $entity_id => $stub_entity) {
$results[] = array(
$entity_type,
$entity_id,
);
}
}
if (!isset($ordered) || !$ordered) {
sort($results);
sort($intended_results);
}
$this
->assertEqual($results, $intended_results, $message);
} catch (Exception $e) {
$this
->fail('Exception thrown: ' . $e
->getMessage());
}
}