You are here

public function MongoDbEntityFieldQueryTestCase::assertEntityFieldQuery in MongoDB 7

Fetches the results of an EntityFieldQuery and compares.

Parameters

\EntityFieldQuery $query: An EntityFieldQuery to run.

array $intended_results: A list of results, every entry is again a list, first being the entity type, the second being the entity_id.

string $message: The message to be displayed as the result of this test.

bool $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.

1 call to MongoDbEntityFieldQueryTestCase::assertEntityFieldQuery()
MongoDbEntityFieldQueryTestCase::testEntityFieldQuery in mongodb_field_storage/mongodb_field_storage.test
Tests EntityFieldQuery.

File

mongodb_field_storage/mongodb_field_storage.test, line 878
Contains MongoDB Field AttachStorage and Query TestCases.

Class

MongoDbEntityFieldQueryTestCase

Code

public function assertEntityFieldQuery(EntityFieldQuery $query, array $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);
    }
    if ($results != $intended_results) {
      debug($results);
      debug($intended_results);
    }
    $this
      ->assertEqual($results, $intended_results, $message);
  } catch (EntityFieldQueryException $e) {
    $this
      ->fail('Exception thrown: ' . $e
      ->getMessage());
  }
}