You are here

protected function ResultsTrait::assertResults in Search API 8

Asserts that the search results contain the expected IDs.

Parameters

\Drupal\search_api\Query\ResultSetInterface $result: The search results.

int[][] $expected: The expected entity IDs, grouped by entity type and with their indexes in this object's respective array properties as the values.

12 calls to ResultsTrait::assertResults()
AddHierarchyTest::testPreprocessIndexItems in tests/src/Kernel/Processor/AddHierarchyTest.php
Tests non-taxonomy-based hierarchy.
AddHierarchyTest::testPreprocessIndexItemsTaxonomy in tests/src/Kernel/Processor/AddHierarchyTest.php
Tests taxonomy-based hierarchy indexing.
AddHierarchyTest::testRegression3059312 in tests/src/Kernel/Processor/AddHierarchyTest.php
Tests adding values to Fulltext fields.
ContentAccessTest::testQueryAccessAll in tests/src/Kernel/Processor/ContentAccessTest.php
Tests searching when content is accessible to all.
ContentAccessTest::testQueryAccessBypass in tests/src/Kernel/Processor/ContentAccessTest.php
Tests whether the "search_api_bypass_access" query option is respected.

... See full list

File

tests/src/Kernel/ResultsTrait.php, line 22

Class

ResultsTrait
Defines a trait for testing results.

Namespace

Drupal\Tests\search_api\Kernel

Code

protected function assertResults(ResultSetInterface $result, array $expected) {
  $results = array_keys($result
    ->getResultItems());
  sort($results);
  $ids = [];
  foreach ($expected as $entity_type => $items) {
    $datasource_id = "entity:{$entity_type}";
    foreach ($items as $i) {
      if ($entity_type == 'user') {
        $id = $i . ':en';
      }
      else {

        /** @var \Drupal\Core\Entity\EntityInterface $entity */
        $entity = $this->{"{$entity_type}s"}[$i];
        $id = $entity
          ->id() . ':en';
      }
      $ids[] = Utility::createCombinedId($datasource_id, $id);
    }
  }
  sort($ids);
  $this
    ->assertEquals($ids, $results);
}