Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/tests/views_pager.test | ||
---|---|---|
9 | 9 |
* Tests the pluggable pager system. |
10 | 10 |
*/ |
11 | 11 |
class ViewsPagerTest extends ViewsSqlTest { |
12 |
|
|
13 |
/** |
|
14 |
* |
|
15 |
*/ |
|
12 | 16 |
public static function getInfo() { |
13 | 17 |
return array( |
14 | 18 |
'name' => 'Pager', |
... | ... | |
17 | 21 |
); |
18 | 22 |
} |
19 | 23 |
|
24 |
/** |
|
25 |
* |
|
26 |
*/ |
|
20 | 27 |
public function setUp() { |
21 | 28 |
parent::setUp('views', 'views_ui', 'views_test'); |
22 | 29 |
} |
... | ... | |
29 | 36 |
public function testStorePagerSettings() { |
30 | 37 |
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); |
31 | 38 |
$this->drupalLogin($admin_user); |
32 |
// Test behaviour described in http://drupal.org/node/652712#comment-2354918.
|
|
33 |
|
|
39 |
// Test behaviour described in |
|
40 |
// http://drupal.org/node/652712#comment-2354918. |
|
34 | 41 |
$this->drupalGet('admin/structure/views/view/frontpage/edit'); |
35 | 42 |
|
36 |
|
|
37 | 43 |
$edit = array( |
38 | 44 |
'pager_options[items_per_page]' => 20, |
39 | 45 |
); |
... | ... | |
70 | 76 |
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options', $edit, t('Apply')); |
71 | 77 |
$this->assertText('20 items'); |
72 | 78 |
|
73 |
// add new display and test the settings again, by override it.
|
|
74 |
$edit = array( );
|
|
79 |
// Add new display and test the settings again, by override it.
|
|
80 |
$edit = array(); |
|
75 | 81 |
// Add a display and override the pager settings. |
76 | 82 |
$this->drupalPost('admin/structure/views/view/test_store_pager_settings/edit', $edit, t('Add Page')); |
77 | 83 |
$edit = array( |
... | ... | |
91 | 97 |
); |
92 | 98 |
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options', $edit, t('Apply')); |
93 | 99 |
$this->assertText('20 items'); |
94 |
|
|
95 | 100 |
} |
96 | 101 |
|
102 |
/** |
|
103 |
* |
|
104 |
*/ |
|
97 | 105 |
public function viewsStorePagerSettings() { |
98 |
$view = new view; |
|
106 |
$view = new view();
|
|
99 | 107 |
$view->name = 'test_store_pager_settings'; |
100 | 108 |
$view->description = ''; |
101 | 109 |
$view->tag = ''; |
... | ... | |
120 | 128 |
* Tests the none-pager-query. |
121 | 129 |
*/ |
122 | 130 |
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.
|
|
131 |
// Create 11 nodes and make sure that everyone is returned. We create 11
|
|
132 |
// nodes, because the default pager plugin had 10 items per page. |
|
125 | 133 |
for ($i = 0; $i < 11; $i++) { |
126 | 134 |
$this->drupalCreateNode(); |
127 | 135 |
} |
... | ... | |
153 | 161 |
$this->assertEqual($view->query->pager->get_items_per_page(), 0); |
154 | 162 |
} |
155 | 163 |
|
164 |
/** |
|
165 |
* |
|
166 |
*/ |
|
156 | 167 |
public function viewsPagerNoLimit() { |
157 |
$view = new view; |
|
168 |
$view = new view();
|
|
158 | 169 |
$view->name = 'test_pager_none'; |
159 | 170 |
$view->description = ''; |
160 | 171 |
$view->tag = ''; |
161 | 172 |
$view->view_php = ''; |
162 | 173 |
$view->base_table = 'node'; |
163 | 174 |
$view->is_cacheable = FALSE; |
164 |
$view->api_version =3; |
|
175 |
$view->api_version = 3;
|
|
165 | 176 |
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ |
166 | 177 |
|
167 | 178 |
/* Display: Master */ |
... | ... | |
175 | 186 |
return $view; |
176 | 187 |
} |
177 | 188 |
|
189 |
/** |
|
190 |
* |
|
191 |
*/ |
|
178 | 192 |
public function testViewTotalRowsWithoutPager() { |
179 | 193 |
$this->createNodes(23); |
180 | 194 |
|
... | ... | |
186 | 200 |
$this->assertEqual($view->total_rows, 23, "'total_rows' is calculated when pager type is 'none' and 'get_total_rows' is TRUE."); |
187 | 201 |
} |
188 | 202 |
|
203 |
/** |
|
204 |
* |
|
205 |
*/ |
|
189 | 206 |
public function createNodes($count) { |
190 | 207 |
if ($count >= 0) { |
191 | 208 |
for ($i = 0; $i < $count; $i++) { |
... | ... | |
198 | 215 |
* Tests the some pager plugin. |
199 | 216 |
*/ |
200 | 217 |
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.
|
|
218 |
// Create 11 nodes and make sure that everyone is returned. We create 11
|
|
219 |
// nodes, because the default pager plugin had 10 items per page. |
|
203 | 220 |
for ($i = 0; $i < 11; $i++) { |
204 | 221 |
$this->drupalCreateNode(); |
205 | 222 |
} |
... | ... | |
229 | 246 |
$this->assertFalse($view->query->pager->use_count_query()); |
230 | 247 |
} |
231 | 248 |
|
249 |
/** |
|
250 |
* |
|
251 |
*/ |
|
232 | 252 |
public function viewsPagerLimit() { |
233 |
$view = new view; |
|
253 |
$view = new view();
|
|
234 | 254 |
$view->name = 'test_pager_some'; |
235 | 255 |
$view->description = ''; |
236 | 256 |
$view->tag = ''; |
... | ... | |
257 | 277 |
* Tests the normal pager. |
258 | 278 |
*/ |
259 | 279 |
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.
|
|
280 |
// Create 11 nodes and make sure that everyone is returned. We create 11
|
|
281 |
// nodes, because the default pager plugin had 10 items per page. |
|
262 | 282 |
for ($i = 0; $i < 11; $i++) { |
263 | 283 |
$this->drupalCreateNode(); |
264 | 284 |
} |
... | ... | |
290 | 310 |
|
291 | 311 |
$this->assertEqual(count($view->result), 11, 'All items are return'); |
292 | 312 |
|
293 |
// TODO test number of pages. |
|
294 |
|
|
313 |
// @todo test number of pages. |
|
295 | 314 |
// Test items per page = 0. |
296 | 315 |
$view->destroy(); |
297 | 316 |
|
... | ... | |
313 | 332 |
$this->assertEqual(count($view->result), 11); |
314 | 333 |
} |
315 | 334 |
|
335 |
/** |
|
336 |
* |
|
337 |
*/ |
|
316 | 338 |
function viewPagerFullZeroItemsPerPage() { |
317 |
$view = new view; |
|
339 |
$view = new view();
|
|
318 | 340 |
$view->name = 'view_pager_full_zero_items_per_page'; |
319 | 341 |
$view->description = ''; |
320 | 342 |
$view->tag = ''; |
... | ... | |
353 | 375 |
return $view; |
354 | 376 |
} |
355 | 377 |
|
378 |
/** |
|
379 |
* |
|
380 |
*/ |
|
356 | 381 |
function viewsPagerFull() { |
357 |
$view = new view; |
|
382 |
$view = new view();
|
|
358 | 383 |
$view->name = 'test_pager_full'; |
359 | 384 |
$view->description = ''; |
360 | 385 |
$view->tag = ''; |
... | ... | |
379 | 404 |
return $view; |
380 | 405 |
} |
381 | 406 |
|
407 |
/** |
|
408 |
* |
|
409 |
*/ |
|
382 | 410 |
function viewsPagerFullFields() { |
383 |
$view = new view; |
|
411 |
$view = new view();
|
|
384 | 412 |
$view->name = 'test_pager_full'; |
385 | 413 |
$view->description = ''; |
386 | 414 |
$view->tag = ''; |
... | ... | |
421 | 449 |
* Tests the minipager. |
422 | 450 |
*/ |
423 | 451 |
public function testMiniPager() { |
424 |
// the functionality is the same as the normal pager, so i don't know what to test here. |
|
452 |
// The functionality is the same as the normal pager, so i don't know what |
|
453 |
// to test here. |
|
425 | 454 |
} |
426 | 455 |
|
427 | 456 |
/** |
428 | 457 |
* Tests rendering with NULL pager. |
429 | 458 |
*/ |
430 | 459 |
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.
|
|
460 |
// Create 11 nodes and make sure that everyone is returned. We create 11
|
|
461 |
// nodes, because the default pager plugin had 10 items per page. |
|
433 | 462 |
for ($i = 0; $i < 11; $i++) { |
434 | 463 |
$this->drupalCreateNode(); |
435 | 464 |
} |
436 | 465 |
$view = $this->viewsPagerFullFields(); |
437 | 466 |
$view->set_display('default'); |
438 | 467 |
$this->executeView($view); |
439 |
$view->use_ajax = TRUE; // force the value again here |
|
468 |
$view->use_ajax = TRUE; |
|
469 |
// force the value again here. |
|
440 | 470 |
$view->query->pager = NULL; |
441 | 471 |
$output = $view->render(); |
442 | 472 |
$this->assertEqual(preg_match('/<ul class="pager">/', $output), 0, t('The pager is not rendered.')); |
... | ... | |
448 | 478 |
function testPagerApi() { |
449 | 479 |
$view = $this->viewsPagerFull(); |
450 | 480 |
// On the first round don't initialize the pager. |
451 |
|
|
452 | 481 |
$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 | 482 |
$rand_number = rand(1, 5); |
454 | 483 |
$view->set_items_per_page($rand_number); |
... | ... | |
491 | 520 |
$rand_number = rand(6, 11); |
492 | 521 |
$view->query->pager->set_current_page($rand_number); |
493 | 522 |
$this->assertEqual($view->get_current_page(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.'); |
494 |
|
|
495 | 523 |
} |
524 |
|
|
496 | 525 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules