Révision 6f57d8c7
Ajouté par Assos Assos il y a environ 9 ans
drupal7/sites/all/modules/views/tests/views_groupby.test | ||
---|---|---|
108 | 108 |
} |
109 | 109 |
|
110 | 110 |
/** |
111 |
* @param $group_by |
|
112 |
* Which group_by function should be used, for example sum or count. |
|
111 |
* @param string|null $group_by |
|
112 |
* (optional) Which group_by function should be used, for example sum or |
|
113 |
* count. If omitted, the aggregation is tested with no group function. |
|
114 |
* @param array|null $values |
|
115 |
* (optional) Expected values. |
|
113 | 116 |
*/ |
114 |
function GroupByTestHelper($group_by, $values) {
|
|
115 |
// Create 2 nodes of type1 and 3 nodes of type2
|
|
117 |
function GroupByTestHelper($group_by = NULL, $values = NULL) {
|
|
118 |
// Create 4 nodes of type1 and 3 nodes of type2
|
|
116 | 119 |
$type1 = $this->drupalCreateContentType(); |
117 | 120 |
$type2 = $this->drupalCreateContentType(); |
118 | 121 |
|
... | ... | |
136 | 139 |
$output = $view->execute_display(); |
137 | 140 |
|
138 | 141 |
$this->assertEqual(count($view->result), 2, 'Make sure the count of items is right.'); |
142 |
|
|
143 |
$results = array(); |
|
144 |
// There's no need for a function in order to have aggregation. |
|
145 |
if (empty($group_by)) { |
|
146 |
$types = array($type1->type, $type2->type); |
|
147 |
$results = array_map(function ($item) { return $item->node_type; }, $view->result); |
|
148 |
sort($types); |
|
149 |
sort($results); |
|
150 |
$this->assertIdentical($results, $types); |
|
151 |
// Exit here with no aggregation function. |
|
152 |
return; |
|
153 |
} |
|
154 |
|
|
139 | 155 |
// Group by nodetype to identify the right count. |
140 | 156 |
foreach ($view->result as $item) { |
141 | 157 |
$results[$item->node_type] = $item->nid; |
... | ... | |
144 | 160 |
$this->assertEqual($results[$type2->type], $values[1]); |
145 | 161 |
} |
146 | 162 |
|
147 |
function viewsGroupByViewHelper($group_by) { |
|
163 |
function viewsGroupByViewHelper($group_by = NULL) {
|
|
148 | 164 |
$view = new view; |
149 | 165 |
$view->name = 'group_by_count'; |
150 | 166 |
$view->description = ''; |
... | ... | |
164 | 180 |
$handler->display->display_options['pager']['type'] = 'some'; |
165 | 181 |
$handler->display->display_options['style_plugin'] = 'default'; |
166 | 182 |
$handler->display->display_options['row_plugin'] = 'fields'; |
167 |
/* Field: Content: Nid */ |
|
168 |
$handler->display->display_options['fields']['nid']['id'] = 'nid'; |
|
169 |
$handler->display->display_options['fields']['nid']['table'] = 'node'; |
|
170 |
$handler->display->display_options['fields']['nid']['field'] = 'nid'; |
|
171 |
$handler->display->display_options['fields']['nid']['group_type'] = $group_by; |
|
172 |
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0; |
|
173 |
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0; |
|
174 |
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0; |
|
175 |
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1; |
|
176 |
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1; |
|
177 |
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0; |
|
178 |
$handler->display->display_options['fields']['nid']['alter']['html'] = 0; |
|
179 |
$handler->display->display_options['fields']['nid']['hide_empty'] = 0; |
|
180 |
$handler->display->display_options['fields']['nid']['empty_zero'] = 0; |
|
181 |
$handler->display->display_options['fields']['nid']['link_to_node'] = 0; |
|
183 |
|
|
184 |
// The test view has 2 fields ('nid' and 'type'). Don't add 'nid' when |
|
185 |
// having no aggregation function. We just want to aggregate on node type. |
|
186 |
if (!empty($group_by)) { |
|
187 |
/* Field: Content: Nid */ |
|
188 |
$handler->display->display_options['fields']['nid']['id'] = 'nid'; |
|
189 |
$handler->display->display_options['fields']['nid']['table'] = 'node'; |
|
190 |
$handler->display->display_options['fields']['nid']['field'] = 'nid'; |
|
191 |
$handler->display->display_options['fields']['nid']['group_type'] = $group_by; |
|
192 |
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0; |
|
193 |
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0; |
|
194 |
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0; |
|
195 |
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1; |
|
196 |
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1; |
|
197 |
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0; |
|
198 |
$handler->display->display_options['fields']['nid']['alter']['html'] = 0; |
|
199 |
$handler->display->display_options['fields']['nid']['hide_empty'] = 0; |
|
200 |
$handler->display->display_options['fields']['nid']['empty_zero'] = 0; |
|
201 |
$handler->display->display_options['fields']['nid']['link_to_node'] = 0; |
|
202 |
} |
|
203 |
|
|
182 | 204 |
/* Field: Content: Type */ |
183 | 205 |
$handler->display->display_options['fields']['type']['id'] = 'type'; |
184 | 206 |
$handler->display->display_options['fields']['type']['table'] = 'node'; |
... | ... | |
218 | 240 |
$this->GroupByTestHelper('max', array(4, 7)); |
219 | 241 |
} |
220 | 242 |
|
243 |
function testGroupByNone() { |
|
244 |
$this->GroupByTestHelper(); |
|
245 |
} |
|
246 |
|
|
221 | 247 |
public function testGroupByCountOnlyFilters() { |
222 | 248 |
// Check if GROUP BY and HAVING are included when a view |
223 | 249 |
// Doesn't display SUM, COUNT, MAX... functions in SELECT statment |
Formats disponibles : Unified diff
Weekly update of contrib modules