1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Definition of ViewsPagerTest.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Tests the pluggable pager system.
|
10 |
|
|
*/
|
11 |
|
|
class ViewsPagerTest extends ViewsSqlTest {
|
12 |
|
|
public static function getInfo() {
|
13 |
|
|
return array(
|
14 |
|
|
'name' => 'Pager',
|
15 |
|
|
'description' => 'Test the pluggable pager system',
|
16 |
|
|
'group' => 'Views Plugins',
|
17 |
|
|
);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
public function setUp() {
|
21 |
|
|
parent::setUp('views', 'views_ui', 'views_test');
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Pagers was sometimes not stored.
|
26 |
|
|
*
|
27 |
|
|
* @see http://drupal.org/node/652712
|
28 |
|
|
*/
|
29 |
|
|
public function testStorePagerSettings() {
|
30 |
|
|
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
31 |
|
|
$this->drupalLogin($admin_user);
|
32 |
|
|
// Test behaviour described in http://drupal.org/node/652712#comment-2354918.
|
33 |
|
|
|
34 |
|
|
$this->drupalGet('admin/structure/views/view/frontpage/edit');
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
$edit = array(
|
38 |
|
|
'pager_options[items_per_page]' => 20,
|
39 |
|
|
);
|
40 |
|
|
$this->drupalPost('admin/structure/views/nojs/display/frontpage/default/pager_options', $edit, t('Apply'));
|
41 |
|
|
$this->assertText('20 items');
|
42 |
|
|
|
43 |
|
|
// Change type and check whether the type is new type is stored.
|
44 |
|
|
$edit = array();
|
45 |
|
|
$edit = array(
|
46 |
|
|
'pager[type]' => 'mini',
|
47 |
|
|
);
|
48 |
|
|
$this->drupalPost('admin/structure/views/nojs/display/frontpage/default/pager', $edit, t('Apply'));
|
49 |
|
|
$this->drupalGet('admin/structure/views/view/frontpage/edit');
|
50 |
|
|
$this->assertText('Mini', 'Changed pager plugin, should change some text');
|
51 |
|
|
|
52 |
|
|
// Test behaviour described in http://drupal.org/node/652712#comment-2354400
|
53 |
|
|
$view = $this->viewsStorePagerSettings();
|
54 |
|
|
// Make it editable in the admin interface.
|
55 |
|
|
$view->save();
|
56 |
|
|
|
57 |
|
|
$this->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
|
58 |
|
|
|
59 |
|
|
$edit = array();
|
60 |
|
|
$edit = array(
|
61 |
|
|
'pager[type]' => 'full',
|
62 |
|
|
);
|
63 |
|
|
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager', $edit, t('Apply'));
|
64 |
|
|
$this->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
|
65 |
|
|
$this->assertText('Full');
|
66 |
|
|
|
67 |
|
|
$edit = array(
|
68 |
|
|
'pager_options[items_per_page]' => 20,
|
69 |
|
|
);
|
70 |
|
|
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options', $edit, t('Apply'));
|
71 |
|
|
$this->assertText('20 items');
|
72 |
|
|
|
73 |
|
|
// add new display and test the settings again, by override it.
|
74 |
|
|
$edit = array( );
|
75 |
|
|
// Add a display and override the pager settings.
|
76 |
|
|
$this->drupalPost('admin/structure/views/view/test_store_pager_settings/edit', $edit, t('Add Page'));
|
77 |
|
|
$edit = array(
|
78 |
|
|
'override[dropdown]' => 'page_1',
|
79 |
|
|
);
|
80 |
|
|
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager', $edit, t('Apply'));
|
81 |
|
|
|
82 |
|
|
$edit = array(
|
83 |
|
|
'pager[type]' => 'mini',
|
84 |
|
|
);
|
85 |
|
|
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager', $edit, t('Apply'));
|
86 |
|
|
$this->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
|
87 |
|
|
$this->assertText('Mini', 'Changed pager plugin, should change some text');
|
88 |
|
|
|
89 |
|
|
$edit = array(
|
90 |
|
|
'pager_options[items_per_page]' => 10,
|
91 |
|
|
);
|
92 |
|
|
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options', $edit, t('Apply'));
|
93 |
|
|
$this->assertText('20 items');
|
94 |
|
|
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
public function viewsStorePagerSettings() {
|
98 |
|
|
$view = new view;
|
99 |
|
|
$view->name = 'test_store_pager_settings';
|
100 |
|
|
$view->description = '';
|
101 |
|
|
$view->tag = '';
|
102 |
|
|
$view->view_php = '';
|
103 |
|
|
$view->base_table = 'node';
|
104 |
|
|
$view->is_cacheable = FALSE;
|
105 |
|
|
$view->api_version = 3;
|
106 |
|
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
107 |
|
|
|
108 |
|
|
/* Display: Master */
|
109 |
|
|
$handler = $view->new_display('default', 'Master', 'default');
|
110 |
|
|
$handler->display->display_options['access']['type'] = 'none';
|
111 |
|
|
$handler->display->display_options['cache']['type'] = 'none';
|
112 |
|
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
113 |
|
|
$handler->display->display_options['pager']['type'] = 'none';
|
114 |
|
|
$handler->display->display_options['style_plugin'] = 'default';
|
115 |
|
|
$handler->display->display_options['row_plugin'] = 'node';
|
116 |
|
|
return $view;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/**
|
120 |
|
|
* Tests the none-pager-query.
|
121 |
|
|
*/
|
122 |
|
|
public function testNoLimit() {
|
123 |
|
|
// Create 11 nodes and make sure that everyone is returned.
|
124 |
|
|
// We create 11 nodes, because the default pager plugin had 10 items per page.
|
125 |
|
|
for ($i = 0; $i < 11; $i++) {
|
126 |
|
|
$this->drupalCreateNode();
|
127 |
|
|
}
|
128 |
|
|
$view = $this->viewsPagerNoLimit();
|
129 |
|
|
$view->set_display('default');
|
130 |
|
|
$this->executeView($view);
|
131 |
|
|
$this->assertEqual(count($view->result), 11, 'Make sure that every item is returned in the result');
|
132 |
|
|
|
133 |
|
|
$view->destroy();
|
134 |
|
|
|
135 |
|
|
// Setup and test a offset.
|
136 |
|
|
$view = $this->viewsPagerNoLimit();
|
137 |
|
|
$view->set_display('default');
|
138 |
|
|
|
139 |
|
|
$pager = array(
|
140 |
|
|
'type' => 'none',
|
141 |
|
|
'options' => array(
|
142 |
|
|
'offset' => 3,
|
143 |
|
|
),
|
144 |
|
|
);
|
145 |
|
|
$view->display_handler->set_option('pager', $pager);
|
146 |
|
|
$this->executeView($view);
|
147 |
|
|
|
148 |
|
|
$this->assertEqual(count($view->result), 8, 'Make sure that every item beside the first three is returned in the result');
|
149 |
|
|
|
150 |
|
|
// Check some public functions.
|
151 |
|
|
$this->assertFalse($view->query->pager->use_pager());
|
152 |
|
|
$this->assertFalse($view->query->pager->use_count_query());
|
153 |
|
|
$this->assertEqual($view->query->pager->get_items_per_page(), 0);
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
public function viewsPagerNoLimit() {
|
157 |
|
|
$view = new view;
|
158 |
|
|
$view->name = 'test_pager_none';
|
159 |
|
|
$view->description = '';
|
160 |
|
|
$view->tag = '';
|
161 |
|
|
$view->view_php = '';
|
162 |
|
|
$view->base_table = 'node';
|
163 |
|
|
$view->is_cacheable = FALSE;
|
164 |
|
|
$view->api_version =3;
|
165 |
|
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
166 |
|
|
|
167 |
|
|
/* Display: Master */
|
168 |
|
|
$handler = $view->new_display('default', 'Master', 'default');
|
169 |
|
|
$handler->display->display_options['access']['type'] = 'none';
|
170 |
|
|
$handler->display->display_options['cache']['type'] = 'none';
|
171 |
|
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
172 |
|
|
$handler->display->display_options['pager']['type'] = 'none';
|
173 |
|
|
$handler->display->display_options['style_plugin'] = 'default';
|
174 |
|
|
$handler->display->display_options['row_plugin'] = 'node';
|
175 |
|
|
return $view;
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
public function testViewTotalRowsWithoutPager() {
|
179 |
|
|
$this->createNodes(23);
|
180 |
|
|
|
181 |
|
|
$view = $this->viewsPagerNoLimit();
|
182 |
|
|
$view->get_total_rows = TRUE;
|
183 |
|
|
$view->set_display('default');
|
184 |
|
|
$this->executeView($view);
|
185 |
|
|
|
186 |
|
|
$this->assertEqual($view->total_rows, 23, "'total_rows' is calculated when pager type is 'none' and 'get_total_rows' is TRUE.");
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
public function createNodes($count) {
|
190 |
|
|
if ($count >= 0) {
|
191 |
|
|
for ($i = 0; $i < $count; $i++) {
|
192 |
|
|
$this->drupalCreateNode();
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
/**
|
198 |
|
|
* Tests the some pager plugin.
|
199 |
|
|
*/
|
200 |
|
|
public function testLimit() {
|
201 |
|
|
// Create 11 nodes and make sure that everyone is returned.
|
202 |
|
|
// We create 11 nodes, because the default pager plugin had 10 items per page.
|
203 |
|
|
for ($i = 0; $i < 11; $i++) {
|
204 |
|
|
$this->drupalCreateNode();
|
205 |
|
|
}
|
206 |
|
|
$view = $this->viewsPagerLimit();
|
207 |
|
|
$view->set_display('default');
|
208 |
|
|
$this->executeView($view);
|
209 |
|
|
$this->assertEqual(count($view->result), 5, 'Make sure that only a certain count of items is returned');
|
210 |
|
|
$view->destroy();
|
211 |
|
|
|
212 |
|
|
// Setup and test a offset.
|
213 |
|
|
$view = $this->viewsPagerLimit();
|
214 |
|
|
$view->set_display('default');
|
215 |
|
|
|
216 |
|
|
$pager = array(
|
217 |
|
|
'type' => 'none',
|
218 |
|
|
'options' => array(
|
219 |
|
|
'offset' => 8,
|
220 |
|
|
'items_per_page' => 5,
|
221 |
|
|
),
|
222 |
|
|
);
|
223 |
|
|
$view->display_handler->set_option('pager', $pager);
|
224 |
|
|
$this->executeView($view);
|
225 |
|
|
$this->assertEqual(count($view->result), 3, 'Make sure that only a certain count of items is returned');
|
226 |
|
|
|
227 |
|
|
// Check some public functions.
|
228 |
|
|
$this->assertFalse($view->query->pager->use_pager());
|
229 |
|
|
$this->assertFalse($view->query->pager->use_count_query());
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
public function viewsPagerLimit() {
|
233 |
|
|
$view = new view;
|
234 |
|
|
$view->name = 'test_pager_some';
|
235 |
|
|
$view->description = '';
|
236 |
|
|
$view->tag = '';
|
237 |
|
|
$view->view_php = '';
|
238 |
|
|
$view->base_table = 'node';
|
239 |
|
|
$view->is_cacheable = FALSE;
|
240 |
|
|
$view->api_version = 3;
|
241 |
|
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
242 |
|
|
|
243 |
|
|
/* Display: Master */
|
244 |
|
|
$handler = $view->new_display('default', 'Master', 'default');
|
245 |
|
|
$handler->display->display_options['access']['type'] = 'none';
|
246 |
|
|
$handler->display->display_options['cache']['type'] = 'none';
|
247 |
|
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
248 |
|
|
$handler->display->display_options['pager']['type'] = 'some';
|
249 |
|
|
$handler->display->display_options['pager']['options']['offset'] = 0;
|
250 |
|
|
$handler->display->display_options['pager']['options']['items_per_page'] = 5;
|
251 |
|
|
$handler->display->display_options['style_plugin'] = 'default';
|
252 |
|
|
$handler->display->display_options['row_plugin'] = 'node';
|
253 |
|
|
return $view;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
/**
|
257 |
|
|
* Tests the normal pager.
|
258 |
|
|
*/
|
259 |
|
|
public function testNormalPager() {
|
260 |
|
|
// Create 11 nodes and make sure that everyone is returned.
|
261 |
|
|
// We create 11 nodes, because the default pager plugin had 10 items per page.
|
262 |
|
|
for ($i = 0; $i < 11; $i++) {
|
263 |
|
|
$this->drupalCreateNode();
|
264 |
|
|
}
|
265 |
|
|
$view = $this->viewsPagerFull();
|
266 |
|
|
$view->set_display('default');
|
267 |
|
|
$this->executeView($view);
|
268 |
|
|
$this->assertEqual(count($view->result), 5, 'Make sure that only a certain count of items is returned');
|
269 |
|
|
$view->destroy();
|
270 |
|
|
|
271 |
|
|
// Setup and test a offset.
|
272 |
|
|
$view = $this->viewsPagerFull();
|
273 |
|
|
$view->set_display('default');
|
274 |
|
|
|
275 |
|
|
$pager = array(
|
276 |
|
|
'type' => 'full',
|
277 |
|
|
'options' => array(
|
278 |
|
|
'offset' => 8,
|
279 |
|
|
'items_per_page' => 5,
|
280 |
|
|
),
|
281 |
|
|
);
|
282 |
|
|
$view->display_handler->set_option('pager', $pager);
|
283 |
|
|
$this->executeView($view);
|
284 |
|
|
$this->assertEqual(count($view->result), 3, 'Make sure that only a certain count of items is returned');
|
285 |
|
|
|
286 |
|
|
// Test items per page = 0
|
287 |
|
|
$view = $this->viewPagerFullZeroItemsPerPage();
|
288 |
|
|
$view->set_display('default');
|
289 |
|
|
$this->executeView($view);
|
290 |
|
|
|
291 |
|
|
$this->assertEqual(count($view->result), 11, 'All items are return');
|
292 |
|
|
|
293 |
|
|
// TODO test number of pages.
|
294 |
|
|
|
295 |
|
|
// Test items per page = 0.
|
296 |
|
|
$view->destroy();
|
297 |
|
|
|
298 |
|
|
// Setup and test a offset.
|
299 |
|
|
$view = $this->viewsPagerFull();
|
300 |
|
|
$view->set_display('default');
|
301 |
|
|
|
302 |
|
|
$pager = array(
|
303 |
|
|
'type' => 'full',
|
304 |
|
|
'options' => array(
|
305 |
|
|
'offset' => 0,
|
306 |
|
|
'items_per_page' => 0,
|
307 |
|
|
),
|
308 |
|
|
);
|
309 |
|
|
|
310 |
|
|
$view->display_handler->set_option('pager', $pager);
|
311 |
|
|
$this->executeView($view);
|
312 |
|
|
$this->assertEqual($view->query->pager->get_items_per_page(), 0);
|
313 |
|
|
$this->assertEqual(count($view->result), 11);
|
314 |
|
|
}
|
315 |
|
|
|
316 |
|
|
function viewPagerFullZeroItemsPerPage() {
|
317 |
|
|
$view = new view;
|
318 |
|
|
$view->name = 'view_pager_full_zero_items_per_page';
|
319 |
|
|
$view->description = '';
|
320 |
|
|
$view->tag = '';
|
321 |
|
|
$view->view_php = '';
|
322 |
|
|
$view->base_table = 'node';
|
323 |
|
|
$view->is_cacheable = FALSE;
|
324 |
|
|
$view->api_version = 3;
|
325 |
|
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
326 |
|
|
|
327 |
|
|
/* Display: Master */
|
328 |
|
|
$handler = $view->new_display('default', 'Master', 'default');
|
329 |
|
|
$handler->display->display_options['access']['type'] = 'none';
|
330 |
|
|
$handler->display->display_options['cache']['type'] = 'none';
|
331 |
|
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
332 |
|
|
$handler->display->display_options['pager']['type'] = 'full';
|
333 |
|
|
$handler->display->display_options['pager']['options']['items_per_page'] = '0';
|
334 |
|
|
$handler->display->display_options['pager']['options']['offset'] = '0';
|
335 |
|
|
$handler->display->display_options['pager']['options']['id'] = '0';
|
336 |
|
|
$handler->display->display_options['style_plugin'] = 'default';
|
337 |
|
|
$handler->display->display_options['row_plugin'] = 'fields';
|
338 |
|
|
/* Field: Content: Title */
|
339 |
|
|
$handler->display->display_options['fields']['title']['id'] = 'title';
|
340 |
|
|
$handler->display->display_options['fields']['title']['table'] = 'node';
|
341 |
|
|
$handler->display->display_options['fields']['title']['field'] = 'title';
|
342 |
|
|
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
|
343 |
|
|
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
344 |
|
|
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
345 |
|
|
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
346 |
|
|
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
347 |
|
|
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
348 |
|
|
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
349 |
|
|
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
350 |
|
|
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
351 |
|
|
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
|
352 |
|
|
|
353 |
|
|
return $view;
|
354 |
|
|
}
|
355 |
|
|
|
356 |
|
|
function viewsPagerFull() {
|
357 |
|
|
$view = new view;
|
358 |
|
|
$view->name = 'test_pager_full';
|
359 |
|
|
$view->description = '';
|
360 |
|
|
$view->tag = '';
|
361 |
|
|
$view->view_php = '';
|
362 |
|
|
$view->base_table = 'node';
|
363 |
|
|
$view->is_cacheable = FALSE;
|
364 |
|
|
$view->api_version = 3;
|
365 |
|
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
366 |
|
|
|
367 |
|
|
/* Display: Master */
|
368 |
|
|
$handler = $view->new_display('default', 'Master', 'default');
|
369 |
|
|
$handler->display->display_options['access']['type'] = 'none';
|
370 |
|
|
$handler->display->display_options['cache']['type'] = 'none';
|
371 |
|
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
372 |
|
|
$handler->display->display_options['pager']['type'] = 'full';
|
373 |
|
|
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
|
374 |
|
|
$handler->display->display_options['pager']['options']['offset'] = '0';
|
375 |
|
|
$handler->display->display_options['pager']['options']['id'] = '0';
|
376 |
|
|
$handler->display->display_options['style_plugin'] = 'default';
|
377 |
|
|
$handler->display->display_options['row_plugin'] = 'node';
|
378 |
|
|
|
379 |
|
|
return $view;
|
380 |
|
|
}
|
381 |
|
|
|
382 |
|
|
function viewsPagerFullFields() {
|
383 |
|
|
$view = new view;
|
384 |
|
|
$view->name = 'test_pager_full';
|
385 |
|
|
$view->description = '';
|
386 |
|
|
$view->tag = '';
|
387 |
|
|
$view->view_php = '';
|
388 |
|
|
$view->base_table = 'node';
|
389 |
|
|
$view->is_cacheable = FALSE;
|
390 |
|
|
$view->api_version = 3;
|
391 |
|
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
392 |
|
|
|
393 |
|
|
/* Display: Master */
|
394 |
|
|
$handler = $view->new_display('default', 'Master', 'default');
|
395 |
|
|
$handler->display->display_options['access']['type'] = 'none';
|
396 |
|
|
$handler->display->display_options['cache']['type'] = 'none';
|
397 |
|
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
398 |
|
|
$handler->display->display_options['pager']['type'] = 'full';
|
399 |
|
|
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
|
400 |
|
|
$handler->display->display_options['pager']['options']['offset'] = '0';
|
401 |
|
|
$handler->display->display_options['pager']['options']['id'] = '0';
|
402 |
|
|
$handler->display->display_options['style_plugin'] = 'default';
|
403 |
|
|
$handler->display->display_options['row_plugin'] = 'fields';
|
404 |
|
|
$handler->display->display_options['fields']['title']['id'] = 'title';
|
405 |
|
|
$handler->display->display_options['fields']['title']['table'] = 'node';
|
406 |
|
|
$handler->display->display_options['fields']['title']['field'] = 'title';
|
407 |
|
|
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
|
408 |
|
|
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
409 |
|
|
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
410 |
|
|
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
411 |
|
|
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
412 |
|
|
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
413 |
|
|
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
414 |
|
|
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
415 |
|
|
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
416 |
|
|
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
|
417 |
|
|
return $view;
|
418 |
|
|
}
|
419 |
|
|
|
420 |
|
|
/**
|
421 |
|
|
* Tests the minipager.
|
422 |
|
|
*/
|
423 |
|
|
public function testMiniPager() {
|
424 |
|
|
// the functionality is the same as the normal pager, so i don't know what to test here.
|
425 |
|
|
}
|
426 |
|
|
|
427 |
|
|
/**
|
428 |
|
|
* Tests rendering with NULL pager.
|
429 |
|
|
*/
|
430 |
|
|
public function testRenderNullPager() {
|
431 |
|
|
// Create 11 nodes and make sure that everyone is returned.
|
432 |
|
|
// We create 11 nodes, because the default pager plugin had 10 items per page.
|
433 |
|
|
for ($i = 0; $i < 11; $i++) {
|
434 |
|
|
$this->drupalCreateNode();
|
435 |
|
|
}
|
436 |
|
|
$view = $this->viewsPagerFullFields();
|
437 |
|
|
$view->set_display('default');
|
438 |
|
|
$this->executeView($view);
|
439 |
|
|
$view->use_ajax = TRUE; // force the value again here
|
440 |
|
|
$view->query->pager = NULL;
|
441 |
|
|
$output = $view->render();
|
442 |
|
|
$this->assertEqual(preg_match('/<ul class="pager">/', $output), 0, t('The pager is not rendered.'));
|
443 |
|
|
}
|
444 |
|
|
|
445 |
|
|
/**
|
446 |
|
|
* Test the api functions on the view object.
|
447 |
|
|
*/
|
448 |
|
|
function testPagerApi() {
|
449 |
|
|
$view = $this->viewsPagerFull();
|
450 |
|
|
// On the first round don't initialize the pager.
|
451 |
|
|
|
452 |
|
|
$this->assertEqual($view->get_items_per_page(), NULL, 'If the pager is not initialized and no manual override there is no items per page.');
|
453 |
|
|
$rand_number = rand(1, 5);
|
454 |
|
|
$view->set_items_per_page($rand_number);
|
455 |
|
|
$this->assertEqual($view->get_items_per_page(), $rand_number, 'Make sure get_items_per_page uses the settings of set_items_per_page.');
|
456 |
|
|
|
457 |
|
|
$this->assertEqual($view->get_offset(), NULL, 'If the pager is not initialized and no manual override there is no offset.');
|
458 |
|
|
$rand_number = rand(1, 5);
|
459 |
|
|
$view->set_offset($rand_number);
|
460 |
|
|
$this->assertEqual($view->get_offset(), $rand_number, 'Make sure get_offset uses the settings of set_offset.');
|
461 |
|
|
|
462 |
|
|
$this->assertEqual($view->get_current_page(), NULL, 'If the pager is not initialized and no manual override there is no current page.');
|
463 |
|
|
$rand_number = rand(1, 5);
|
464 |
|
|
$view->set_current_page($rand_number);
|
465 |
|
|
$this->assertEqual($view->get_current_page(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.');
|
466 |
|
|
|
467 |
|
|
$view->destroy();
|
468 |
|
|
|
469 |
|
|
// On this round enable the pager.
|
470 |
|
|
$view->init_display();
|
471 |
|
|
$view->init_query();
|
472 |
|
|
$view->init_pager();
|
473 |
|
|
|
474 |
|
|
$this->assertEqual($view->get_items_per_page(), 5, 'Per default the view has 5 items per page.');
|
475 |
|
|
$rand_number = rand(1, 5);
|
476 |
|
|
$view->set_items_per_page($rand_number);
|
477 |
|
|
$rand_number = rand(6, 11);
|
478 |
|
|
$view->query->pager->set_items_per_page($rand_number);
|
479 |
|
|
$this->assertEqual($view->get_items_per_page(), $rand_number, 'Make sure get_items_per_page uses the settings of set_items_per_page.');
|
480 |
|
|
|
481 |
|
|
$this->assertEqual($view->get_offset(), 0, 'Per default a view has a 0 offset.');
|
482 |
|
|
$rand_number = rand(1, 5);
|
483 |
|
|
$view->set_offset($rand_number);
|
484 |
|
|
$rand_number = rand(6, 11);
|
485 |
|
|
$view->query->pager->set_offset($rand_number);
|
486 |
|
|
$this->assertEqual($view->get_offset(), $rand_number, 'Make sure get_offset uses the settings of set_offset.');
|
487 |
|
|
|
488 |
|
|
$this->assertEqual($view->get_current_page(), 0, 'Per default the current page is 0.');
|
489 |
|
|
$rand_number = rand(1, 5);
|
490 |
|
|
$view->set_current_page($rand_number);
|
491 |
|
|
$rand_number = rand(6, 11);
|
492 |
|
|
$view->query->pager->set_current_page($rand_number);
|
493 |
|
|
$this->assertEqual($view->get_current_page(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.');
|
494 |
|
|
|
495 |
|
|
}
|
496 |
|
|
} |