class SearchApiRptTest in Search API Location 8
Unit test for query type.
@group search_api_location
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\facets_map_widget\Unit\Plugin\query_type\SearchApiRptTest
Expanded class hierarchy of SearchApiRptTest
File
- modules/
facets_map_widget/ tests/ src/ Unit/ Plugin/ query_type/ SearchApiRptTest.php, line 17
Namespace
Drupal\Tests\facets_map_widget\Unit\Plugin\query_typeView source
class SearchApiRptTest extends UnitTestCase {
/**
* Tests rpt query type without executing the query with an "AND" operator.
*/
public function testQueryTypeAnd() {
$query = new SearchApiQuery([], 'search_api_query', []);
$facet = new Facet([
'query_operator' => 'and',
], 'facets_facet');
$original_results = [
[
'count' => 3,
'filter' => 'heatmap',
],
];
$query_type = new SearchApiRpt([
'facet' => $facet,
'query' => $query,
'results' => $original_results,
], 'search_api_rpt', []);
$built_facet = $query_type
->build();
$this
->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet
->getResults();
$this
->assertTrue(is_array($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());
}
}
/**
* Tests rpt query type without executing the query with an "OR" operator.
*/
public function testQueryTypeOr() {
$query = new SearchApiQuery([], 'search_api_query', []);
$facet = new Facet([
'query_operator' => 'or',
], 'facets_facet');
$facet
->setFieldIdentifier('field_animal');
$original_results = [
[
'count' => 8,
'filter' => 'heatmap',
],
];
$query_type = new SearchApiRpt([
'facet' => $facet,
'query' => $query,
'results' => $original_results,
], 'search_api_rpt', []);
$built_facet = $query_type
->build();
$this
->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet
->getResults();
$this
->assertTrue(is_array($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());
}
}
/**
* Tests rpt query type without results.
*/
public function testEmptyResults() {
$query = new SearchApiQuery([], 'search_api_query', []);
$facet = new Facet([], 'facets_facet');
$query_type = new SearchApiRpt([
'facet' => $facet,
'query' => $query,
], 'search_api_rpt', []);
$built_facet = $query_type
->build();
$this
->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet
->getResults();
$this
->assertTrue(is_array($results));
$this
->assertEmpty($results);
}
/**
* Tests rpt query type without results.
*/
public function testConfiguration() {
$query = new SearchApiQuery([], 'search_api_query', []);
$facet = new Facet([], 'facets_facet');
$default_config = [
'facet' => $facet,
'query' => $query,
];
$query_type = new SearchApiRpt($default_config, 'search_api_rpt', []);
$this
->assertEquals([], $query_type
->defaultConfiguration());
$this
->assertEquals($default_config, $query_type
->getConfiguration());
$query_type
->setConfiguration([
'owl' => 'Long-eared owl',
]);
$this
->assertEquals([
'owl' => 'Long-eared owl',
], $query_type
->getConfiguration());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
SearchApiRptTest:: |
public | function | Tests rpt query type without results. | |
SearchApiRptTest:: |
public | function | Tests rpt query type without results. | |
SearchApiRptTest:: |
public | function | Tests rpt query type without executing the query with an "AND" operator. | |
SearchApiRptTest:: |
public | function | Tests rpt query type without executing the query with an "OR" operator. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |