summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorJoris Vercammen2015-11-11 21:37:05 (GMT)
committerJoris Vercammen2015-11-11 21:37:05 (GMT)
commit08f528cbe173fae5055c282f0db5e4aebed2b1cf (patch)
treee870ca2835918760072a9a22617a205c3f8718d1 /tests/src
parent91f378704c240666765a99f61e181572027f2ff3 (diff)
Add basic unit test for searchapi string query type.
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/Unit/Plugin/query_type/SearchApiStringTest.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php b/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
new file mode 100644
index 0000000..89d00d7
--- /dev/null
+++ b/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
@@ -0,0 +1,82 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\facetapi\Plugin\query_string\SearchApiStringTest.
+ */
+
+namespace Drupal\Tests\facetapi\Unit\Plugin\query_string;
+
+use Drupal\facetapi\Entity\Facet;
+use Drupal\facetapi\Plugin\facetapi\query_type\SearchApiString;
+use Drupal\search_api\Plugin\views\query\SearchApiQuery;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @group facetapi
+ */
+
+class SearchApiStringTest extends UnitTestCase {
+
+ /**
+ * Test string query type without executing the query.
+ */
+ public function testQueryType() {
+ $query = new SearchApiQuery([], 'search_api_query', []);
+ $facet = new Facet([], 'facetapi_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('\Drupal\facetapi\FacetInterface', $built_facet);
+
+ $results = $built_facet->getResults();
+ $this->assertInternalType('array', $results);
+
+ foreach ($original_results as $k => $result) {
+ $this->assertInstanceOf('\Drupal\facetapi\Result\ResultInterface', $results[$k]);
+ $this->assertEquals($result['count'], $results[$k]->getCount());
+ $this->assertEquals($result['filter'], $results[$k]->getDisplayValue());
+ }
+ }
+
+ /**
+ * Test string query type without results.
+ */
+ public function testEmptyResults() {
+ $query = new SearchApiQuery([], 'search_api_query', []);
+ $facet = new Facet([], 'facetapi_facet');
+
+ $query_type = new SearchApiString(
+ [
+ 'facet' => $facet,
+ 'query' => $query,
+ ],
+ 'search_api_string',
+ []
+ );
+
+ $built_facet = $query_type->build();
+ $this->assertInstanceOf('\Drupal\facetapi\FacetInterface', $built_facet);
+
+ $results = $built_facet->getResults();
+ $this->assertInternalType('array', $results);
+ $this->assertEmpty($results);
+ }
+
+}