You are here

public function SearchApiStringTest::testQueryTypeAnd in Facets 8

Tests string query type without executing the query with an "AND" operator.

File

tests/src/Unit/Plugin/query_type/SearchApiStringTest.php, line 22

Class

SearchApiStringTest
Unit test for query type.

Namespace

Drupal\Tests\facets\Unit\Plugin\query_type

Code

public function testQueryTypeAnd() {
  $query = new SearchApiQuery([], 'search_api_query', []);
  $facet = new Facet([
    'query_operator' => 'and',
  ], 'facets_facet');
  $original_results = [
    [
      'count' => 3,
      'filter' => 'badger',
    ],
    [
      'count' => 5,
      'filter' => 'mushroom',
    ],
    [
      'count' => 7,
      'filter' => 'narwhal',
    ],
    [
      'count' => 9,
      'filter' => 'unicorn',
    ],
  ];
  $query_type = new SearchApiString([
    'facet' => $facet,
    'query' => $query,
    'results' => $original_results,
  ], 'search_api_string', []);
  $built_facet = $query_type
    ->build();
  $this
    ->assertInstanceOf(FacetInterface::class, $built_facet);
  $results = $built_facet
    ->getResults();
  $this
    ->assertSame('array', gettype($results));
  foreach ($original_results as $k => $result) {
    $this
      ->assertInstanceOf(ResultInterface::class, $results[$k]);
    $this
      ->assertEquals($result['count'], $results[$k]
      ->getCount());
    $this
      ->assertEquals($result['filter'], $results[$k]
      ->getDisplayValue());
  }
}