1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of ViewsHandlerSortTest.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests for core views_handler_sort handler.
|
10
|
*/
|
11
|
class ViewsHandlerSortTest extends ViewsSqlTest {
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'Sort: generic',
|
15
|
'description' => 'Test the core views_handler_sort handler.',
|
16
|
'group' => 'Views Handlers',
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* Tests numeric ordering of the result set.
|
22
|
*/
|
23
|
public function testNumericOrdering() {
|
24
|
$view = $this->getBasicView();
|
25
|
|
26
|
// Change the ordering.
|
27
|
$view->display['default']->handler->override_option('sorts', array(
|
28
|
'age' => array(
|
29
|
'order' => 'ASC',
|
30
|
'id' => 'age',
|
31
|
'table' => 'views_test',
|
32
|
'field' => 'age',
|
33
|
'relationship' => 'none',
|
34
|
),
|
35
|
));
|
36
|
|
37
|
// Execute the view.
|
38
|
$this->executeView($view);
|
39
|
|
40
|
// Verify the result.
|
41
|
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
42
|
$this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age'), array(
|
43
|
'views_test_name' => 'name',
|
44
|
'views_test_age' => 'age',
|
45
|
));
|
46
|
|
47
|
$view = $this->getBasicView();
|
48
|
|
49
|
// Reverse the ordering.
|
50
|
$view->display['default']->handler->override_option('sorts', array(
|
51
|
'age' => array(
|
52
|
'order' => 'DESC',
|
53
|
'id' => 'age',
|
54
|
'table' => 'views_test',
|
55
|
'field' => 'age',
|
56
|
'relationship' => 'none',
|
57
|
),
|
58
|
));
|
59
|
|
60
|
// Execute the view.
|
61
|
$this->executeView($view);
|
62
|
|
63
|
// Verify the result.
|
64
|
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
65
|
$this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age', TRUE), array(
|
66
|
'views_test_name' => 'name',
|
67
|
'views_test_age' => 'age',
|
68
|
));
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Tests string ordering of the result set.
|
73
|
*/
|
74
|
public function testStringOrdering() {
|
75
|
$view = $this->getBasicView();
|
76
|
|
77
|
// Change the ordering.
|
78
|
$view->display['default']->handler->override_option('sorts', array(
|
79
|
'name' => array(
|
80
|
'order' => 'ASC',
|
81
|
'id' => 'name',
|
82
|
'table' => 'views_test',
|
83
|
'field' => 'name',
|
84
|
'relationship' => 'none',
|
85
|
),
|
86
|
));
|
87
|
|
88
|
// Execute the view.
|
89
|
$this->executeView($view);
|
90
|
|
91
|
// Verify the result.
|
92
|
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
93
|
$this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name'), array(
|
94
|
'views_test_name' => 'name',
|
95
|
'views_test_age' => 'age',
|
96
|
));
|
97
|
|
98
|
$view = $this->getBasicView();
|
99
|
|
100
|
// Reverse the ordering.
|
101
|
$view->display['default']->handler->override_option('sorts', array(
|
102
|
'name' => array(
|
103
|
'order' => 'DESC',
|
104
|
'id' => 'name',
|
105
|
'table' => 'views_test',
|
106
|
'field' => 'name',
|
107
|
'relationship' => 'none',
|
108
|
),
|
109
|
));
|
110
|
|
111
|
// Execute the view.
|
112
|
$this->executeView($view);
|
113
|
|
114
|
// Verify the result.
|
115
|
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
116
|
$this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name', TRUE), array(
|
117
|
'views_test_name' => 'name',
|
118
|
'views_test_age' => 'age',
|
119
|
));
|
120
|
}
|
121
|
|
122
|
}
|