summaryrefslogtreecommitdiffstats
path: root/tests/src/Unit/Plugin
diff options
context:
space:
mode:
authormr.baileys2015-10-24 14:14:51 (GMT)
committermr.baileys2015-10-24 14:15:11 (GMT)
commitb4682da325131c6d96300e72469c153748901284 (patch)
tree682524776cfa2cbefea21684d5f0feb3c207b9b5 /tests/src/Unit/Plugin
parentce6740f09e475a4a5bb9c38058552f59c53dd8e2 (diff)
Issue #2596371 by mr.baileys: Create the "indexed value" widget order processor
Diffstat (limited to 'tests/src/Unit/Plugin')
-rw-r--r--tests/src/Unit/Plugin/processor/RAwValueWidgetOrderProcessorTest.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/src/Unit/Plugin/processor/RAwValueWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/RAwValueWidgetOrderProcessorTest.php
new file mode 100644
index 0000000..7b8f12e
--- /dev/null
+++ b/tests/src/Unit/Plugin/processor/RAwValueWidgetOrderProcessorTest.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\facetapi\Plugin\Processor\RawValueWidgetOrderProcessorTest.
+ */
+
+namespace Drupal\Tests\facetapi\Unit\Plugin\Processor;
+
+use Drupal\facetapi\Plugin\facetapi\processor\RawValueWidgetOrderProcessor;
+use Drupal\facetapi\Processor\WidgetOrderProcessorInterface;
+use Drupal\facetapi\Result\Result;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @group facetapi
+ */
+class RawValueWidgetOrderProcessorTest 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('C', 'thetans', 10),
+ new Result('B', 'xenu', 5),
+ new Result('A', 'Tom', 15),
+ new Result('D', 'Hubbard', 666),
+ new Result('E', 'FALSE', 1),
+ new Result('G', '1977', 20),
+ new Result('F', '2', 22),
+ ];
+
+ $this->processor = new RawValueWidgetOrderProcessor([], 'raw_value_widget_order', []);
+ }
+
+ /**
+ * Test sorting ascending.
+ */
+ public function testAscending() {
+ $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
+ $expected_values = array('Tom', 'xenu', 'thetans', 'Hubbard', 'FALSE', '2', '1977');
+ foreach ($expected_values as $index => $value) {
+ $this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
+ }
+ }
+
+ /**
+ * Test sorting descending.
+ */
+ public function testDescending() {
+ $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
+ $expected_values = array_reverse(array('Tom', 'xenu', 'thetans', 'Hubbard', 'FALSE', '2', '1977'));
+ foreach ($expected_values as $index => $value) {
+ $this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
+ }
+ }
+
+}