You are here

public function SearchApiStringTest::testTrim in Facets 8

Tests trimming in ::build.

@dataProvider provideTrimValues

File

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

Class

SearchApiStringTest
Unit test for query type.

Namespace

Drupal\Tests\facets\Unit\Plugin\query_type

Code

public function testTrim($expected_value, $input_value) {
  $query = new SearchApiQuery([], 'search_api_query', []);
  $facet = new Facet([], 'facets_facet');
  $original_results = [
    [
      'count' => 1,
      'filter' => $input_value,
    ],
  ];
  $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));
  $this
    ->assertInstanceOf(ResultInterface::class, $results[0]);
  $this
    ->assertEquals(1, $results[0]
    ->getCount());
  $this
    ->assertEquals($expected_value, $results[0]
    ->getDisplayValue());
}