comparison cake/tests/cases/libs/view/helpers/paginator.test.php @ 0:261e66bd5a0c

hg init
author Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Jul 2011 21:08:31 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:261e66bd5a0c
1 <?php
2 /**
3 * PaginatorHelperTest file
4 *
5 * PHP versions 4 and 5
6 *
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
9 *
10 * Licensed under The Open Group Test Suite License
11 * Redistributions of files must retain the above copyright notice.
12 *
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
15 * @package cake
16 * @subpackage cake.tests.cases.libs.view.helpers
17 * @since CakePHP(tm) v 1.2.0.4206
18 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
19 */
20 App::import('Helper', array('Html', 'Paginator', 'Form', 'Ajax', 'Javascript', 'Js'));
21
22 Mock::generate('JsHelper', 'PaginatorMockJsHelper');
23
24 if (!defined('FULL_BASE_URL')) {
25 define('FULL_BASE_URL', 'http://cakephp.org');
26 }
27
28 /**
29 * PaginatorHelperTest class
30 *
31 * @package cake
32 * @subpackage cake.tests.cases.libs.view.helpers
33 */
34 class PaginatorHelperTest extends CakeTestCase {
35
36 /**
37 * setUp method
38 *
39 * @access public
40 * @return void
41 */
42 function setUp() {
43 $this->Paginator = new PaginatorHelper(array('ajax' => 'Ajax'));
44 $this->Paginator->params['paging'] = array(
45 'Article' => array(
46 'current' => 9,
47 'count' => 62,
48 'prevPage' => false,
49 'nextPage' => true,
50 'pageCount' => 7,
51 'defaults' => array(
52 'order' => array('Article.date' => 'asc'),
53 'limit' => 9,
54 'conditions' => array()
55 ),
56 'options' => array(
57 'order' => array('Article.date' => 'asc'),
58 'limit' => 9,
59 'page' => 1,
60 'conditions' => array()
61 )
62 )
63 );
64 $this->Paginator->Html =& new HtmlHelper();
65 $this->Paginator->Ajax =& new AjaxHelper();
66 $this->Paginator->Ajax->Html =& new HtmlHelper();
67 $this->Paginator->Ajax->Javascript =& new JavascriptHelper();
68 $this->Paginator->Ajax->Form =& new FormHelper();
69
70 Configure::write('Routing.prefixes', array());
71 Router::reload();
72 }
73
74 /**
75 * tearDown method
76 *
77 * @access public
78 * @return void
79 */
80 function tearDown() {
81 unset($this->Paginator);
82 }
83
84 /**
85 * testHasPrevious method
86 *
87 * @access public
88 * @return void
89 */
90 function testHasPrevious() {
91 $this->assertIdentical($this->Paginator->hasPrev(), false);
92 $this->Paginator->params['paging']['Article']['prevPage'] = true;
93 $this->assertIdentical($this->Paginator->hasPrev(), true);
94 $this->Paginator->params['paging']['Article']['prevPage'] = false;
95 }
96
97 /**
98 * testHasNext method
99 *
100 * @access public
101 * @return void
102 */
103 function testHasNext() {
104 $this->assertIdentical($this->Paginator->hasNext(), true);
105 $this->Paginator->params['paging']['Article']['nextPage'] = false;
106 $this->assertIdentical($this->Paginator->hasNext(), false);
107 $this->Paginator->params['paging']['Article']['nextPage'] = true;
108 }
109
110 /**
111 * testDisabledLink method
112 *
113 * @access public
114 * @return void
115 */
116 function testDisabledLink() {
117 $this->Paginator->params['paging']['Article']['nextPage'] = false;
118 $this->Paginator->params['paging']['Article']['page'] = 1;
119 $result = $this->Paginator->next('Next', array(), true);
120 $expected = '<span class="next">Next</span>';
121 $this->assertEqual($result, $expected);
122
123 $this->Paginator->params['paging']['Article']['prevPage'] = false;
124 $result = $this->Paginator->prev('prev', array('update' => 'theList', 'indicator' => 'loading', 'url' => array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span'));
125 $expected = array(
126 'span' => array('class' => 'disabled'), 'prev', '/span'
127 );
128 $this->assertTags($result, $expected);
129 }
130
131 /**
132 * testSortLinks method
133 *
134 * @access public
135 * @return void
136 */
137 function testSortLinks() {
138 Router::reload();
139 Router::parse('/');
140 Router::setRequestInfo(array(
141 array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/'), 'bare' => 0),
142 array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
143 ));
144 $this->Paginator->options(array('url' => array('param')));
145 $result = $this->Paginator->sort('title');
146 $expected = array(
147 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
148 'Title',
149 '/a'
150 );
151 $this->assertTags($result, $expected);
152
153 $result = $this->Paginator->sort('date');
154 $expected = array(
155 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc', 'class' => 'asc'),
156 'Date',
157 '/a'
158 );
159 $this->assertTags($result, $expected);
160
161 $result = $this->Paginator->numbers(array('modulus'=> '2', 'url'=> array('controller'=>'projects', 'action'=>'sort'),'update'=>'list'));
162 $this->assertPattern('/\/projects\/sort\/page:2/', $result);
163 $this->assertPattern('/<script type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*Event.observe/', $result);
164
165 $result = $this->Paginator->sort('TestTitle', 'title');
166 $expected = array(
167 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
168 'TestTitle',
169 '/a'
170 );
171 $this->assertTags($result, $expected);
172
173 $result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
174 $expected = array(
175 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
176 'ascending',
177 '/a'
178 );
179 $this->assertTags($result, $expected);
180
181 $this->Paginator->params['paging']['Article']['options']['sort'] = 'title';
182 $result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
183 $expected = array(
184 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc', 'class' => 'asc'),
185 'descending',
186 '/a'
187 );
188 $this->assertTags($result, $expected);
189
190 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
191 $this->Paginator->params['paging']['Article']['options']['sort'] = null;
192 $result = $this->Paginator->sort('title');
193 $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
194
195 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
196 $this->Paginator->params['paging']['Article']['options']['sort'] = null;
197 $result = $this->Paginator->sort('title');
198 $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
199
200 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
201 $this->Paginator->params['paging']['Article']['options']['sort'] = null;
202 $result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc'));
203 $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
204
205 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
206 $this->Paginator->params['paging']['Article']['options']['sort'] = null;
207 $result = $this->Paginator->sort('Title', 'title', array('direction' => 'asc'));
208 $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
209
210 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
211 $this->Paginator->params['paging']['Article']['options']['sort'] = null;
212 $result = $this->Paginator->sort('Title', 'title', array('direction' => 'asc'));
213 $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
214
215 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
216 $this->Paginator->params['paging']['Article']['options']['sort'] = null;
217 $result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc'));
218 $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
219
220 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
221 $this->Paginator->params['paging']['Article']['options']['sort'] = null;
222 $result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc', 'class' => 'foo'));
223 $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="foo asc">Title<\/a>$/', $result);
224 }
225
226 /**
227 * test that sort() works with virtual field order options.
228 *
229 * @return void
230 */
231 function testSortLinkWithVirtualField() {
232 Router::setRequestInfo(array(
233 array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')),
234 array('base' => '', 'here' => '/accounts/', 'webroot' => '/')
235 ));
236 $this->Paginator->params['paging']['Article']['options']['order'] = array('full_name' => 'asc');
237
238 $result = $this->Paginator->sort('Article.full_name');
239 $expected = array(
240 'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:desc', 'class' => 'asc'),
241 'Article.full Name',
242 '/a'
243 );
244 $this->assertTags($result, $expected);
245
246 $result = $this->Paginator->sort('full_name');
247 $expected = array(
248 'a' => array('href' => '/accounts/index/page:1/sort:full_name/direction:desc', 'class' => 'asc'),
249 'Full Name',
250 '/a'
251 );
252 $this->assertTags($result, $expected);
253
254 $this->Paginator->params['paging']['Article']['options']['order'] = array('full_name' => 'desc');
255 $result = $this->Paginator->sort('Article.full_name');
256 $expected = array(
257 'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:asc', 'class' => 'desc'),
258 'Article.full Name',
259 '/a'
260 );
261 $this->assertTags($result, $expected);
262
263 $result = $this->Paginator->sort('full_name');
264 $expected = array(
265 'a' => array('href' => '/accounts/index/page:1/sort:full_name/direction:asc', 'class' => 'desc'),
266 'Full Name',
267 '/a'
268 );
269 $this->assertTags($result, $expected);
270 }
271
272 /**
273 * testSortLinksUsingDirectionOption method
274 *
275 * @access public
276 * @return void
277 */
278 function testSortLinksUsingDirectionOption(){
279 Router::reload();
280 Router::parse('/');
281 Router::setRequestInfo(array(
282 array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(),
283 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
284 array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/', 'here' => '/accounts/',
285 'webroot' => '/', 'passedArgs' => array())
286 ));
287 $this->Paginator->options(array('url' => array('param')));
288
289 $result = $this->Paginator->sort('TestTitle', 'title', array('direction' => 'desc'));
290 $expected = array(
291 'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'),
292 'TestTitle',
293 '/a'
294 );
295 $this->assertTags($result, $expected);
296
297 $result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title', array('direction' => 'desc'));
298 $expected = array(
299 'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'),
300 'descending',
301 '/a'
302 );
303 $this->assertTags($result, $expected);
304 }
305
306 /**
307 * testSortLinksUsingDotNotation method
308 *
309 * @access public
310 * @return void
311 */
312 function testSortLinksUsingDotNotation() {
313 Router::reload();
314 Router::parse('/');
315 Router::setRequestInfo(array(
316 array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
317 array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
318 ));
319
320 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
321 $result = $this->Paginator->sort('Title','Article.title');
322 $expected = array(
323 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc', 'class' => 'desc'),
324 'Title',
325 '/a'
326 );
327 $this->assertTags($result, $expected);
328
329 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
330 $result = $this->Paginator->sort('Title','Article.title');
331 $expected = array(
332 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc', 'class' => 'asc'),
333 'Title',
334 '/a'
335 );
336 $this->assertTags($result, $expected);
337
338 $this->Paginator->params['paging']['Article']['options']['order'] = array('Account.title' => 'asc');
339 $result = $this->Paginator->sort('title');
340 $expected = array(
341 'a' => array('href' => '/officespace/accounts/index/page:1/sort:title/direction:asc'),
342 'Title',
343 '/a'
344 );
345 $this->assertTags($result, $expected);
346 }
347
348 /**
349 * testSortKey method
350 *
351 * @access public
352 * @return void
353 */
354 function testSortKey() {
355 $result = $this->Paginator->sortKey(null, array(
356 'order' => array('Article.title' => 'desc'
357 )));
358 $this->assertEqual('Article.title', $result);
359
360 $result = $this->Paginator->sortKey('Article', array('sort' => 'Article.title'));
361 $this->assertEqual($result, 'Article.title');
362
363 $result = $this->Paginator->sortKey('Article', array('sort' => 'Article'));
364 $this->assertEqual($result, 'Article');
365 }
366
367 /**
368 * testSortDir method
369 *
370 * @access public
371 * @return void
372 */
373 function testSortDir() {
374 $result = $this->Paginator->sortDir();
375 $expected = 'asc';
376
377 $this->assertEqual($result, $expected);
378
379 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
380 $result = $this->Paginator->sortDir();
381 $expected = 'desc';
382
383 $this->assertEqual($result, $expected);
384
385 unset($this->Paginator->params['paging']['Article']['options']);
386 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
387 $result = $this->Paginator->sortDir();
388 $expected = 'asc';
389
390 $this->assertEqual($result, $expected);
391
392 unset($this->Paginator->params['paging']['Article']['options']);
393 $this->Paginator->params['paging']['Article']['options']['order'] = array('title' => 'desc');
394 $result = $this->Paginator->sortDir();
395 $expected = 'desc';
396
397 $this->assertEqual($result, $expected);
398
399 unset($this->Paginator->params['paging']['Article']['options']);
400 $this->Paginator->params['paging']['Article']['options']['order'] = array('title' => 'asc');
401 $result = $this->Paginator->sortDir();
402 $expected = 'asc';
403
404 $this->assertEqual($result, $expected);
405
406 unset($this->Paginator->params['paging']['Article']['options']);
407 $this->Paginator->params['paging']['Article']['options']['direction'] = 'asc';
408 $result = $this->Paginator->sortDir();
409 $expected = 'asc';
410
411 $this->assertEqual($result, $expected);
412
413 unset($this->Paginator->params['paging']['Article']['options']);
414 $this->Paginator->params['paging']['Article']['options']['direction'] = 'desc';
415 $result = $this->Paginator->sortDir();
416 $expected = 'desc';
417
418 $this->assertEqual($result, $expected);
419
420 unset($this->Paginator->params['paging']['Article']['options']);
421 $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
422 $expected = 'asc';
423
424 $this->assertEqual($result, $expected);
425
426 $result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
427 $expected = 'desc';
428
429 $this->assertEqual($result, $expected);
430
431 $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
432 $expected = 'asc';
433
434 $this->assertEqual($result, $expected);
435 }
436
437 /**
438 * testSortAdminLinks method
439 *
440 * @access public
441 * @return void
442 */
443 function testSortAdminLinks() {
444 Configure::write('Routing.prefixes', array('admin'));
445
446 Router::reload();
447 Router::setRequestInfo(array(
448 array('pass' => array(), 'named' => array(), 'controller' => 'users', 'plugin' => null, 'action' => 'admin_index', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/users'), 'form' => array()),
449 array('base' => '', 'here' => '/admin/users', 'webroot' => '/')
450 ));
451 Router::parse('/admin/users');
452 $this->Paginator->params['paging']['Article']['page'] = 1;
453 $result = $this->Paginator->next('Next');
454 $expected = array(
455 '<span',
456 'a' => array('href' => '/admin/users/index/page:2', 'class' => 'next'),
457 'Next',
458 '/a',
459 '/span'
460 );
461 $this->assertTags($result, $expected);
462
463 Router::reload();
464 Router::setRequestInfo(array(
465 array('plugin' => null, 'controller' => 'test', 'action' => 'admin_index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/test')),
466 array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/admin/test', 'webroot' => '/')
467 ));
468 Router::parse('/');
469 $this->Paginator->options(array('url' => array('param')));
470 $result = $this->Paginator->sort('title');
471 $expected = array(
472 'a' => array('href' => '/admin/test/index/param/page:1/sort:title/direction:asc'),
473 'Title',
474 '/a'
475 );
476 $this->assertTags($result, $expected);
477
478 $this->Paginator->options(array('url' => array('param')));
479 $result = $this->Paginator->sort('Title', 'Article.title');
480 $expected = array(
481 'a' => array('href' => '/admin/test/index/param/page:1/sort:Article.title/direction:asc'),
482 'Title',
483 '/a'
484 );
485 $this->assertTags($result, $expected);
486 }
487
488 /**
489 * testUrlGeneration method
490 *
491 * @access public
492 * @return void
493 */
494 function testUrlGeneration() {
495 $result = $this->Paginator->sort('controller');
496 $expected = array(
497 'a' => array('href' => '/index/page:1/sort:controller/direction:asc'),
498 'Controller',
499 '/a'
500 );
501 $this->assertTags($result, $expected);
502
503 $result = $this->Paginator->url();
504 $this->assertEqual($result, '/index/page:1');
505
506 $this->Paginator->params['paging']['Article']['options']['page'] = 2;
507 $result = $this->Paginator->url();
508 $this->assertEqual($result, '/index/page:2');
509
510 $options = array('order' => array('Article' => 'desc'));
511 $result = $this->Paginator->url($options);
512 $this->assertEqual($result, '/index/page:2/sort:Article/direction:desc');
513
514 $this->Paginator->params['paging']['Article']['options']['page'] = 3;
515 $options = array('order' => array('Article.name' => 'desc'));
516 $result = $this->Paginator->url($options);
517 $this->assertEqual($result, '/index/page:3/sort:Article.name/direction:desc');
518 }
519
520 /**
521 * test URL generation with prefix routes
522 *
523 * @access public
524 * @return void
525 */
526 function testUrlGenerationWithPrefixes() {
527 $_back = Configure::read('Routing');
528
529 Configure::write('Routing.prefixes', array('members'));
530 Router::reload();
531
532 Router::parse('/');
533
534 Router::setRequestInfo( array(
535 array('controller' => 'posts', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null),
536 array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => 'posts/index', 'webroot' => '/')
537 ));
538
539 $this->Paginator->params['paging']['Article']['options']['page'] = 2;
540 $this->Paginator->params['paging']['Article']['page'] = 2;
541 $this->Paginator->params['paging']['Article']['prevPage'] = true;
542 $options = array('members' => true);
543
544 $result = $this->Paginator->url($options);
545 $expected = '/members/posts/index/page:2';
546 $this->assertEqual($result, $expected);
547
548 $result = $this->Paginator->sort('name', null, array('url' => $options));
549 $expected = array(
550 'a' => array('href' => '/members/posts/index/page:2/sort:name/direction:asc'),
551 'Name',
552 '/a'
553 );
554 $this->assertTags($result, $expected, true);
555
556 $result = $this->Paginator->next('next', array('url' => $options));
557 $expected = array(
558 '<span',
559 'a' => array('href' => '/members/posts/index/page:3', 'class' => 'next'),
560 'next',
561 '/a',
562 '/span'
563 );
564 $this->assertTags($result, $expected);
565
566 $result = $this->Paginator->prev('prev', array('url' => $options));
567 $expected = array(
568 '<span',
569 'a' => array('href' => '/members/posts/index/page:1', 'class' => 'prev'),
570 'prev',
571 '/a',
572 '/span'
573 );
574 $this->assertTags($result, $expected);
575
576 $options = array('members' => true, 'controller' => 'posts', 'order' => array('name' => 'desc'));
577 $result = $this->Paginator->url($options);
578 $expected = '/members/posts/index/page:2/sort:name/direction:desc';
579 $this->assertEqual($result, $expected);
580
581 $options = array('controller' => 'posts', 'order' => array('Article.name' => 'desc'));
582 $result = $this->Paginator->url($options);
583 $expected = '/posts/index/page:2/sort:Article.name/direction:desc';
584 $this->assertEqual($result, $expected);
585
586 Configure::write('Routing', $_back);
587 }
588
589 /**
590 * testOptions method
591 *
592 * @access public
593 * @return void
594 */
595 function testOptions() {
596 $this->Paginator->options('myDiv');
597 $this->assertEqual('myDiv', $this->Paginator->options['update']);
598
599 $this->Paginator->options = array();
600 $this->Paginator->params = array();
601
602 $options = array('paging' => array('Article' => array(
603 'order' => 'desc',
604 'sort' => 'title'
605 )));
606 $this->Paginator->options($options);
607
608 $expected = array('Article' => array(
609 'order' => 'desc',
610 'sort' => 'title'
611 ));
612 $this->assertEqual($expected, $this->Paginator->params['paging']);
613
614 $this->Paginator->options = array();
615 $this->Paginator->params = array();
616
617 $options = array('Article' => array(
618 'order' => 'desc',
619 'sort' => 'title'
620 ));
621 $this->Paginator->options($options);
622 $this->assertEqual($expected, $this->Paginator->params['paging']);
623
624 $options = array('paging' => array('Article' => array(
625 'order' => 'desc',
626 'sort' => 'Article.title'
627 )));
628 $this->Paginator->options($options);
629
630 $expected = array('Article' => array(
631 'order' => 'desc',
632 'sort' => 'Article.title'
633 ));
634 $this->assertEqual($expected, $this->Paginator->params['paging']);
635 }
636
637 /**
638 * testPassedArgsMergingWithUrlOptions method
639 *
640 * @access public
641 * @return void
642 */
643 function testPassedArgsMergingWithUrlOptions() {
644 Router::reload();
645 Router::parse('/');
646 Router::setRequestInfo(array(
647 array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'form' => array(), 'url' => array('url' => 'articles/index/2/foo:bar'), 'bare' => 0),
648 array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/', 'here' => '/articles/', 'webroot' => '/', 'passedArgs' => array(0 => '2', 'foo' => 'bar'))
649 ));
650 $this->Paginator->params['paging'] = array(
651 'Article' => array(
652 'page' => 1, 'current' => 3, 'count' => 13,
653 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
654 'defaults' => array(
655 'limit' => 3, 'step' => 1, 'order' => array(), 'conditions' => array()
656 ),
657 'options' => array(
658 'page' => 1, 'limit' => 3, 'order' => array(), 'conditions' => array()
659 )
660 )
661 );
662
663 $this->Paginator->params['pass'] = array(2);
664 $this->Paginator->params['named'] = array('foo' => 'bar');
665 $this->Paginator->beforeRender();
666
667 $result = $this->Paginator->sort('title');
668 $expected = array(
669 'a' => array('href' => '/articles/index/2/page:1/foo:bar/sort:title/direction:asc'),
670 'Title',
671 '/a'
672 );
673 $this->assertTags($result, $expected);
674
675 $result = $this->Paginator->numbers();
676 $expected = array(
677 array('span' => array('class' => 'current')), '1', '/span',
678 ' | ',
679 array('span' => array()), array('a' => array('href' => '/articles/index/2/page:2/foo:bar')), '2', '/a', '/span',
680 ' | ',
681 array('span' => array()), array('a' => array('href' => '/articles/index/2/page:3/foo:bar')), '3', '/a', '/span',
682 ' | ',
683 array('span' => array()), array('a' => array('href' => '/articles/index/2/page:4/foo:bar')), '4', '/a', '/span',
684 ' | ',
685 array('span' => array()), array('a' => array('href' => '/articles/index/2/page:5/foo:bar')), '5', '/a', '/span',
686 ' | ',
687 array('span' => array()), array('a' => array('href' => '/articles/index/2/page:6/foo:bar')), '6', '/a', '/span',
688 ' | ',
689 array('span' => array()), array('a' => array('href' => '/articles/index/2/page:7/foo:bar')), '7', '/a', '/span',
690 );
691 $this->assertTags($result, $expected);
692
693 $result = $this->Paginator->next('Next');
694 $expected = array(
695 '<span',
696 'a' => array('href' => '/articles/index/2/page:2/foo:bar', 'class' => 'next'),
697 'Next',
698 '/a',
699 '/span'
700 );
701 $this->assertTags($result, $expected);
702 }
703
704 /**
705 * testPagingLinks method
706 *
707 * @access public
708 * @return void
709 */
710 function testPagingLinks() {
711 $this->Paginator->params['paging'] = array('Client' => array(
712 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
713 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
714 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
715 );
716 $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
717 $expected = array(
718 'span' => array('class' => 'disabled'),
719 '&lt;&lt; Previous',
720 '/span'
721 );
722 $this->assertTags($result, $expected);
723
724 $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'div'));
725 $expected = array(
726 'div' => array('class' => 'disabled'),
727 '&lt;&lt; Previous',
728 '/div'
729 );
730 $this->assertTags($result, $expected);
731
732 $this->Paginator->params['paging']['Client']['page'] = 2;
733 $this->Paginator->params['paging']['Client']['prevPage'] = true;
734 $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
735 $expected = array(
736 '<span',
737 'a' => array('href' => '/index/page:1', 'class' => 'prev'),
738 '&lt;&lt; Previous',
739 '/a',
740 '/span'
741 );
742 $this->assertTags($result, $expected);
743
744 $result = $this->Paginator->next('Next');
745 $expected = array(
746 '<span',
747 'a' => array('href' => '/index/page:3', 'class' => 'next'),
748 'Next',
749 '/a',
750 '/span'
751 );
752 $this->assertTags($result, $expected);
753
754 $result = $this->Paginator->next('Next', array('tag' => 'li'));
755 $expected = array(
756 '<li',
757 'a' => array('href' => '/index/page:3', 'class' => 'next'),
758 'Next',
759 '/a',
760 '/li'
761 );
762 $this->assertTags($result, $expected);
763
764 $result = $this->Paginator->prev('<< Previous', array('escape' => true));
765 $expected = array(
766 '<span',
767 'a' => array('href' => '/index/page:1', 'class' => 'prev'),
768 '&lt;&lt; Previous',
769 '/a',
770 '/span'
771 );
772 $this->assertTags($result, $expected);
773
774 $result = $this->Paginator->prev('<< Previous', array('escape' => false));
775 $expected = array(
776 '<span',
777 'a' => array('href' => '/index/page:1', 'class' => 'prev'),
778 'preg:/<< Previous/',
779 '/a',
780 '/span'
781 );
782 $this->assertTags($result, $expected);
783
784 $this->Paginator->params['paging'] = array('Client' => array(
785 'page' => 1, 'current' => 1, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
786 'defaults' => array(),
787 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
788 );
789
790 $result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>');
791 $expected = array(
792 'span' => array('class' => 'prev'),
793 '&lt;strong&gt;Disabled&lt;/strong&gt;',
794 '/span'
795 );
796 $this->assertTags($result, $expected);
797
798 $result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => true));
799 $expected = array(
800 'span' => array('class' => 'prev'),
801 '&lt;strong&gt;Disabled&lt;/strong&gt;',
802 '/span'
803 );
804 $this->assertTags($result, $expected);
805
806 $result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => false));
807 $expected = array(
808 'span' => array('class' => 'prev'),
809 '<strong', 'Disabled', '/strong',
810 '/span'
811 );
812 $this->assertTags($result, $expected);
813
814 $this->Paginator->params['paging'] = array('Client' => array(
815 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
816 'defaults' => array(),
817 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
818 );
819
820 $this->Paginator->params['paging']['Client']['page'] = 2;
821 $this->Paginator->params['paging']['Client']['prevPage'] = true;
822 $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
823 $expected = array(
824 '<span',
825 'a' => array('href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC', 'class' => 'prev'),
826 '&lt;&lt; Previous',
827 '/a',
828 '/span'
829 );
830 $this->assertTags($result, $expected, true);
831
832 $result = $this->Paginator->next('Next');
833 $expected = array(
834 '<span',
835 'a' => array('href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC', 'class' => 'next'),
836 'Next',
837 '/a',
838 '/span'
839 );
840 $this->assertTags($result, $expected);
841
842 $this->Paginator->params['paging'] = array('Client' => array(
843 'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true, 'nextPage' => false, 'pageCount' => 2,
844 'defaults' => array(),
845 'options' => array('page' => 2, 'limit' => 10, 'order' => array(), 'conditions' => array())
846 ));
847 $result = $this->Paginator->prev('Prev');
848 $expected = array(
849 '<span',
850 'a' => array('href' => '/index/page:1/limit:10', 'class' => 'prev'),
851 'Prev',
852 '/a',
853 '/span'
854 );
855 $this->assertTags($result, $expected);
856
857 $this->Paginator->params['paging'] = array(
858 'Client' => array(
859 'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
860 'nextPage' => false, 'pageCount' => 2,
861 'defaults' => array(),
862 'options' => array(
863 'page' => 2, 'limit' => 10, 'order' => array(), 'conditions' => array()
864 )
865 )
866 );
867 $this->Paginator->options(array('url' => array(12, 'page' => 3)));
868 $result = $this->Paginator->prev('Prev', array('url' => array('foo' => 'bar')));
869 $expected = array(
870 '<span',
871 'a' => array('href' => '/index/12/page:1/limit:10/foo:bar', 'class' => 'prev'),
872 'Prev',
873 '/a',
874 '/span'
875 );
876 $this->assertTags($result, $expected);
877 }
878
879 /**
880 * test that __pagingLink methods use $options when $disabledOptions is an empty value.
881 * allowing you to use shortcut syntax
882 *
883 * @return void
884 */
885 function testPagingLinksOptionsReplaceEmptyDisabledOptions() {
886 $this->Paginator->params['paging'] = array(
887 'Client' => array(
888 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false,
889 'nextPage' => true, 'pageCount' => 5,
890 'defaults' => array(
891 'limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()
892 ),
893 'options' => array(
894 'page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()
895 )
896 )
897 );
898 $result = $this->Paginator->prev('<< Previous', array('escape' => false));
899 $expected = array(
900 'span' => array('class' => 'prev'),
901 'preg:/<< Previous/',
902 '/span'
903 );
904 $this->assertTags($result, $expected);
905
906 $result = $this->Paginator->next('Next >>', array('escape' => false));
907 $expected = array(
908 '<span',
909 'a' => array('href' => '/index/page:2', 'class' => 'next'),
910 'preg:/Next >>/',
911 '/a',
912 '/span'
913 );
914 $this->assertTags($result, $expected);
915 }
916
917 /**
918 * testPagingLinksNotDefaultModel
919 *
920 * Test the creation of paging links when the non default model is used.
921 *
922 * @access public
923 * @return void
924 */
925 function testPagingLinksNotDefaultModel() {
926 // Multiple Model Paginate
927 $this->Paginator->params['paging'] = array(
928 'Client' => array(
929 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
930 'defaults' => array( 'limit'=>3, 'order' => array('Client.name' => 'DESC')),
931 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())
932 ),
933 'Server' => array(
934 'page' => 1, 'current' => 1, 'count' => 5, 'prevPage' => false, 'nextPage' => false, 'pageCount' => 5,
935 'defaults' => array(),
936 'options' => array('page' => 1, 'limit' => 5, 'order' => array('Server.name' => 'ASC'), 'conditions' => array())
937 )
938 );
939 $result = $this->Paginator->next('Next', array('model' => 'Client'));
940 $expected = array(
941 '<span',
942 'a' => array('href' => '/index/page:2', 'class' => 'next'),
943 'Next',
944 '/a',
945 '/span'
946 );
947 $this->assertTags($result, $expected);
948
949 $result = $this->Paginator->next('Next', array('model' => 'Server'), 'No Next', array('model' => 'Server'));
950 $expected = array(
951 'span' => array('class' => 'next'), 'No Next', '/span'
952 );
953 $this->assertTags($result, $expected);
954 }
955
956 /**
957 * testGenericLinks method
958 *
959 * @access public
960 * @return void
961 */
962 function testGenericLinks() {
963 $result = $this->Paginator->link('Sort by title on page 5', array('sort' => 'title', 'page' => 5, 'direction' => 'desc'));
964 $expected = array(
965 'a' => array('href' => '/index/page:5/sort:title/direction:desc'),
966 'Sort by title on page 5',
967 '/a'
968 );
969 $this->assertTags($result, $expected);
970
971 $this->Paginator->params['paging']['Article']['options']['page'] = 2;
972 $result = $this->Paginator->link('Sort by title', array('sort' => 'title', 'direction' => 'desc'));
973 $expected = array(
974 'a' => array('href' => '/index/page:2/sort:title/direction:desc'),
975 'Sort by title',
976 '/a'
977 );
978 $this->assertTags($result, $expected);
979
980 $this->Paginator->params['paging']['Article']['options']['page'] = 4;
981 $result = $this->Paginator->link('Sort by title on page 4', array('sort' => 'Article.title', 'direction' => 'desc'));
982 $expected = array(
983 'a' => array('href' => '/index/page:4/sort:Article.title/direction:desc'),
984 'Sort by title on page 4',
985 '/a'
986 );
987 $this->assertTags($result, $expected);
988 }
989
990 /**
991 * Tests generation of generic links with preset options
992 *
993 * @access public
994 * @return void
995 */
996 function testGenericLinksWithPresetOptions() {
997 $result = $this->Paginator->link('Foo!', array('page' => 1));
998 $this->assertTags($result, array('a' => array('href' => '/index/page:1'), 'Foo!', '/a'));
999
1000 $this->Paginator->options(array('sort' => 'title', 'direction' => 'desc'));
1001 $result = $this->Paginator->link('Foo!', array('page' => 1));
1002 $this->assertTags($result, array(
1003 'a' => array(
1004 'href' => '/index/page:1',
1005 'sort' => 'title',
1006 'direction' => 'desc'
1007 ),
1008 'Foo!',
1009 '/a'
1010 ));
1011
1012 $this->Paginator->options(array('sort' => null, 'direction' => null));
1013 $result = $this->Paginator->link('Foo!', array('page' => 1));
1014 $this->assertTags($result, array('a' => array('href' => '/index/page:1'), 'Foo!', '/a'));
1015
1016 $this->Paginator->options(array('url' => array(
1017 'sort' => 'title',
1018 'direction' => 'desc'
1019 )));
1020 $result = $this->Paginator->link('Foo!', array('page' => 1));
1021 $this->assertTags($result, array(
1022 'a' => array('href' => '/index/page:1/sort:title/direction:desc'),
1023 'Foo!',
1024 '/a'
1025 ));
1026 }
1027
1028 /**
1029 * testNumbers method
1030 *
1031 * @access public
1032 * @return void
1033 */
1034 function testNumbers() {
1035 $this->Paginator->params['paging'] = array('Client' => array(
1036 'page' => 8, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1037 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1038 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1039 );
1040 $result = $this->Paginator->numbers();
1041 $expected = array(
1042 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1043 ' | ',
1044 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1045 ' | ',
1046 array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1047 ' | ',
1048 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1049 ' | ',
1050 array('span' => array('class' => 'current')), '8', '/span',
1051 ' | ',
1052 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1053 ' | ',
1054 array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1055 ' | ',
1056 array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1057 ' | ',
1058 array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1059 );
1060 $this->assertTags($result, $expected);
1061
1062 $result = $this->Paginator->numbers(array('tag' => 'li'));
1063 $expected = array(
1064 array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
1065 ' | ',
1066 array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
1067 ' | ',
1068 array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
1069 ' | ',
1070 array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
1071 ' | ',
1072 array('li' => array('class' => 'current')), '8', '/li',
1073 ' | ',
1074 array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
1075 ' | ',
1076 array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li',
1077 ' | ',
1078 array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li',
1079 ' | ',
1080 array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li',
1081 );
1082 $this->assertTags($result, $expected);
1083
1084 $result = $this->Paginator->numbers(array('tag' => 'li', 'separator' => false));
1085 $expected = array(
1086 array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
1087 array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
1088 array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
1089 array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
1090 array('li' => array('class' => 'current')), '8', '/li',
1091 array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
1092 array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li',
1093 array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li',
1094 array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li',
1095 );
1096 $this->assertTags($result, $expected);
1097
1098 $result = $this->Paginator->numbers(true);
1099 $expected = array(
1100 array('span' => array()), array('a' => array('href' => '/index/page:1')), 'first', '/a', '/span',
1101 ' | ',
1102 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1103 ' | ',
1104 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1105 ' | ',
1106 array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1107 ' | ',
1108 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1109 ' | ',
1110 array('span' => array('class' => 'current')), '8', '/span',
1111 ' | ',
1112 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1113 ' | ',
1114 array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1115 ' | ',
1116 array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1117 ' | ',
1118 array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1119 ' | ',
1120 array('span' => array()), array('a' => array('href' => '/index/page:15')), 'last', '/a', '/span',
1121 );
1122 $this->assertTags($result, $expected);
1123
1124 $this->Paginator->params['paging'] = array('Client' => array(
1125 'page' => 1, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1126 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1127 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1128 );
1129 $result = $this->Paginator->numbers();
1130 $expected = array(
1131 array('span' => array('class' => 'current')), '1', '/span',
1132 ' | ',
1133 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1134 ' | ',
1135 array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1136 ' | ',
1137 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1138 ' | ',
1139 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1140 ' | ',
1141 array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1142 ' | ',
1143 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1144 ' | ',
1145 array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1146 ' | ',
1147 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1148 );
1149 $this->assertTags($result, $expected);
1150
1151
1152 $this->Paginator->params['paging'] = array('Client' => array(
1153 'page' => 14, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1154 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1155 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1156 );
1157 $result = $this->Paginator->numbers();
1158 $expected = array(
1159 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1160 ' | ',
1161 array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1162 ' | ',
1163 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1164 ' | ',
1165 array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1166 ' | ',
1167 array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1168 ' | ',
1169 array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1170 ' | ',
1171 array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
1172 ' | ',
1173 array('span' => array('class' => 'current')), '14', '/span',
1174 ' | ',
1175 array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span',
1176 );
1177 $this->assertTags($result, $expected);
1178
1179 $this->Paginator->params['paging'] = array('Client' => array(
1180 'page' => 2, 'current' => 3, 'count' => 27, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 9,
1181 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1182 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1183 );
1184
1185 $result = $this->Paginator->numbers(array('first' => 1));
1186 $expected = array(
1187 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1188 ' | ',
1189 array('span' => array('class' => 'current')), '2', '/span',
1190 ' | ',
1191 array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1192 ' | ',
1193 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1194 ' | ',
1195 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1196 ' | ',
1197 array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1198 ' | ',
1199 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1200 ' | ',
1201 array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1202 ' | ',
1203 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1204 );
1205 $this->assertTags($result, $expected);
1206
1207 $result = $this->Paginator->numbers(array('last' => 1));
1208 $expected = array(
1209 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1210 ' | ',
1211 array('span' => array('class' => 'current')), '2', '/span',
1212 ' | ',
1213 array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1214 ' | ',
1215 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1216 ' | ',
1217 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1218 ' | ',
1219 array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1220 ' | ',
1221 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1222 ' | ',
1223 array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1224 ' | ',
1225 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1226 );
1227 $this->assertTags($result, $expected);
1228
1229 $this->Paginator->params['paging'] = array('Client' => array(
1230 'page' => 15, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1231 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1232 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1233 );
1234
1235 $result = $this->Paginator->numbers(array('first' => 1));
1236 $expected = array(
1237 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1238 '...',
1239 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1240 ' | ',
1241 array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1242 ' | ',
1243 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1244 ' | ',
1245 array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1246 ' | ',
1247 array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1248 ' | ',
1249 array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1250 ' | ',
1251 array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
1252 ' | ',
1253 array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span',
1254 ' | ',
1255 array('span' => array('class' => 'current')), '15', '/span',
1256
1257 );
1258 $this->assertTags($result, $expected);
1259
1260 $this->Paginator->params['paging'] = array('Client' => array(
1261 'page' => 10, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1262 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1263 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1264 );
1265
1266 $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
1267 $expected = array(
1268 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1269 '...',
1270 array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1271 ' | ',
1272 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1273 ' | ',
1274 array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1275 ' | ',
1276 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1277 ' | ',
1278 array('span' => array('class' => 'current')), '10', '/span',
1279 ' | ',
1280 array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1281 ' | ',
1282 array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1283 ' | ',
1284 array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
1285 ' | ',
1286 array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span',
1287 ' | ',
1288 array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span',
1289 );
1290 $this->assertTags($result, $expected);
1291
1292 $this->Paginator->params['paging'] = array('Client' => array(
1293 'page' => 6, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42,
1294 'defaults' => array('limit' => 15, 'step' => 1, 'page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1295 'options' => array('page' => 6, 'limit' => 15, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1296 );
1297
1298 $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
1299 $expected = array(
1300 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1301 ' | ',
1302 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1303 ' | ',
1304 array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1305 ' | ',
1306 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1307 ' | ',
1308 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1309 ' | ',
1310 array('span' => array('class' => 'current')), '6', '/span',
1311 ' | ',
1312 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1313 ' | ',
1314 array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1315 ' | ',
1316 array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1317 ' | ',
1318 array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1319 '...',
1320 array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span',
1321 );
1322 $this->assertTags($result, $expected);
1323
1324 $this->Paginator->params['paging'] = array('Client' => array(
1325 'page' => 37, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42,
1326 'defaults' => array('limit' => 15, 'step' => 1, 'page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1327 'options' => array('page' => 37, 'limit' => 15, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1328 );
1329
1330 $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
1331 $expected = array(
1332 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1333 '...',
1334 array('span' => array()), array('a' => array('href' => '/index/page:33')), '33', '/a', '/span',
1335 ' | ',
1336 array('span' => array()), array('a' => array('href' => '/index/page:34')), '34', '/a', '/span',
1337 ' | ',
1338 array('span' => array()), array('a' => array('href' => '/index/page:35')), '35', '/a', '/span',
1339 ' | ',
1340 array('span' => array()), array('a' => array('href' => '/index/page:36')), '36', '/a', '/span',
1341 ' | ',
1342 array('span' => array('class' => 'current')), '37', '/span',
1343 ' | ',
1344 array('span' => array()), array('a' => array('href' => '/index/page:38')), '38', '/a', '/span',
1345 ' | ',
1346 array('span' => array()), array('a' => array('href' => '/index/page:39')), '39', '/a', '/span',
1347 ' | ',
1348 array('span' => array()), array('a' => array('href' => '/index/page:40')), '40', '/a', '/span',
1349 ' | ',
1350 array('span' => array()), array('a' => array('href' => '/index/page:41')), '41', '/a', '/span',
1351 ' | ',
1352 array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span',
1353 );
1354 $this->assertTags($result, $expected);
1355
1356 $this->Paginator->params['paging'] = array(
1357 'Client' => array(
1358 'page' => 1,
1359 'current' => 10,
1360 'count' => 30,
1361 'prevPage' => false,
1362 'nextPage' => 2,
1363 'pageCount' => 3,
1364 'defaults' => array(
1365 'limit' => 3,
1366 'step' => 1,
1367 'order' => array('Client.name' => 'DESC'),
1368 'conditions' => array()
1369 ),
1370 'options' => array(
1371 'page' => 1,
1372 'limit' => 3,
1373 'order' => array('Client.name' => 'DESC'),
1374 'conditions' => array()
1375 )
1376 )
1377 );
1378 $options = array('modulus' => 10);
1379 $result = $this->Paginator->numbers($options);
1380 $expected = array(
1381 array('span' => array('class' => 'current')), '1', '/span',
1382 ' | ',
1383 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1384 ' | ',
1385 array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1386 );
1387 $this->assertTags($result, $expected);
1388
1389 $this->Paginator->params['paging'] = array('Client' => array(
1390 'page' => 2, 'current' => 10, 'count' => 31, 'prevPage' => true, 'nextPage' => true, 'pageCount' => 4,
1391 'defaults' => array('limit' => 10),
1392 'options' => array('page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1393 );
1394 $result = $this->Paginator->numbers();
1395 $expected = array(
1396 array('span' => array()), array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '1', '/a', '/span',
1397 ' | ',
1398 array('span' => array('class' => 'current')), '2', '/span',
1399 ' | ',
1400 array('span' => array()), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span',
1401 ' | ',
1402 array('span' => array()), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span',
1403 );
1404 $this->assertTags($result, $expected);
1405
1406
1407 $this->Paginator->params['paging'] = array('Client' => array(
1408 'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
1409 'defaults' => array('limit' => 10),
1410 'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array()))
1411 );
1412
1413 $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
1414 $expected = array(
1415 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1416 ' | ',
1417 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1418 '...',
1419 array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
1420 ' | ',
1421 array('span' => array('class' => 'current')), '4895', '/span',
1422 ' | ',
1423 array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1424 ' | ',
1425 array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1426 );
1427 $this->assertTags($result, $expected);
1428
1429 $this->Paginator->params['paging']['Client']['page'] = 3;
1430
1431 $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
1432 $expected = array(
1433 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1434 ' | ',
1435 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1436 ' | ',
1437 array('span' => array('class' => 'current')), '3', '/span',
1438 ' | ',
1439 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1440 '...',
1441 array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1442 ' | ',
1443 array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1444 );
1445 $this->assertTags($result, $expected);
1446
1447 $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - '));
1448 $expected = array(
1449 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1450 ' - ',
1451 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1452 ' - ',
1453 array('span' => array('class' => 'current')), '3', '/span',
1454 ' - ',
1455 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1456 '...',
1457 array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1458 ' - ',
1459 array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1460 );
1461 $this->assertTags($result, $expected);
1462
1463 $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 5, 'last' => 5, 'separator' => ' - '));
1464 $expected = array(
1465 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1466 ' - ',
1467 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1468 ' - ',
1469 array('span' => array('class' => 'current')), '3', '/span',
1470 ' - ',
1471 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1472 ' - ',
1473 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1474 ' - ',
1475 array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1476 '...',
1477 array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
1478 ' - ',
1479 array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
1480 ' - ',
1481 array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
1482 ' - ',
1483 array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1484 ' - ',
1485 array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1486 );
1487 $this->assertTags($result, $expected);
1488
1489 $this->Paginator->params['paging']['Client']['page'] = 4893;
1490 $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
1491 $expected = array(
1492 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1493 ' - ',
1494 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1495 ' - ',
1496 array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1497 ' - ',
1498 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1499 ' - ',
1500 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1501 '...',
1502 array('span' => array()), array('a' => array('href' => '/index/page:4891')), '4891', '/a', '/span',
1503 ' - ',
1504 array('span' => array()), array('a' => array('href' => '/index/page:4892')), '4892', '/a', '/span',
1505 ' - ',
1506 array('span' => array('class' => 'current')), '4893', '/span',
1507 ' - ',
1508 array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
1509 ' - ',
1510 array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
1511 ' - ',
1512 array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1513 ' - ',
1514 array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1515 );
1516 $this->assertTags($result, $expected);
1517
1518 $this->Paginator->params['paging']['Client']['page'] = 58;
1519 $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
1520 $expected = array(
1521 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1522 ' - ',
1523 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1524 ' - ',
1525 array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1526 ' - ',
1527 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1528 ' - ',
1529 array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1530 '...',
1531 array('span' => array()), array('a' => array('href' => '/index/page:56')), '56', '/a', '/span',
1532 ' - ',
1533 array('span' => array()), array('a' => array('href' => '/index/page:57')), '57', '/a', '/span',
1534 ' - ',
1535 array('span' => array('class' => 'current')), '58', '/span',
1536 ' - ',
1537 array('span' => array()), array('a' => array('href' => '/index/page:59')), '59', '/a', '/span',
1538 ' - ',
1539 array('span' => array()), array('a' => array('href' => '/index/page:60')), '60', '/a', '/span',
1540 '...',
1541 array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
1542 ' - ',
1543 array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
1544 ' - ',
1545 array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
1546 ' - ',
1547 array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1548 ' - ',
1549 array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1550 );
1551 $this->assertTags($result, $expected);
1552
1553 $this->Paginator->params['paging']['Client']['page'] = 5;
1554 $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
1555 $expected = array(
1556 array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
1557 ' - ',
1558 array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1559 ' - ',
1560 array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1561 ' - ',
1562 array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1563 ' - ',
1564 array('span' => array('class' => 'current')), '5', '/span',
1565 ' - ',
1566 array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1567 ' - ',
1568 array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1569 '...',
1570 array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
1571 ' - ',
1572 array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
1573 ' - ',
1574 array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
1575 ' - ',
1576 array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1577 ' - ',
1578 array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1579 );
1580 $this->assertTags($result, $expected);
1581 }
1582
1583 /**
1584 * testFirstAndLast method
1585 *
1586 * @access public
1587 * @return void
1588 */
1589 function testFirstAndLast() {
1590 $this->Paginator->params['paging'] = array('Client' => array(
1591 'page' => 1, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1592 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1593 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1594 );
1595
1596 $result = $this->Paginator->first();
1597 $expected = '';
1598 $this->assertEqual($result, $expected);
1599
1600 $this->Paginator->params['paging'] = array('Client' => array(
1601 'page' => 4, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1602 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1603 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1604 );
1605
1606 $result = $this->Paginator->first();
1607 $expected = array(
1608 '<span',
1609 'a' => array('href' => '/index/page:1'),
1610 '&lt;&lt; first',
1611 '/a',
1612 '/span'
1613 );
1614 $this->assertTags($result, $expected);
1615
1616 $result = $this->Paginator->first('<<', array('tag' => 'li'));
1617 $expected = array(
1618 '<li',
1619 'a' => array('href' => '/index/page:1'),
1620 '&lt;&lt;',
1621 '/a',
1622 '/li'
1623 );
1624 $this->assertTags($result, $expected);
1625
1626 $result = $this->Paginator->last();
1627 $expected = array(
1628 '<span',
1629 'a' => array('href' => '/index/page:15'),
1630 'last &gt;&gt;',
1631 '/a',
1632 '/span'
1633 );
1634 $this->assertTags($result, $expected);
1635
1636 $result = $this->Paginator->last(1);
1637 $expected = array(
1638 '...',
1639 '<span',
1640 'a' => array('href' => '/index/page:15'),
1641 '15',
1642 '/a',
1643 '/span'
1644 );
1645 $this->assertTags($result, $expected);
1646
1647 $result = $this->Paginator->last(2);
1648 $expected = array(
1649 '...',
1650 '<span',
1651 array('a' => array('href' => '/index/page:14')), '14', '/a',
1652 '/span',
1653 ' | ',
1654 '<span',
1655 array('a' => array('href' => '/index/page:15')), '15', '/a',
1656 '/span',
1657 );
1658 $this->assertTags($result, $expected);
1659
1660 $result = $this->Paginator->last(2, array('tag' => 'li'));
1661 $expected = array(
1662 '...',
1663 '<li',
1664 array('a' => array('href' => '/index/page:14')), '14', '/a',
1665 '/li',
1666 ' | ',
1667 '<li',
1668 array('a' => array('href' => '/index/page:15')), '15', '/a',
1669 '/li',
1670 );
1671 $this->assertTags($result, $expected);
1672
1673 $this->Paginator->params['paging'] = array('Client' => array(
1674 'page' => 15, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1675 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
1676 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1677 );
1678 $result = $this->Paginator->last();
1679 $expected = '';
1680 $this->assertEqual($result, $expected);
1681
1682 $this->Paginator->params['paging'] = array('Client' => array(
1683 'page' => 4, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
1684 'defaults' => array('limit' => 3),
1685 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
1686 );
1687
1688 $result = $this->Paginator->first();
1689 $expected = array(
1690 '<span',
1691 array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '&lt;&lt; first', '/a',
1692 '/span',
1693 );
1694 $this->assertTags($result, $expected);
1695
1696 $result = $this->Paginator->last();
1697 $expected = array(
1698 '<span',
1699 array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), 'last &gt;&gt;', '/a',
1700 '/span',
1701 );
1702 $this->assertTags($result, $expected);
1703
1704 $result = $this->Paginator->last(1);
1705 $expected = array(
1706 '...',
1707 '<span',
1708 array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
1709 '/span',
1710 );
1711 $this->assertTags($result, $expected);
1712
1713 $result = $this->Paginator->last(2);
1714 $expected = array(
1715 '...',
1716 '<span',
1717 array('a' => array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a',
1718 '/span',
1719 ' | ',
1720 '<span',
1721 array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
1722 '/span',
1723 );
1724 $this->assertTags($result, $expected);
1725
1726 $this->Paginator->options(array('url' => array('full_base' => true)));
1727 $result = $this->Paginator->first();
1728
1729 $expected = array(
1730 '<span',
1731 array('a' => array('href' => FULL_BASE_URL . '/index/page:1/sort:Client.name/direction:DESC')), '&lt;&lt; first', '/a',
1732 '/span',
1733 );
1734 $this->assertTags($result, $expected);
1735 }
1736
1737 /**
1738 * testCounter method
1739 *
1740 * @access public
1741 * @return void
1742 */
1743 function testCounter() {
1744 $this->Paginator->params['paging'] = array(
1745 'Client' => array(
1746 'page' => 1,
1747 'current' => 3,
1748 'count' => 13,
1749 'prevPage' => false,
1750 'nextPage' => true,
1751 'pageCount' => 5,
1752 'defaults' => array(
1753 'limit' => 3,
1754 'step' => 1,
1755 'order' => array('Client.name' => 'DESC'),
1756 'conditions' => array()
1757 ),
1758 'options' => array(
1759 'page' => 1,
1760 'limit' => 3,
1761 'order' => array('Client.name' => 'DESC'),
1762 'conditions' => array(),
1763 'separator' => 'of'
1764 ),
1765 )
1766 );
1767 $input = 'Page %page% of %pages%, showing %current% records out of %count% total, ';
1768 $input .= 'starting on record %start%, ending on %end%';
1769 $result = $this->Paginator->counter($input);
1770 $expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ';
1771 $expected .= 'ending on 3';
1772 $this->assertEqual($result, $expected);
1773
1774 $input = 'Page {:page} of {:pages}, showing {:current} records out of {:count} total, ';
1775 $input .= 'starting on record {:start}, ending on {:end}';
1776 $result = $this->Paginator->counter($input);
1777 $this->assertEqual($result, $expected);
1778
1779 $input = 'Page %page% of %pages%';
1780 $result = $this->Paginator->counter($input);
1781 $expected = 'Page 1 of 5';
1782 $this->assertEqual($result, $expected);
1783
1784 $result = $this->Paginator->counter(array('format' => $input));
1785 $expected = 'Page 1 of 5';
1786 $this->assertEqual($result, $expected);
1787
1788 $result = $this->Paginator->counter(array('format' => 'pages'));
1789 $expected = '1 of 5';
1790 $this->assertEqual($result, $expected);
1791
1792 $result = $this->Paginator->counter(array('format' => 'range'));
1793 $expected = '1 - 3 of 13';
1794 $this->assertEqual($result, $expected);
1795 }
1796
1797 /**
1798 * testHasPage method
1799 *
1800 * @access public
1801 * @return void
1802 */
1803 function testHasPage() {
1804 $result = $this->Paginator->hasPage('Article', 15);
1805 $this->assertFalse($result);
1806
1807 $result = $this->Paginator->hasPage('UndefinedModel', 2);
1808 $this->assertFalse($result);
1809
1810 $result = $this->Paginator->hasPage('Article', 2);
1811 $this->assertTrue($result);
1812
1813 $result = $this->Paginator->hasPage(2);
1814 $this->assertTrue($result);
1815 }
1816
1817 /**
1818 * testWithPlugin method
1819 *
1820 * @access public
1821 * @return void
1822 */
1823 function testWithPlugin() {
1824 Router::reload();
1825 Router::setRequestInfo(array(
1826 array(
1827 'pass' => array(), 'named' => array(), 'prefix' => null, 'form' => array(),
1828 'controller' => 'magazines', 'plugin' => 'my_plugin', 'action' => 'index',
1829 'url' => array('ext' => 'html', 'url' => 'my_plugin/magazines')),
1830 array('base' => '', 'here' => '/my_plugin/magazines', 'webroot' => '/')
1831 ));
1832
1833 $result = $this->Paginator->link('Page 3', array('page' => 3));
1834 $expected = array(
1835 'a' => array('href' => '/my_plugin/magazines/index/page:3'), 'Page 3', '/a'
1836 );
1837 $this->assertTags($result, $expected);
1838
1839 $this->Paginator->options(array('url' => array('action' => 'another_index')));
1840 $result = $this->Paginator->link('Page 3', array('page' => 3));
1841 $expected = array(
1842 'a' => array('href' => '/my_plugin/magazines/another_index/page:3'), 'Page 3', '/a'
1843 );
1844 $this->assertTags($result, $expected);
1845
1846 $this->Paginator->options(array('url' => array('controller' => 'issues')));
1847 $result = $this->Paginator->link('Page 3', array('page' => 3));
1848 $expected = array(
1849 'a' => array('href' => '/my_plugin/issues/index/page:3'), 'Page 3', '/a'
1850 );
1851 $this->assertTags($result, $expected);
1852
1853 $this->Paginator->options(array('url' => array('plugin' => null)));
1854 $result = $this->Paginator->link('Page 3', array('page' => 3));
1855 $expected = array(
1856 'a' => array('/magazines/index/page:3'), 'Page 3', '/a'
1857 );
1858
1859 $this->Paginator->options(array('url' => array('plugin' => null, 'controller' => 'issues')));
1860 $result = $this->Paginator->link('Page 3', array('page' => 3));
1861 $expected = array(
1862 'a' => array('href' => '/issues/index/page:3'), 'Page 3', '/a'
1863 );
1864 $this->assertTags($result, $expected);
1865 }
1866
1867 /**
1868 * testNextLinkUsingDotNotation method
1869 *
1870 * @access public
1871 * @return void
1872 */
1873 function testNextLinkUsingDotNotation() {
1874 Router::reload();
1875 Router::parse('/');
1876 Router::setRequestInfo(array(
1877 array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
1878 array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
1879 ));
1880
1881 $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
1882 $this->Paginator->params['paging']['Article']['page'] = 1;
1883
1884 $test = array('url'=> array(
1885 'page'=> '1',
1886 'sort'=>'Article.title',
1887 'direction'=>'asc',
1888 ));
1889 $this->Paginator->options($test);
1890
1891 $result = $this->Paginator->next('Next');
1892 $expected = array(
1893 '<span',
1894 'a' => array('href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc', 'class' => 'next'),
1895 'Next',
1896 '/a',
1897 '/span',
1898 );
1899 $this->assertTags($result, $expected);
1900 }
1901
1902 /**
1903 * test that mock classes injected into paginatorHelper are called when using link()
1904 *
1905 * @return void
1906 */
1907 function testMockAjaxProviderClassInjection() {
1908 $Paginator =& new PaginatorHelper(array('ajax' => 'PaginatorMockJs'));
1909 $Paginator->params['paging'] = array(
1910 'Article' => array(
1911 'current' => 9,
1912 'count' => 62,
1913 'prevPage' => false,
1914 'nextPage' => true,
1915 'pageCount' => 7,
1916 'defaults' => array(),
1917 'options' => array()
1918 )
1919 );
1920 $Paginator->PaginatorMockJs =& new PaginatorMockJsHelper();
1921 $Paginator->PaginatorMockJs->expectOnce('link');
1922 $result = $Paginator->link('Page 2', array('page' => 2), array('update' => '#content'));
1923
1924 $this->expectError();
1925 $Paginator =& new PaginatorHelper(array('ajax' => 'Form'));
1926 }
1927 }