summaryrefslogtreecommitdiffstats
path: root/tests/src/Unit/Plugin
diff options
context:
space:
mode:
authorJoris Vercammen2015-10-21 12:56:35 (GMT)
committerJoris Vercammen2015-10-21 12:56:35 (GMT)
commit7623ba8b142187b056acdfaf2fda01833d7dbdd7 (patch)
treee48b102ed1a68762e81b265266d3b8d26da9f62d /tests/src/Unit/Plugin
parentebc07552c48b9c3241c21e9bd5c0ff1f5b09e282 (diff)
Issue #2588731: Interfaces for processors + add default widgetconfig processor + move url processor to processor
Diffstat (limited to 'tests/src/Unit/Plugin')
-rw-r--r--tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php
new file mode 100644
index 0000000..3e30c4f
--- /dev/null
+++ b/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\facetapi\Plugin\Processor\CountWidgetOrderProcessorTest.
+ */
+
+namespace Drupal\Tests\facetapi\Unit\Plugin\Processor;
+
+use Drupal\facetapi\Plugin\facetapi\processor\CountWidgetOrderProcessor;
+use Drupal\facetapi\Processor\WidgetOrderProcessorInterface;
+use Drupal\facetapi\Result\Result;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @group facetapi
+ */
+class CountWidgetOrderProcessorTest extends UnitTestCase {
+
+ /**
+ * The processor to be tested.
+ *
+ * @var WidgetOrderProcessorInterface
+ */
+ protected $processor;
+
+ /**
+ * Creates a new processor object for use in the tests.
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->processor = new CountWidgetOrderProcessor([], 'count_widget_order', []);
+ }
+
+ /**
+ * Test sorting ascending.
+ */
+ public function testAscending() {
+ $results = [
+ new Result('llama', 10),
+ new Result('badger', 5),
+ new Result('duck', 15),
+ ];
+
+ $sorted_results = $this->processor->sortResults($results, 'ASC');
+
+ $this->assertEquals(5, $sorted_results[0]->getCount());
+ $this->assertEquals('badger', $sorted_results[0]->getValue());
+ $this->assertEquals(10, $sorted_results[1]->getCount());
+ $this->assertEquals('llama', $sorted_results[1]->getValue());
+ $this->assertEquals(15, $sorted_results[2]->getCount());
+ $this->assertEquals('duck', $sorted_results[2]->getValue());
+ }
+
+ /**
+ * Test sorting descending.
+ */
+ public function testDescending() {
+ $results = [
+ new Result('llama', 10),
+ new Result('badger', 5),
+ new Result('duck', 15),
+ ];
+
+ /** @var Result[] $sorted_results */
+ $sorted_results = $this->processor->sortResults($results, 'DESC');
+
+ $this->assertEquals(15, $sorted_results[0]->getCount());
+ $this->assertEquals('duck', $sorted_results[0]->getValue());
+ $this->assertEquals(10, $sorted_results[1]->getCount());
+ $this->assertEquals('llama', $sorted_results[1]->getValue());
+ $this->assertEquals(5, $sorted_results[2]->getCount());
+ $this->assertEquals('badger', $sorted_results[2]->getValue());
+ }
+
+}