You are here

public function DateRangeTest::testRangeQueries in Search API Solr 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Processor/DateRangeTest.php \Drupal\Tests\search_api_solr\Kernel\Processor\DateRangeTest::testRangeQueries()
  2. 4.x tests/src/Kernel/Processor/DateRangeTest.php \Drupal\Tests\search_api_solr\Kernel\Processor\DateRangeTest::testRangeQueries()

Tests date range queries.

@dataProvider rangeQueryDataProvider

Throws

\Drupal\search_api\SearchApiException

File

tests/src/Kernel/Processor/DateRangeTest.php, line 175

Class

DateRangeTest
Tests the "Date range" processor.

Namespace

Drupal\Tests\search_api_solr\Kernel\Processor

Code

public function testRangeQueries(string $field, string $date1, string $date2) {
  $this
    ->indexItems();
  $query_helper = \Drupal::getContainer()
    ->get('search_api.query_helper');
  $query = $query_helper
    ->createQuery($this->index);
  $result = $query
    ->execute();
  $expected = [
    'node' => [
      0,
      1,
    ],
  ];
  $this
    ->assertResults($result, $expected);
  $query = $query_helper
    ->createQuery($this->index);
  $query
    ->addCondition($field, $date1);
  $result = $query
    ->execute();
  $expected = [
    'node' => [
      1,
    ],
  ];
  $this
    ->assertResults($result, $expected);
  $query = $query_helper
    ->createQuery($this->index);
  $query
    ->addCondition($field, $date2);
  $result = $query
    ->execute();
  $expected = [
    'node' => [
      0,
      1,
    ],
  ];
  $this
    ->assertResults($result, $expected);
}