summaryrefslogtreecommitdiffstats
path: root/tests/src/Unit/Plugin
diff options
context:
space:
mode:
authormr.baileys2015-11-01 10:05:51 (GMT)
committerJoris Vercammen2015-11-01 10:05:51 (GMT)
commit63aa103b5f1d449f95710e52d8a303f2ec904198 (patch)
tree1681ee11c83a2120896deaf64d19156d4da87525 /tests/src/Unit/Plugin
parent39a98bf67a2250ca99ce5e2c03b454d52684dec3 (diff)
Issue #2596365 by mr.baileys: Create the "facet active" widget order processor
Diffstat (limited to 'tests/src/Unit/Plugin')
-rw-r--r--tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
new file mode 100644
index 0000000..f0f2f23
--- /dev/null
+++ b/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\facetapi\Plugin\Processor\ActiveWidgetOrderProcessorTest.
+ */
+
+namespace Drupal\Tests\facetapi\Unit\Plugin\Processor;
+
+use Drupal\facetapi\Plugin\facetapi\processor\ActiveWidgetOrderProcessor;
+use Drupal\facetapi\Processor\WidgetOrderProcessorInterface;
+use Drupal\facetapi\Result\Result;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @group facetapi
+ */
+class ActiveWidgetOrderProcessorTest extends UnitTestCase {
+
+ /**
+ * The processor to be tested.
+ *
+ * @var WidgetOrderProcessorInterface
+ */
+ protected $processor;
+
+ /**
+ * An array containing the results before the processor has ran.
+ *
+ * @var \Drupal\facetapi\Result\Result[]
+ */
+ protected $original_results;
+
+ /**
+ * Creates a new processor object for use in the tests.
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->original_results = [
+ new Result('Boxer', 'Boxer', 10),
+ new Result('Old Major', 'Old Major', 3),
+ new Result('Minimus', 'Minimus', 60),
+ new Result('Mr Whymper', 'Mr. Whymper', 1),
+ new Result('Clover', 'Clover', 50),
+ ];
+
+ $this->original_results[1]->setActiveState(true);
+ $this->original_results[2]->setActiveState(true);
+ $this->original_results[3]->setActiveState(true);
+
+ $this->processor = new ActiveWidgetOrderProcessor([], 'active_widget_order', []);
+ }
+
+ /**
+ * Test sorting ascending.
+ */
+ public function testAscending() {
+ $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
+ $expected_values = [true, true, true, false, false];
+ foreach ($expected_values as $index => $value) {
+ $this->assertEquals($value, $sorted_results[$index]->isActive());
+ }
+ }
+
+ /**
+ * Test sorting descending.
+ */
+ public function testDescending() {
+ $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
+ $expected_values = array_reverse([true, true, true, false, false]);
+ foreach ($expected_values as $index => $value) {
+ $this->assertEquals($value, $sorted_results[$index]->isActive());
+ }
+ }
+
+}