You are here

protected function ViewsTest::checkResults in Search API 8

Checks the Views results for a certain set of parameters.

Parameters

array $query: The GET parameters to set for the view.

int[]|null $expected_results: (optional) The IDs of the expected results; or NULL to skip checking the results.

string $label: (optional) A label for this search, to include in assert messages.

string $arguments: (optional) A string to append to the search path.

4 calls to ViewsTest::checkResults()
ViewsTest::checkExposedSearchFields in tests/src/Functional/ViewsTest.php
Verifies that exposed fulltext fields work correctly.
ViewsTest::regressionTest2869121 in tests/src/Functional/ViewsTest.php
Tests setting the "Fulltext search" filter to "Required".
ViewsTest::regressionTest3031991 in tests/src/Functional/ViewsTest.php
Tests the interaction of multiple fulltext filters.
ViewsTest::testSearchView in tests/src/Functional/ViewsTest.php
Tests a view with exposed filters.

File

tests/src/Functional/ViewsTest.php, line 611

Class

ViewsTest
Tests the Views integration of the Search API.

Namespace

Drupal\Tests\search_api\Functional

Code

protected function checkResults(array $query, array $expected_results = NULL, $label = 'Search', $arguments = '') {
  $this
    ->drupalGet('search-api-test/' . $arguments, [
    'query' => $query,
  ]);
  if (isset($expected_results)) {
    $count = count($expected_results);
    if ($count) {
      $this
        ->assertSession()
        ->pageTextContains("Displaying {$count} search results");
    }
    else {
      $this
        ->assertSession()
        ->pageTextNotContains('search results');
    }
    $expected_results = array_combine($expected_results, $expected_results);
    $actual_results = [];
    foreach ($this->entities as $id => $entity) {
      $entity_label = Html::escape($entity
        ->label());
      if (strpos($this
        ->getSession()
        ->getPage()
        ->getContent(), ">{$entity_label}<") !== FALSE) {
        $actual_results[$id] = $id;
      }
    }
    $this
      ->assertEquals($expected_results, $actual_results, "{$label} returned correct results.");
  }
}