1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<?php
/**
* @file
* Contains \Drupal\Tests\facets\Plugin\Processor\RawValueWidgetOrderProcessorTest.
*/
namespace Drupal\Tests\facets\Unit\Plugin\processor;
use Drupal\facets\Plugin\facets\processor\RawValueWidgetOrderProcessor;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
* Unit test for processor.
*
* @group facets
*/
class RawValueWidgetOrderProcessorTest extends UnitTestCase {
/**
* The processor to be tested.
*
* @var \Drupal\facets\processor\WidgetOrderProcessorInterface
*/
protected $processor;
/**
* An array containing the results before the processor has ran.
*
* @var \Drupal\facets\Result\Result[]
*/
protected $originalResults;
/**
* Creates a new processor object for use in the tests.
*/
protected function setUp() {
parent::setUp();
$this->originalResults = [
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', []);
}
/**
* Tests sorting ascending.
*/
public function testAscending() {
$sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
$expected_values = [
'Tom',
'xenu',
'thetans',
'Hubbard',
'FALSE',
'2',
'1977',
];
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
}
/**
* Tests sorting descending.
*/
public function testDescending() {
$sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
$expected_values = array_reverse([
'Tom',
'xenu',
'thetans',
'Hubbard',
'FALSE',
'2',
'1977',
]);
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
}
}
|