1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of ViewsHandlerFilterEqualityTest.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests the core views_handler_filter_equality handler.
|
10
|
*/
|
11
|
class ViewsHandlerFilterEqualityTest extends ViewsSqlTest {
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'Filter: Equality',
|
15
|
'description' => 'Test the core views_handler_filter_equality handler.',
|
16
|
'group' => 'Views Handlers',
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* {@inheritdoc}
|
22
|
*/
|
23
|
public function setUp(array $modules = array()) {
|
24
|
parent::setUp($modules);
|
25
|
|
26
|
$this->column_map = array(
|
27
|
'views_test_name' => 'name',
|
28
|
);
|
29
|
}
|
30
|
|
31
|
function viewsData() {
|
32
|
$data = parent::viewsData();
|
33
|
$data['views_test']['name']['filter']['handler'] = 'views_handler_filter_equality';
|
34
|
|
35
|
return $data;
|
36
|
}
|
37
|
|
38
|
function testEqual() {
|
39
|
$view = $this->getBasicView();
|
40
|
|
41
|
// Change the filtering.
|
42
|
$view->display['default']->handler->override_option('filters', array(
|
43
|
'name' => array(
|
44
|
'id' => 'name',
|
45
|
'table' => 'views_test',
|
46
|
'field' => 'name',
|
47
|
'relationship' => 'none',
|
48
|
'operator' => '=',
|
49
|
'value' => array('value' => 'Ringo'),
|
50
|
),
|
51
|
));
|
52
|
|
53
|
$this->executeView($view);
|
54
|
$resultset = array(
|
55
|
array(
|
56
|
'name' => 'Ringo',
|
57
|
),
|
58
|
);
|
59
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
60
|
}
|
61
|
|
62
|
public function testEqualGroupedExposed() {
|
63
|
$filters = $this->getGroupedExposedFilters();
|
64
|
$view = $this->getBasicPageView();
|
65
|
|
66
|
// Filter: Name, Operator: =, Value: Ringo.
|
67
|
$filters['name']['group_info']['default_group'] = 1;
|
68
|
$view->set_display('page_1');
|
69
|
$view->display['page_1']->handler->override_option('filters', $filters);
|
70
|
|
71
|
$this->executeView($view);
|
72
|
$resultset = array(
|
73
|
array(
|
74
|
'name' => 'Ringo',
|
75
|
),
|
76
|
);
|
77
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
78
|
}
|
79
|
|
80
|
function testNotEqual() {
|
81
|
$view = $this->getBasicView();
|
82
|
|
83
|
// Change the filtering.
|
84
|
$view->display['default']->handler->override_option('filters', array(
|
85
|
'name' => array(
|
86
|
'id' => 'name',
|
87
|
'table' => 'views_test',
|
88
|
'field' => 'name',
|
89
|
'relationship' => 'none',
|
90
|
'operator' => '!=',
|
91
|
'value' => array('value' => 'Ringo'),
|
92
|
),
|
93
|
));
|
94
|
|
95
|
$this->executeView($view);
|
96
|
$resultset = array(
|
97
|
array(
|
98
|
'name' => 'John',
|
99
|
),
|
100
|
array(
|
101
|
'name' => 'George',
|
102
|
),
|
103
|
array(
|
104
|
'name' => 'Paul',
|
105
|
),
|
106
|
array(
|
107
|
'name' => 'Meredith',
|
108
|
),
|
109
|
);
|
110
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
111
|
}
|
112
|
|
113
|
public function testEqualGroupedNotExposed() {
|
114
|
$filters = $this->getGroupedExposedFilters();
|
115
|
$view = $this->getBasicPageView();
|
116
|
|
117
|
// Filter: Name, Operator: !=, Value: Ringo.
|
118
|
$filters['name']['group_info']['default_group'] = 2;
|
119
|
$view->set_display('page_1');
|
120
|
$view->display['page_1']->handler->override_option('filters', $filters);
|
121
|
|
122
|
$this->executeView($view);
|
123
|
$resultset = array(
|
124
|
array(
|
125
|
'name' => 'John',
|
126
|
),
|
127
|
array(
|
128
|
'name' => 'George',
|
129
|
),
|
130
|
array(
|
131
|
'name' => 'Paul',
|
132
|
),
|
133
|
array(
|
134
|
'name' => 'Meredith',
|
135
|
),
|
136
|
);
|
137
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
138
|
}
|
139
|
|
140
|
|
141
|
protected function getGroupedExposedFilters() {
|
142
|
$filters = array(
|
143
|
'name' => array(
|
144
|
'id' => 'name',
|
145
|
'table' => 'views_test',
|
146
|
'field' => 'name',
|
147
|
'relationship' => 'none',
|
148
|
'exposed' => TRUE,
|
149
|
'expose' => array(
|
150
|
'operator' => 'name_op',
|
151
|
'label' => 'name',
|
152
|
'identifier' => 'name',
|
153
|
),
|
154
|
'is_grouped' => TRUE,
|
155
|
'group_info' => array(
|
156
|
'label' => 'name',
|
157
|
'identifier' => 'name',
|
158
|
'default_group' => 'All',
|
159
|
'group_items' => array(
|
160
|
1 => array(
|
161
|
'title' => 'Name is equal to Ringo',
|
162
|
'operator' => '=',
|
163
|
'value' => array('value' => 'Ringo'),
|
164
|
),
|
165
|
2 => array(
|
166
|
'title' => 'Name is not equal to Ringo',
|
167
|
'operator' => '!=',
|
168
|
'value' => array('value' => 'Ringo'),
|
169
|
),
|
170
|
),
|
171
|
),
|
172
|
),
|
173
|
);
|
174
|
return $filters;
|
175
|
}
|
176
|
|
177
|
}
|