Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 1
<?php
2
/**
3
 * PaginatorHelperTest file
4
 *
5
 * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
14
 * @package       Cake.Test.Case.View.Helper
15
 * @since         CakePHP(tm) v 1.2.0.4206
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
App::uses('View', 'View');
20
App::uses('HtmlHelper', 'View/Helper');
21
App::uses('JsHelper', 'View/Helper');
22
App::uses('PaginatorHelper', 'View/Helper');
23
App::uses('FormHelper', 'View/Helper');
24
 
25
if (!defined('FULL_BASE_URL')) {
26
	define('FULL_BASE_URL', 'http://cakephp.org');
27
}
28
 
29
/**
30
 * PaginatorHelperTest class
31
 *
32
 * @package       Cake.Test.Case.View.Helper
33
 */
34
class PaginatorHelperTest extends CakeTestCase {
35
 
36
/**
37
 * setUp method
38
 *
39
 * @return void
40
 */
41
	public function setUp() {
42
		parent::setUp();
43
		Configure::write('Config.language', 'eng');
44
		$controller = null;
45
		$this->View = new View($controller);
46
		$this->Paginator = new PaginatorHelper($this->View);
47
		$this->Paginator->Js = $this->getMock('PaginatorHelper', array(), array($this->View));
48
		$this->Paginator->request = new CakeRequest(null, false);
49
		$this->Paginator->request->addParams(array(
50
			'paging' => array(
51
				'Article' => array(
52
					'page' => 2,
53
					'current' => 9,
54
					'count' => 62,
55
					'prevPage' => false,
56
					'nextPage' => true,
57
					'pageCount' => 7,
58
					'order' => null,
59
					'limit' => 20,
60
					'options' => array(
61
						'page' => 1,
62
						'conditions' => array()
63
					),
64
					'paramType' => 'named'
65
				)
66
			)
67
		));
68
		$this->Paginator->Html = new HtmlHelper($this->View);
69
 
70
		Configure::write('Routing.prefixes', array());
71
		Router::reload();
72
	}
73
 
74
/**
75
 * tearDown method
76
 *
77
 * @return void
78
 */
79
	public function tearDown() {
80
		parent::tearDown();
81
		unset($this->View, $this->Paginator);
82
	}
83
 
84
/**
85
 * testHasPrevious method
86
 *
87
 * @return void
88
 */
89
	public function testHasPrevious() {
90
		$this->assertFalse($this->Paginator->hasPrev());
91
		$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
92
		$this->assertTrue($this->Paginator->hasPrev());
93
		$this->Paginator->request->params['paging']['Article']['prevPage'] = false;
94
	}
95
 
96
/**
97
 * testHasNext method
98
 *
99
 * @return void
100
 */
101
	public function testHasNext() {
102
		$this->assertTrue($this->Paginator->hasNext());
103
		$this->Paginator->request->params['paging']['Article']['nextPage'] = false;
104
		$this->assertFalse($this->Paginator->hasNext());
105
		$this->Paginator->request->params['paging']['Article']['nextPage'] = true;
106
	}
107
 
108
/**
109
 * testDisabledLink method
110
 *
111
 * @return void
112
 */
113
	public function testDisabledLink() {
114
		$this->Paginator->request->params['paging']['Article']['nextPage'] = false;
115
		$this->Paginator->request->params['paging']['Article']['page'] = 1;
116
		$result = $this->Paginator->next('Next', array(), true);
117
		$expected = '<span class="next">Next</span>';
118
		$this->assertEquals($expected, $result);
119
 
120
		$this->Paginator->request->params['paging']['Article']['prevPage'] = false;
121
		$result = $this->Paginator->prev('prev', array('update' => 'theList', 'indicator' => 'loading', 'url' => array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span'));
122
		$expected = array(
123
			'span' => array('class' => 'disabled'), 'prev', '/span'
124
		);
125
		$this->assertTags($result, $expected);
126
	}
127
 
128
/**
129
 * testSortLinks method
130
 *
131
 * @return void
132
 */
133
	public function testSortLinks() {
134
		Router::reload();
135
		Router::parse('/');
136
		Router::setRequestInfo(array(
137
			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')),
138
			array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
139
		));
140
		$this->Paginator->options(array('url' => array('param')));
141
		$this->Paginator->request['paging'] = array(
142
			'Article' => array(
143
				'current' => 9,
144
				'count' => 62,
145
				'prevPage' => false,
146
				'nextPage' => true,
147
				'pageCount' => 7,
148
				'options' => array(
149
					'page' => 1,
150
					'order' => array('date' => 'asc'),
151
					'conditions' => array()
152
				),
153
				'paramType' => 'named'
154
			)
155
		);
156
 
157
		$result = $this->Paginator->sort('title');
158
		$expected = array(
159
			'a' => array('href' => '/officespace/accounts/index/param/sort:title/direction:asc'),
160
			'Title',
161
			'/a'
162
		);
163
		$this->assertTags($result, $expected);
164
 
165
		$result = $this->Paginator->sort('date');
166
		$expected = array(
167
			'a' => array('href' => '/officespace/accounts/index/param/sort:date/direction:desc', 'class' => 'asc'),
168
			'Date',
169
			'/a'
170
		);
171
		$this->assertTags($result, $expected);
172
 
173
		$result = $this->Paginator->sort('title', 'TestTitle');
174
		$expected = array(
175
			'a' => array('href' => '/officespace/accounts/index/param/sort:title/direction:asc'),
176
			'TestTitle',
177
			'/a'
178
		);
179
		$this->assertTags($result, $expected);
180
 
181
		$result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'));
182
		$expected = array(
183
			'a' => array('href' => '/officespace/accounts/index/param/sort:title/direction:asc'),
184
			'ascending',
185
			'/a'
186
		);
187
		$this->assertTags($result, $expected);
188
 
189
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = 'title';
190
		$result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'));
191
		$expected = array(
192
			'a' => array('href' => '/officespace/accounts/index/param/sort:title/direction:desc', 'class' => 'asc'),
193
			'descending',
194
			'/a'
195
		);
196
		$this->assertTags($result, $expected);
197
 
198
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
199
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
200
		$result = $this->Paginator->sort('title');
201
		$this->assertRegExp('/\/accounts\/index\/param\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
202
 
203
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
204
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
205
		$result = $this->Paginator->sort('title');
206
		$this->assertRegExp('/\/accounts\/index\/param\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
207
 
208
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
209
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
210
		$result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc'));
211
		$this->assertRegExp('/\/accounts\/index\/param\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
212
 
213
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
214
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
215
		$result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc'));
216
		$this->assertRegExp('/\/accounts\/index\/param\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
217
 
218
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
219
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
220
		$result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc'));
221
		$this->assertRegExp('/\/accounts\/index\/param\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
222
 
223
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
224
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
225
		$result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc'));
226
		$this->assertRegExp('/\/accounts\/index\/param\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
227
 
228
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
229
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
230
		$result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc', 'class' => 'foo'));
231
		$this->assertRegExp('/\/accounts\/index\/param\/sort:title\/direction:desc" class="foo asc">Title<\/a>$/', $result);
232
	}
233
 
234
/**
235
 * testSortLinksWithLockOption method
236
 *
237
 * @return void
238
 */
239
	public function testSortLinksWithLockOption() {
240
		Router::reload();
241
		Router::parse('/');
242
		Router::setRequestInfo(array(
243
			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')),
244
			array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
245
		));
246
		$this->Paginator->options(array('url' => array('param')));
247
		$this->Paginator->request['paging'] = array(
248
			'Article' => array(
249
				'current' => 9,
250
				'count' => 62,
251
				'prevPage' => false,
252
				'nextPage' => true,
253
				'pageCount' => 7,
254
				'options' => array(
255
					'page' => 1,
256
					'order' => array('date' => 'asc'),
257
					'conditions' => array()
258
				),
259
				'paramType' => 'named'
260
			)
261
		);
262
 
263
		$result = $this->Paginator->sort('distance', null, array('lock' => true));
264
		$expected = array(
265
			'a' => array('href' => '/officespace/accounts/index/param/sort:distance/direction:asc'),
266
			'Distance',
267
			'/a'
268
		);
269
		$this->assertTags($result, $expected);
270
 
271
		$this->Paginator->request->params['paging']['Article']['options']['sort'] = 'distance';
272
		$result = $this->Paginator->sort('distance', null, array('lock' => true));
273
		$expected = array(
274
			'a' => array('href' => '/officespace/accounts/index/param/sort:distance/direction:asc', 'class' => 'asc locked'),
275
			'Distance',
276
			'/a'
277
		);
278
		$this->assertTags($result, $expected);
279
	}
280
 
281
/**
282
 * test that sort() works with virtual field order options.
283
 *
284
 * @return void
285
 */
286
	public function testSortLinkWithVirtualField() {
287
		Router::setRequestInfo(array(
288
			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')),
289
			array('base' => '', 'here' => '/accounts/', 'webroot' => '/')
290
		));
291
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('full_name' => 'asc');
292
 
293
		$result = $this->Paginator->sort('Article.full_name');
294
		$expected = array(
295
			'a' => array('href' => '/accounts/index/sort:Article.full_name/direction:desc', 'class' => 'asc'),
296
			'Article Full Name',
297
			'/a'
298
		);
299
		$this->assertTags($result, $expected);
300
 
301
		$result = $this->Paginator->sort('full_name');
302
		$expected = array(
303
			'a' => array('href' => '/accounts/index/sort:full_name/direction:desc', 'class' => 'asc'),
304
			'Full Name',
305
			'/a'
306
		);
307
		$this->assertTags($result, $expected);
308
 
309
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('full_name' => 'desc');
310
		$result = $this->Paginator->sort('Article.full_name');
311
		$expected = array(
312
			'a' => array('href' => '/accounts/index/sort:Article.full_name/direction:asc', 'class' => 'desc'),
313
			'Article Full Name',
314
			'/a'
315
		);
316
		$this->assertTags($result, $expected);
317
 
318
		$result = $this->Paginator->sort('full_name');
319
		$expected = array(
320
			'a' => array('href' => '/accounts/index/sort:full_name/direction:asc', 'class' => 'desc'),
321
			'Full Name',
322
			'/a'
323
		);
324
		$this->assertTags($result, $expected);
325
	}
326
 
327
/**
328
 * testSortLinksUsingDirectionOption method
329
 *
330
 * @return void
331
 */
332
	public function testSortLinksUsingDirectionOption() {
333
		Router::reload();
334
		Router::parse('/');
335
		Router::setRequestInfo(array(
336
			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(),
337
				'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true')),
338
			array('base' => '/', 'here' => '/accounts/', 'webroot' => '/')
339
		));
340
		$this->Paginator->options(array('url' => array('param')));
341
 
342
		$result = $this->Paginator->sort('title', 'TestTitle', array('direction' => 'desc'));
343
		$expected = array(
344
			'a' => array('href' => '/accounts/index/param/sort:title/direction:desc'),
345
			'TestTitle',
346
			'/a'
347
		);
348
		$this->assertTags($result, $expected);
349
 
350
		$result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'), array('direction' => 'desc'));
351
		$expected = array(
352
			'a' => array('href' => '/accounts/index/param/sort:title/direction:desc'),
353
			'descending',
354
			'/a'
355
		);
356
		$this->assertTags($result, $expected);
357
	}
358
 
359
/**
360
 * testSortLinksUsingDotNotation method
361
 *
362
 * @return void
363
 */
364
	public function testSortLinksUsingDotNotation() {
365
		Router::reload();
366
		Router::parse('/');
367
		Router::setRequestInfo(array(
368
			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
369
			array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
370
		));
371
 
372
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
373
		$result = $this->Paginator->sort('Article.title');
374
		$expected = array(
375
			'a' => array('href' => '/officespace/accounts/index/sort:Article.title/direction:asc', 'class' => 'desc'),
376
			'Article Title',
377
			'/a'
378
		);
379
		$this->assertTags($result, $expected);
380
 
381
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
382
		$result = $this->Paginator->sort('Article.title', 'Title');
383
		$expected = array(
384
			'a' => array('href' => '/officespace/accounts/index/sort:Article.title/direction:asc', 'class' => 'desc'),
385
			'Title',
386
			'/a'
387
		);
388
		$this->assertTags($result, $expected);
389
 
390
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
391
		$result = $this->Paginator->sort('Article.title', 'Title');
392
		$expected = array(
393
			'a' => array('href' => '/officespace/accounts/index/sort:Article.title/direction:desc', 'class' => 'asc'),
394
			'Title',
395
			'/a'
396
		);
397
		$this->assertTags($result, $expected);
398
 
399
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Account.title' => 'asc');
400
		$result = $this->Paginator->sort('title');
401
		$expected = array(
402
			'a' => array('href' => '/officespace/accounts/index/sort:title/direction:asc'),
403
			'Title',
404
			'/a'
405
		);
406
		$this->assertTags($result, $expected);
407
	}
408
 
409
/**
410
 * testSortKey method
411
 *
412
 * @return void
413
 */
414
	public function testSortKey() {
415
		$result = $this->Paginator->sortKey(null, array(
416
			'order' => array('Article.title' => 'desc'
417
		)));
418
		$this->assertEquals('Article.title', $result);
419
 
420
		$result = $this->Paginator->sortKey('Article', array('order' => 'Article.title'));
421
		$this->assertEquals('Article.title', $result);
422
 
423
		$result = $this->Paginator->sortKey('Article', array('sort' => 'Article.title'));
424
		$this->assertEquals('Article.title', $result);
425
 
426
		$result = $this->Paginator->sortKey('Article', array('sort' => 'Article'));
427
		$this->assertEquals('Article', $result);
428
	}
429
 
430
/**
431
 * Test that sortKey falls back to the default sorting options set
432
 * in the $params which are the default pagination options.
433
 *
434
 * @return void
435
 */
436
	public function testSortKeyFallbackToParams() {
437
		$this->Paginator->request->params['paging']['Article']['order'] = 'Article.body';
438
		$result = $this->Paginator->sortKey();
439
		$this->assertEquals('Article.body', $result);
440
 
441
		$result = $this->Paginator->sortKey('Article');
442
		$this->assertEquals('Article.body', $result);
443
 
444
		$this->Paginator->request->params['paging']['Article']['order'] = array(
445
			'Article.body' => 'DESC'
446
		);
447
		$result = $this->Paginator->sortKey();
448
		$this->assertEquals('Article.body', $result);
449
 
450
		$result = $this->Paginator->sortKey('Article');
451
		$this->assertEquals('Article.body', $result);
452
	}
453
 
454
/**
455
 * testSortDir method
456
 *
457
 * @return void
458
 */
459
	public function testSortDir() {
460
		$result = $this->Paginator->sortDir();
461
		$expected = 'asc';
462
 
463
		$this->assertEquals($expected, $result);
464
 
465
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
466
		$result = $this->Paginator->sortDir();
467
		$expected = 'desc';
468
 
469
		$this->assertEquals($expected, $result);
470
 
471
		unset($this->Paginator->request->params['paging']['Article']['options']);
472
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
473
		$result = $this->Paginator->sortDir();
474
		$expected = 'asc';
475
 
476
		$this->assertEquals($expected, $result);
477
 
478
		unset($this->Paginator->request->params['paging']['Article']['options']);
479
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('title' => 'desc');
480
		$result = $this->Paginator->sortDir();
481
		$expected = 'desc';
482
 
483
		$this->assertEquals($expected, $result);
484
 
485
		unset($this->Paginator->request->params['paging']['Article']['options']);
486
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('title' => 'asc');
487
		$result = $this->Paginator->sortDir();
488
		$expected = 'asc';
489
 
490
		$this->assertEquals($expected, $result);
491
 
492
		unset($this->Paginator->request->params['paging']['Article']['options']);
493
		$this->Paginator->request->params['paging']['Article']['options']['direction'] = 'asc';
494
		$result = $this->Paginator->sortDir();
495
		$expected = 'asc';
496
 
497
		$this->assertEquals($expected, $result);
498
 
499
		unset($this->Paginator->request->params['paging']['Article']['options']);
500
		$this->Paginator->request->params['paging']['Article']['options']['direction'] = 'desc';
501
		$result = $this->Paginator->sortDir();
502
		$expected = 'desc';
503
 
504
		$this->assertEquals($expected, $result);
505
 
506
		unset($this->Paginator->request->params['paging']['Article']['options']);
507
		$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
508
		$expected = 'asc';
509
 
510
		$this->assertEquals($expected, $result);
511
 
512
		$result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
513
		$expected = 'desc';
514
 
515
		$this->assertEquals($expected, $result);
516
 
517
		$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
518
		$expected = 'asc';
519
 
520
		$this->assertEquals($expected, $result);
521
	}
522
 
523
/**
524
 * Test that sortDir falls back to the default sorting options set
525
 * in the $params which are the default pagination options.
526
 *
527
 * @return void
528
 */
529
	public function testSortDirFallbackToParams() {
530
		$this->Paginator->request->params['paging']['Article']['order'] = array(
531
			'Article.body' => 'ASC'
532
		);
533
		$result = $this->Paginator->sortDir();
534
		$this->assertEquals('asc', $result);
535
 
536
		$result = $this->Paginator->sortDir('Article');
537
		$this->assertEquals('asc', $result);
538
 
539
		$this->Paginator->request->params['paging']['Article']['order'] = array(
540
			'Article.body' => 'DESC'
541
		);
542
		$result = $this->Paginator->sortDir();
543
		$this->assertEquals('desc', $result);
544
 
545
		$result = $this->Paginator->sortDir('Article');
546
		$this->assertEquals('desc', $result);
547
	}
548
 
549
/**
550
 * testSortAdminLinks method
551
 *
552
 * @return void
553
 */
554
	public function testSortAdminLinks() {
555
		Configure::write('Routing.prefixes', array('admin'));
556
 
557
		Router::reload();
558
		Router::setRequestInfo(array(
559
			array('pass' => array(), 'named' => array(), 'controller' => 'users', 'plugin' => null, 'action' => 'admin_index', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/users')),
560
			array('base' => '', 'here' => '/admin/users', 'webroot' => '/')
561
		));
562
		Router::parse('/admin/users');
563
		$this->Paginator->request->params['paging']['Article']['page'] = 1;
564
		$result = $this->Paginator->next('Next');
565
		$expected = array(
566
			'span' => array('class' => 'next'),
567
			'a' => array('href' => '/admin/users/index/page:2', 'rel' => 'next'),
568
			'Next',
569
			'/a',
570
			'/span'
571
		);
572
		$this->assertTags($result, $expected);
573
 
574
		Router::reload();
575
		Router::setRequestInfo(array(
576
			array('plugin' => null, 'controller' => 'test', 'action' => 'admin_index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/test')),
577
			array('base' => '', 'here' => '/admin/test', 'webroot' => '/')
578
		));
579
		Router::parse('/');
580
		$this->Paginator->options(array('url' => array('param')));
581
		$result = $this->Paginator->sort('title');
582
		$expected = array(
583
			'a' => array('href' => '/admin/test/index/param/sort:title/direction:asc'),
584
			'Title',
585
			'/a'
586
		);
587
		$this->assertTags($result, $expected);
588
 
589
		$this->Paginator->options(array('url' => array('param')));
590
		$result = $this->Paginator->sort('Article.title', 'Title');
591
		$expected = array(
592
			'a' => array('href' => '/admin/test/index/param/sort:Article.title/direction:asc'),
593
			'Title',
594
			'/a'
595
		);
596
		$this->assertTags($result, $expected);
597
	}
598
 
599
/**
600
 * testUrlGeneration method
601
 *
602
 * @return void
603
 */
604
	public function testUrlGeneration() {
605
		$result = $this->Paginator->sort('controller');
606
		$expected = array(
607
			'a' => array('href' => '/index/sort:controller/direction:asc'),
608
			'Controller',
609
			'/a'
610
		);
611
		$this->assertTags($result, $expected);
612
 
613
		$result = $this->Paginator->url();
614
		$this->assertEquals('/', $result);
615
 
616
		$this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
617
		$result = $this->Paginator->url();
618
		$this->assertEquals('/index/page:2', $result);
619
 
620
		$options = array('order' => array('Article' => 'desc'));
621
		$result = $this->Paginator->url($options);
622
		$this->assertEquals('/index/page:2/sort:Article/direction:desc', $result);
623
 
624
		$this->Paginator->request->params['paging']['Article']['options']['page'] = 3;
625
		$options = array('order' => array('Article.name' => 'desc'));
626
		$result = $this->Paginator->url($options);
627
		$this->assertEquals('/index/page:3/sort:Article.name/direction:desc', $result);
628
	}
629
 
630
/**
631
 * test URL generation with prefix routes
632
 *
633
 * @return void
634
 */
635
	public function testUrlGenerationWithPrefixes() {
636
		Configure::write('Routing.prefixes', array('members'));
637
		Router::reload();
638
 
639
		Router::parse('/');
640
 
641
		Router::setRequestInfo(array(
642
			array('controller' => 'posts', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null),
643
			array('base' => '', 'here' => 'posts/index', 'webroot' => '/')
644
		));
645
 
646
		$this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
647
		$this->Paginator->request->params['paging']['Article']['page'] = 2;
648
		$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
649
		$options = array('members' => true);
650
 
651
		$result = $this->Paginator->url($options);
652
		$expected = '/members/posts/index/page:2';
653
		$this->assertEquals($expected, $result);
654
 
655
		$result = $this->Paginator->sort('name', null, array('url' => $options));
656
		$expected = array(
657
			'a' => array('href' => '/members/posts/index/page:2/sort:name/direction:asc'),
658
			'Name',
659
			'/a'
660
		);
661
		$this->assertTags($result, $expected);
662
 
663
		$result = $this->Paginator->next('next', array('url' => $options));
664
		$expected = array(
665
			'span' => array('class' => 'next'),
666
			'a' => array('href' => '/members/posts/index/page:3', 'rel' => 'next'),
667
			'next',
668
			'/a',
669
			'/span'
670
		);
671
		$this->assertTags($result, $expected);
672
 
673
		$result = $this->Paginator->prev('prev', array('url' => $options));
674
		$expected = array(
675
			'span' => array('class' => 'prev'),
676
			'a' => array('href' => '/members/posts', 'rel' => 'prev'),
677
			'prev',
678
			'/a',
679
			'/span'
680
		);
681
		$this->assertTags($result, $expected);
682
 
683
		$options = array('members' => true, 'controller' => 'posts', 'order' => array('name' => 'desc'));
684
		$result = $this->Paginator->url($options);
685
		$expected = '/members/posts/index/page:2/sort:name/direction:desc';
686
		$this->assertEquals($expected, $result);
687
 
688
		$options = array('controller' => 'posts', 'order' => array('Article.name' => 'desc'));
689
		$result = $this->Paginator->url($options);
690
		$expected = '/posts/index/page:2/sort:Article.name/direction:desc';
691
		$this->assertEquals($expected, $result);
692
	}
693
 
694
/**
695
 * testOptions method
696
 *
697
 * @return void
698
 */
699
	public function testOptions() {
700
		$this->Paginator->options('myDiv');
701
		$this->assertEquals('myDiv', $this->Paginator->options['update']);
702
 
703
		$this->Paginator->options = array();
704
		$this->Paginator->request->params = array();
705
 
706
		$options = array('paging' => array('Article' => array(
707
			'order' => 'desc',
708
			'sort' => 'title'
709
		)));
710
		$this->Paginator->options($options);
711
 
712
		$expected = array('Article' => array(
713
			'order' => 'desc',
714
			'sort' => 'title'
715
		));
716
		$this->assertEquals($expected, $this->Paginator->request->params['paging']);
717
 
718
		$this->Paginator->options = array();
719
		$this->Paginator->request->params = array();
720
 
721
		$options = array('Article' => array(
722
			'order' => 'desc',
723
			'sort' => 'title'
724
		));
725
		$this->Paginator->options($options);
726
		$this->assertEquals($expected, $this->Paginator->request->params['paging']);
727
 
728
		$options = array('paging' => array('Article' => array(
729
			'order' => 'desc',
730
			'sort' => 'Article.title'
731
		)));
732
		$this->Paginator->options($options);
733
 
734
		$expected = array('Article' => array(
735
			'order' => 'desc',
736
			'sort' => 'Article.title'
737
		));
738
		$this->assertEquals($expected, $this->Paginator->request->params['paging']);
739
	}
740
 
741
/**
742
 * testPassedArgsMergingWithUrlOptions method
743
 *
744
 * @return void
745
 */
746
	public function testPassedArgsMergingWithUrlOptions() {
747
		Router::reload();
748
		Router::parse('/');
749
		Router::setRequestInfo(array(
750
			array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'url' => array('url' => 'articles/index/2/foo:bar')),
751
			array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
752
		));
753
		$this->Paginator->request->params['paging'] = array(
754
			'Article' => array(
755
				'page' => 1, 'current' => 3, 'count' => 13,
756
				'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
757
				'options' => array(
758
					'page' => 1,
759
					'order' => array(),
760
					'conditions' => array()
761
				),
762
				'paramType' => 'named'
763
			)
764
		);
765
 
766
		$this->Paginator->request->params['pass'] = array(2);
767
		$this->Paginator->request->params['named'] = array('foo' => 'bar');
768
		$this->Paginator->request->query = array('x' => 'y');
769
		$this->Paginator->beforeRender('posts/index');
770
 
771
		$result = $this->Paginator->sort('title');
772
		$expected = array(
773
			'a' => array('href' => '/articles/index/2/foo:bar/sort:title/direction:asc?x=y'),
774
			'Title',
775
			'/a'
776
		);
777
		$this->assertTags($result, $expected);
778
 
779
		$result = $this->Paginator->numbers();
780
		$expected = array(
781
			array('span' => array('class' => 'current')), '1', '/span',
782
			' | ',
783
			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:2/foo:bar?x=y')), '2', '/a', '/span',
784
			' | ',
785
			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:3/foo:bar?x=y')), '3', '/a', '/span',
786
			' | ',
787
			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:4/foo:bar?x=y')), '4', '/a', '/span',
788
			' | ',
789
			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:5/foo:bar?x=y')), '5', '/a', '/span',
790
			' | ',
791
			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:6/foo:bar?x=y')), '6', '/a', '/span',
792
			' | ',
793
			array('span' => array()), array('a' => array('href' => '/articles/index/2/page:7/foo:bar?x=y')), '7', '/a', '/span',
794
		);
795
		$this->assertTags($result, $expected);
796
 
797
		$result = $this->Paginator->next('Next');
798
		$expected = array(
799
			'span' => array('class' => 'next'),
800
			'a' => array('href' => '/articles/index/2/page:2/foo:bar?x=y', 'rel' => 'next'),
801
			'Next',
802
			'/a',
803
			'/span'
804
		);
805
		$this->assertTags($result, $expected);
806
	}
807
 
808
/**
809
 * testPassedArgsMergingWithUrlOptionsParamTypeQuerystring method
810
 *
811
 * @return void
812
 */
813
	public function testPassedArgsMergingWithUrlOptionsParamTypeQuerystring() {
814
		Router::reload();
815
		Router::parse('/');
816
		Router::setRequestInfo(array(
817
			array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'url' => array('url' => 'articles/index/2/foo:bar')),
818
			array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
819
		));
820
		$this->Paginator->request->params['paging'] = array(
821
			'Article' => array(
822
				'page' => 1, 'current' => 3, 'count' => 13,
823
				'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
824
				'options' => array(
825
					'page' => 1,
826
					'order' => array(),
827
					'conditions' => array()
828
				),
829
				'paramType' => 'querystring'
830
			)
831
		);
832
 
833
		$this->Paginator->request->params['pass'] = array(2);
834
		$this->Paginator->request->params['named'] = array('foo' => 'bar');
835
		$this->Paginator->request->query = array('x' => 'y');
836
		$this->Paginator->beforeRender('posts/index');
837
 
838
		$result = $this->Paginator->sort('title');
839
		$expected = array(
840
			'a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;sort=title&amp;direction=asc'),
841
			'Title',
842
			'/a'
843
		);
844
		$this->assertTags($result, $expected);
845
 
846
		$result = $this->Paginator->numbers();
847
		$expected = array(
848
			array('span' => array('class' => 'current')), '1', '/span',
849
			' | ',
850
			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=2')), '2', '/a', '/span',
851
			' | ',
852
			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=3')), '3', '/a', '/span',
853
			' | ',
854
			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=4')), '4', '/a', '/span',
855
			' | ',
856
			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=5')), '5', '/a', '/span',
857
			' | ',
858
			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=6')), '6', '/a', '/span',
859
			' | ',
860
			array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=7')), '7', '/a', '/span',
861
		);
862
		$this->assertTags($result, $expected);
863
 
864
		$result = $this->Paginator->next('Next');
865
		$expected = array(
866
			'span' => array('class' => 'next'),
867
			'a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=2', 'rel' => 'next'),
868
			'Next',
869
			'/a',
870
			'/span'
871
		);
872
		$this->assertTags($result, $expected);
873
	}
874
 
875
/**
876
 * testPagingLinks method
877
 *
878
 * @return void
879
 */
880
	public function testPagingLinks() {
881
		$this->Paginator->request->params['paging'] = array(
882
			'Client' => array(
883
				'page' => 1,
884
				'current' => 3,
885
				'count' => 13,
886
				'prevPage' => false,
887
				'nextPage' => true,
888
				'pageCount' => 5,
889
				'options' => array(
890
					'page' => 1,
891
				),
892
				'paramType' => 'named'
893
			)
894
		);
895
		$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
896
		$expected = array(
897
			'span' => array('class' => 'disabled'),
898
			'&lt;&lt; Previous',
899
			'/span'
900
		);
901
		$this->assertTags($result, $expected);
902
 
903
		$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'div'));
904
		$expected = array(
905
			'div' => array('class' => 'disabled'),
906
			'&lt;&lt; Previous',
907
			'/div'
908
		);
909
		$this->assertTags($result, $expected);
910
 
911
		$this->Paginator->request->params['paging']['Client']['page'] = 2;
912
		$this->Paginator->request->params['paging']['Client']['prevPage'] = true;
913
		$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
914
		$expected = array(
915
			'span' => array('class' => 'prev'),
916
			'a' => array('href' => '/', 'rel' => 'prev'),
917
			'&lt;&lt; Previous',
918
			'/a',
919
			'/span'
920
		);
921
		$this->assertTags($result, $expected);
922
 
923
		$result = $this->Paginator->prev('<< Previous', array('tag' => false), null, array('class' => 'disabled'));
924
		$expected = array(
925
			'a' => array('href' => '/', 'rel' => 'prev', 'class' => 'prev'),
926
			'&lt;&lt; Previous',
927
			'/a'
928
		);
929
		$this->assertTags($result, $expected);
930
 
931
		$result = $this->Paginator->prev(
932
			'<< Previous',
933
			array(),
934
			null,
935
			array('disabledTag' => 'span', 'class' => 'disabled')
936
		);
937
		$expected = array(
938
			'span' => array('class' => 'prev'),
939
			'a' => array('href' => '/', 'rel' => 'prev'),
940
			'&lt;&lt; Previous',
941
			'/a',
942
			'/span'
943
		);
944
		$this->assertTags($result, $expected);
945
 
946
		$result = $this->Paginator->next('Next');
947
		$expected = array(
948
			'span' => array('class' => 'next'),
949
			'a' => array('href' => '/index/page:3', 'rel' => 'next'),
950
			'Next',
951
			'/a',
952
			'/span'
953
		);
954
		$this->assertTags($result, $expected);
955
 
956
		$result = $this->Paginator->next('Next', array('tag' => 'li'));
957
		$expected = array(
958
			'li' => array('class' => 'next'),
959
			'a' => array('href' => '/index/page:3', 'rel' => 'next'),
960
			'Next',
961
			'/a',
962
			'/li'
963
		);
964
		$this->assertTags($result, $expected);
965
 
966
		$result = $this->Paginator->next('Next', array('tag' => false));
967
		$expected = array(
968
			'a' => array('href' => '/index/page:3', 'rel' => 'next', 'class' => 'next'),
969
			'Next',
970
			'/a'
971
		);
972
		$this->assertTags($result, $expected);
973
 
974
		$result = $this->Paginator->prev('<< Previous', array('escape' => true));
975
		$expected = array(
976
			'span' => array('class' => 'prev'),
977
			'a' => array('href' => '/', 'rel' => 'prev'),
978
			'&lt;&lt; Previous',
979
			'/a',
980
			'/span'
981
		);
982
		$this->assertTags($result, $expected);
983
 
984
		$result = $this->Paginator->prev('<< Previous', array('escape' => false));
985
		$expected = array(
986
			'span' => array('class' => 'prev'),
987
			'a' => array('href' => '/', 'rel' => 'prev'),
988
			'preg:/<< Previous/',
989
			'/a',
990
			'/span'
991
		);
992
		$this->assertTags($result, $expected);
993
 
994
		$this->Paginator->request->params['paging'] = array(
995
			'Client' => array(
996
				'page' => 1,
997
				'current' => 1,
998
				'count' => 13,
999
				'prevPage' => false,
1000
				'nextPage' => true,
1001
				'pageCount' => 5,
1002
				'options' => array(
1003
					'page' => 1,
1004
				),
1005
				'paramType' => 'named'
1006
			)
1007
		);
1008
 
1009
		$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>');
1010
		$expected = array(
1011
			'span' => array('class' => 'prev'),
1012
			'&lt;strong&gt;Disabled&lt;/strong&gt;',
1013
			'/span'
1014
		);
1015
		$this->assertTags($result, $expected);
1016
 
1017
		$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => true));
1018
		$expected = array(
1019
			'span' => array('class' => 'prev'),
1020
			'&lt;strong&gt;Disabled&lt;/strong&gt;',
1021
			'/span'
1022
		);
1023
		$this->assertTags($result, $expected);
1024
 
1025
		$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => false));
1026
		$expected = array(
1027
			'span' => array('class' => 'prev'),
1028
			'<strong', 'Disabled', '/strong',
1029
			'/span'
1030
		);
1031
		$this->assertTags($result, $expected);
1032
 
1033
		$result = $this->Paginator->prev('<< Previous', array('tag' => false), '<strong>Disabled</strong>');
1034
		$expected = array(
1035
			'span' => array('class' => 'prev'),
1036
			'&lt;strong&gt;Disabled&lt;/strong&gt;',
1037
			'/span'
1038
		);
1039
		$this->assertTags($result, $expected);
1040
 
1041
		$result = $this->Paginator->prev(
1042
			'<< Previous',
1043
			array('tag' => 'li'),
1044
			null,
1045
			array('tag' => 'li', 'disabledTag' => 'span', 'class' => 'disabled')
1046
		);
1047
		$expected = array(
1048
			'li' => array('class' => 'disabled'),
1049
			'span' => array(),
1050
			'&lt;&lt; Previous',
1051
			'/span',
1052
			'/li'
1053
		);
1054
		$this->assertTags($result, $expected);
1055
		$result = $this->Paginator->prev(
1056
			'<< Previous',
1057
			array(),
1058
			null,
1059
			array('tag' => false, 'disabledTag' => 'span', 'class' => 'disabled')
1060
		);
1061
		$expected = array(
1062
			'span' => array('class' => 'disabled'),
1063
			'&lt;&lt; Previous',
1064
			'/span',
1065
		);
1066
		$this->assertTags($result, $expected);
1067
 
1068
		$this->Paginator->request->params['paging'] = array(
1069
			'Client' => array(
1070
				'page' => 1,
1071
				'current' => 3,
1072
				'count' => 13,
1073
				'prevPage' => false,
1074
				'nextPage' => true,
1075
				'pageCount' => 5,
1076
				'options' => array(
1077
					'page' => 1,
1078
					'limit' => 3,
1079
					'order' => array('Client.name' => 'DESC'),
1080
				),
1081
				'paramType' => 'named'
1082
			)
1083
		);
1084
 
1085
		$this->Paginator->request->params['paging']['Client']['page'] = 2;
1086
		$this->Paginator->request->params['paging']['Client']['prevPage'] = true;
1087
		$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
1088
		$expected = array(
1089
			'span' => array('class' => 'prev'),
1090
			'a' => array(
1091
				'href' => '/index/limit:3/sort:Client.name/direction:DESC',
1092
				'rel' => 'prev'
1093
			),
1094
			'&lt;&lt; Previous',
1095
			'/a',
1096
			'/span'
1097
		);
1098
		$this->assertTags($result, $expected);
1099
 
1100
		$result = $this->Paginator->next('Next');
1101
		$expected = array(
1102
			'span' => array('class' => 'next'),
1103
			'a' => array(
1104
				'href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC',
1105
				'rel' => 'next'
1106
			),
1107
			'Next',
1108
			'/a',
1109
			'/span'
1110
		);
1111
		$this->assertTags($result, $expected);
1112
 
1113
		$this->Paginator->request->params['paging'] = array(
1114
			'Client' => array(
1115
				'page' => 2,
1116
				'current' => 1,
1117
				'count' => 13,
1118
				'prevPage' => true,
1119
				'nextPage' => false,
1120
				'pageCount' => 2,
1121
				'options' => array(
1122
					'page' => 2,
1123
					'limit' => 10,
1124
					'order' => array(),
1125
					'conditions' => array()
1126
				),
1127
				'paramType' => 'named'
1128
			)
1129
		);
1130
		$result = $this->Paginator->prev('Prev');
1131
		$expected = array(
1132
			'span' => array('class' => 'prev'),
1133
			'a' => array('href' => '/index/limit:10', 'rel' => 'prev'),
1134
			'Prev',
1135
			'/a',
1136
			'/span'
1137
		);
1138
		$this->assertTags($result, $expected);
1139
 
1140
		$result = $this->Paginator->next('Next', array(), null, array('tag' => false));
1141
		$expected = array(
1142
			'span' => array('class' => 'next'),
1143
			'Next',
1144
			'/span'
1145
		);
1146
		$this->assertTags($result, $expected);
1147
 
1148
		$this->Paginator->request->params['paging'] = array(
1149
			'Client' => array(
1150
				'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
1151
				'nextPage' => false, 'pageCount' => 2,
1152
				'defaults' => array(),
1153
				'options' => array(
1154
					'page' => 2, 'limit' => 10, 'order' => array(), 'conditions' => array()
1155
				),
1156
				'paramType' => 'named'
1157
			)
1158
		);
1159
		$this->Paginator->options(array('url' => array(12, 'page' => 3)));
1160
		$result = $this->Paginator->prev('Prev', array('url' => array('foo' => 'bar')));
1161
		$expected = array(
1162
			'span' => array('class' => 'prev'),
1163
			'a' => array('href' => '/index/12/limit:10/foo:bar', 'rel' => 'prev'),
1164
			'Prev',
1165
			'/a',
1166
			'/span'
1167
		);
1168
		$this->assertTags($result, $expected);
1169
	}
1170
 
1171
/**
1172
 * test that __pagingLink methods use $options when $disabledOptions is an empty value.
1173
 * allowing you to use shortcut syntax
1174
 *
1175
 * @return void
1176
 */
1177
	public function testPagingLinksOptionsReplaceEmptyDisabledOptions() {
1178
		$this->Paginator->request->params['paging'] = array(
1179
			'Client' => array(
1180
				'page' => 1,
1181
				'current' => 3,
1182
				'count' => 13,
1183
				'prevPage' => false,
1184
				'nextPage' => true,
1185
				'pageCount' => 5,
1186
				'options' => array(
1187
					'page' => 1,
1188
				),
1189
				'paramType' => 'named'
1190
			)
1191
		);
1192
		$result = $this->Paginator->prev('<< Previous', array('escape' => false));
1193
		$expected = array(
1194
			'span' => array('class' => 'prev'),
1195
			'preg:/<< Previous/',
1196
			'/span'
1197
		);
1198
		$this->assertTags($result, $expected);
1199
 
1200
		$result = $this->Paginator->next('Next >>', array('escape' => false));
1201
		$expected = array(
1202
			'span' => array('class' => 'next'),
1203
			'a' => array('href' => '/index/page:2', 'rel' => 'next'),
1204
			'preg:/Next >>/',
1205
			'/a',
1206
			'/span'
1207
		);
1208
		$this->assertTags($result, $expected);
1209
	}
1210
 
1211
/**
1212
 * testPagingLinksNotDefaultModel
1213
 *
1214
 * Test the creation of paging links when the non default model is used.
1215
 *
1216
 * @return void
1217
 */
1218
	public function testPagingLinksNotDefaultModel() {
1219
		// Multiple Model Paginate
1220
		$this->Paginator->request->params['paging'] = array(
1221
			'Client' => array(
1222
				'page' => 1,
1223
				'current' => 3,
1224
				'count' => 13,
1225
				'prevPage' => false,
1226
				'nextPage' => true,
1227
				'pageCount' => 5,
1228
				'options' => array(
1229
					'page' => 1,
1230
				),
1231
				'paramType' => 'named'
1232
			),
1233
			'Server' => array(
1234
				'page' => 1,
1235
				'current' => 1,
1236
				'count' => 5,
1237
				'prevPage' => false,
1238
				'nextPage' => false,
1239
				'pageCount' => 5,
1240
				'options' => array(
1241
					'page' => 1,
1242
				),
1243
				'paramType' => 'named'
1244
			)
1245
		);
1246
		$result = $this->Paginator->next('Next', array('model' => 'Client'));
1247
		$expected = array(
1248
			'span' => array('class' => 'next'),
1249
			'a' => array('href' => '/index/page:2', 'rel' => 'next'),
1250
			'Next',
1251
			'/a',
1252
			'/span'
1253
		);
1254
		$this->assertTags($result, $expected);
1255
 
1256
		$result = $this->Paginator->next('Next', array('model' => 'Server'), 'No Next', array('model' => 'Server'));
1257
		$expected = array(
1258
			'span' => array('class' => 'next'), 'No Next', '/span'
1259
		);
1260
		$this->assertTags($result, $expected);
1261
	}
1262
 
1263
/**
1264
 * testGenericLinks method
1265
 *
1266
 * @return void
1267
 */
1268
	public function testGenericLinks() {
1269
		$result = $this->Paginator->link('Sort by title on page 5', array('sort' => 'title', 'page' => 5, 'direction' => 'desc'));
1270
		$expected = array(
1271
			'a' => array('href' => '/index/page:5/sort:title/direction:desc'),
1272
			'Sort by title on page 5',
1273
			'/a'
1274
		);
1275
		$this->assertTags($result, $expected);
1276
 
1277
		$this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
1278
		$result = $this->Paginator->link('Sort by title', array('sort' => 'title', 'direction' => 'desc'));
1279
		$expected = array(
1280
			'a' => array('href' => '/index/page:2/sort:title/direction:desc'),
1281
			'Sort by title',
1282
			'/a'
1283
		);
1284
		$this->assertTags($result, $expected);
1285
 
1286
		$this->Paginator->request->params['paging']['Article']['options']['page'] = 4;
1287
		$result = $this->Paginator->link('Sort by title on page 4', array('sort' => 'Article.title', 'direction' => 'desc'));
1288
		$expected = array(
1289
			'a' => array('href' => '/index/page:4/sort:Article.title/direction:desc'),
1290
			'Sort by title on page 4',
1291
			'/a'
1292
		);
1293
		$this->assertTags($result, $expected);
1294
	}
1295
 
1296
/**
1297
 * Tests generation of generic links with preset options
1298
 *
1299
 * @return void
1300
 */
1301
	public function testGenericLinksWithPresetOptions() {
1302
		$result = $this->Paginator->link('Foo!', array('page' => 1));
1303
		$this->assertTags($result, array('a' => array('href' => '/'), 'Foo!', '/a'));
1304
 
1305
		$this->Paginator->options(array('sort' => 'title', 'direction' => 'desc'));
1306
		$result = $this->Paginator->link('Foo!', array('page' => 1));
1307
		$this->assertTags($result, array(
1308
			'a' => array(
1309
				'href' => '/',
1310
				'sort' => 'title',
1311
				'direction' => 'desc'
1312
			),
1313
			'Foo!',
1314
			'/a'
1315
		));
1316
 
1317
		$this->Paginator->options(array('sort' => null, 'direction' => null));
1318
		$result = $this->Paginator->link('Foo!', array('page' => 1));
1319
		$this->assertTags($result, array('a' => array('href' => '/'), 'Foo!', '/a'));
1320
 
1321
		$this->Paginator->options(array('url' => array(
1322
			'sort' => 'title',
1323
			'direction' => 'desc'
1324
		)));
1325
		$result = $this->Paginator->link('Foo!', array('page' => 1));
1326
		$this->assertTags($result, array(
1327
			'a' => array('href' => '/index/sort:title/direction:desc'),
1328
			'Foo!',
1329
			'/a'
1330
		));
1331
	}
1332
 
1333
/**
1334
 * testNumbers method
1335
 *
1336
 * @return void
1337
 */
1338
	public function testNumbers() {
1339
		$this->Paginator->request->params['paging'] = array(
1340
			'Client' => array(
1341
				'page' => 8,
1342
				'current' => 3,
1343
				'count' => 30,
1344
				'prevPage' => false,
1345
				'nextPage' => 2,
1346
				'pageCount' => 15,
1347
				'options' => array(
1348
					'page' => 1,
1349
				),
1350
				'paramType' => 'named'
1351
			)
1352
		);
1353
		$result = $this->Paginator->numbers();
1354
		$expected = array(
1355
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1356
			' | ',
1357
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1358
			' | ',
1359
			array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1360
			' | ',
1361
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1362
			' | ',
1363
			array('span' => array('class' => 'current')), '8', '/span',
1364
			' | ',
1365
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1366
			' | ',
1367
			array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1368
			' | ',
1369
			array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1370
			' | ',
1371
			array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1372
		);
1373
		$this->assertTags($result, $expected);
1374
 
1375
		$result = $this->Paginator->numbers(array('tag' => 'li'));
1376
		$expected = array(
1377
			array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
1378
			' | ',
1379
			array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
1380
			' | ',
1381
			array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
1382
			' | ',
1383
			array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
1384
			' | ',
1385
			array('li' => array('class' => 'current')), '8', '/li',
1386
			' | ',
1387
			array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
1388
			' | ',
1389
			array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li',
1390
			' | ',
1391
			array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li',
1392
			' | ',
1393
			array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li',
1394
		);
1395
		$this->assertTags($result, $expected);
1396
 
1397
		$result = $this->Paginator->numbers(array('tag' => 'li', 'separator' => false));
1398
		$expected = array(
1399
			array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
1400
			array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
1401
			array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
1402
			array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
1403
			array('li' => array('class' => 'current')), '8', '/li',
1404
			array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
1405
			array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li',
1406
			array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li',
1407
			array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li',
1408
		);
1409
		$this->assertTags($result, $expected);
1410
 
1411
		$result = $this->Paginator->numbers(true);
1412
		$expected = array(
1413
			array('span' => array()), array('a' => array('href' => '/', 'rel' => 'first')), 'first', '/a', '/span',
1414
			' | ',
1415
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1416
			' | ',
1417
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1418
			' | ',
1419
			array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1420
			' | ',
1421
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1422
			' | ',
1423
			array('span' => array('class' => 'current')), '8', '/span',
1424
			' | ',
1425
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1426
			' | ',
1427
			array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1428
			' | ',
1429
			array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1430
			' | ',
1431
			array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1432
			' | ',
1433
			array('span' => array()), array('a' => array('href' => '/index/page:15', 'rel' => 'last')), 'last', '/a', '/span',
1434
		);
1435
		$this->assertTags($result, $expected);
1436
 
1437
		$this->Paginator->request->params['paging'] = array(
1438
			'Client' => array(
1439
				'page' => 1,
1440
				'current' => 3,
1441
				'count' => 30,
1442
				'prevPage' => false,
1443
				'nextPage' => 2,
1444
				'pageCount' => 15,
1445
				'options' => array(
1446
					'page' => 1,
1447
				),
1448
				'paramType' => 'named'
1449
			)
1450
		);
1451
		$result = $this->Paginator->numbers();
1452
		$expected = array(
1453
			array('span' => array('class' => 'current')), '1', '/span',
1454
			' | ',
1455
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1456
			' | ',
1457
			array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1458
			' | ',
1459
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1460
			' | ',
1461
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1462
			' | ',
1463
			array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1464
			' | ',
1465
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1466
			' | ',
1467
			array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1468
			' | ',
1469
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1470
		);
1471
		$this->assertTags($result, $expected);
1472
 
1473
		$this->Paginator->request->params['paging'] = array(
1474
			'Client' => array(
1475
				'page' => 14,
1476
				'current' => 3,
1477
				'count' => 30,
1478
				'prevPage' => false,
1479
				'nextPage' => 2,
1480
				'pageCount' => 15,
1481
				'options' => array(
1482
					'page' => 1,
1483
				),
1484
				'paramType' => 'named'
1485
			)
1486
		);
1487
		$result = $this->Paginator->numbers();
1488
		$expected = array(
1489
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1490
			' | ',
1491
			array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1492
			' | ',
1493
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1494
			' | ',
1495
			array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1496
			' | ',
1497
			array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1498
			' | ',
1499
			array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1500
			' | ',
1501
			array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
1502
			' | ',
1503
			array('span' => array('class' => 'current')), '14', '/span',
1504
			' | ',
1505
			array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span',
1506
		);
1507
		$this->assertTags($result, $expected);
1508
 
1509
		$this->Paginator->request->params['paging'] = array(
1510
			'Client' => array(
1511
				'page' => 2,
1512
				'current' => 3,
1513
				'count' => 27,
1514
				'prevPage' => false,
1515
				'nextPage' => 2,
1516
				'pageCount' => 9,
1517
				'options' => array(
1518
					'page' => 1,
1519
				),
1520
				'paramType' => 'named'
1521
			)
1522
		);
1523
 
1524
		$result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link'));
1525
		$expected = array(
1526
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/')), '1', '/a', '/span',
1527
			' | ',
1528
			array('span' => array('class' => 'current page-link')), '2', '/span',
1529
			' | ',
1530
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1531
			' | ',
1532
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1533
			' | ',
1534
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1535
			' | ',
1536
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1537
			' | ',
1538
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1539
			' | ',
1540
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1541
			' | ',
1542
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1543
		);
1544
		$this->assertTags($result, $expected);
1545
 
1546
		$result = $this->Paginator->numbers(array('first' => 1, 'currentClass' => 'active'));
1547
		$expected = array(
1548
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1549
			' | ',
1550
			array('span' => array('class' => 'active')), '2', '/span',
1551
			' | ',
1552
			array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1553
			' | ',
1554
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1555
			' | ',
1556
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1557
			' | ',
1558
			array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1559
			' | ',
1560
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1561
			' | ',
1562
			array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1563
			' | ',
1564
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1565
		);
1566
		$this->assertTags($result, $expected);
1567
 
1568
		$result = $this->Paginator->numbers(array('first' => 1, 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'a'));
1569
		$expected = array(
1570
			array('li' => array()), array('a' => array('href' => '/')), '1', '/a', '/li',
1571
			' | ',
1572
			array('li' => array('class' => 'active')), array('a' => array()), '2', '/a', '/li',
1573
			' | ',
1574
			array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li',
1575
			' | ',
1576
			array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
1577
			' | ',
1578
			array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
1579
			' | ',
1580
			array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
1581
			' | ',
1582
			array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
1583
			' | ',
1584
			array('li' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/li',
1585
			' | ',
1586
			array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
1587
		);
1588
		$this->assertTags($result, $expected);
1589
 
1590
		$result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link', 'currentClass' => 'active'));
1591
		$expected = array(
1592
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/')), '1', '/a', '/span',
1593
			' | ',
1594
			array('span' => array('class' => 'active page-link')), '2', '/span',
1595
			' | ',
1596
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1597
			' | ',
1598
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1599
			' | ',
1600
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1601
			' | ',
1602
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1603
			' | ',
1604
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1605
			' | ',
1606
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1607
			' | ',
1608
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1609
		);
1610
		$this->assertTags($result, $expected);
1611
 
1612
		$result = $this->Paginator->numbers(array('last' => 1));
1613
		$expected = array(
1614
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1615
			' | ',
1616
			array('span' => array('class' => 'current')), '2', '/span',
1617
			' | ',
1618
			array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1619
			' | ',
1620
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1621
			' | ',
1622
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1623
			' | ',
1624
			array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1625
			' | ',
1626
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1627
			' | ',
1628
			array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1629
			' | ',
1630
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1631
		);
1632
		$this->assertTags($result, $expected);
1633
 
1634
		$this->Paginator->request->params['paging'] = array(
1635
			'Client' => array(
1636
				'page' => 15,
1637
				'current' => 3,
1638
				'count' => 30,
1639
				'prevPage' => false,
1640
				'nextPage' => 2,
1641
				'pageCount' => 15,
1642
				'options' => array(
1643
					'page' => 1,
1644
				),
1645
				'paramType' => 'named'
1646
			)
1647
		);
1648
 
1649
		$result = $this->Paginator->numbers(array('first' => 1));
1650
		$expected = array(
1651
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1652
			'...',
1653
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1654
			' | ',
1655
			array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1656
			' | ',
1657
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1658
			' | ',
1659
			array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1660
			' | ',
1661
			array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1662
			' | ',
1663
			array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1664
			' | ',
1665
			array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
1666
			' | ',
1667
			array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span',
1668
			' | ',
1669
			array('span' => array('class' => 'current')), '15', '/span',
1670
 
1671
		);
1672
		$this->assertTags($result, $expected);
1673
 
1674
		$this->Paginator->request->params['paging'] = array(
1675
			'Client' => array(
1676
				'page' => 10,
1677
				'current' => 3,
1678
				'count' => 30,
1679
				'prevPage' => false,
1680
				'nextPage' => 2,
1681
				'pageCount' => 15,
1682
				'options' => array(
1683
					'page' => 1,
1684
				),
1685
				'paramType' => 'named'
1686
			)
1687
		);
1688
 
1689
		$result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
1690
		$expected = array(
1691
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1692
			'...',
1693
			array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1694
			' | ',
1695
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1696
			' | ',
1697
			array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1698
			' | ',
1699
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1700
			' | ',
1701
			array('span' => array('class' => 'current')), '10', '/span',
1702
			' | ',
1703
			array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
1704
			' | ',
1705
			array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
1706
			' | ',
1707
			array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
1708
			' | ',
1709
			array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span',
1710
			' | ',
1711
			array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span',
1712
		);
1713
		$this->assertTags($result, $expected);
1714
 
1715
		$this->Paginator->request->params['paging'] = array(
1716
			'Client' => array(
1717
				'page' => 6,
1718
				'current' => 15,
1719
				'count' => 623,
1720
				'prevPage' => 1,
1721
				'nextPage' => 1,
1722
				'pageCount' => 42,
1723
				'options' => array(
1724
					'page' => 6,
1725
				),
1726
				'paramType' => 'named'
1727
			)
1728
		);
1729
 
1730
		$result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
1731
		$expected = array(
1732
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1733
			' | ',
1734
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1735
			' | ',
1736
			array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1737
			' | ',
1738
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1739
			' | ',
1740
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1741
			' | ',
1742
			array('span' => array('class' => 'current')), '6', '/span',
1743
			' | ',
1744
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
1745
			' | ',
1746
			array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
1747
			' | ',
1748
			array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
1749
			' | ',
1750
			array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
1751
			'...',
1752
			array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span',
1753
		);
1754
		$this->assertTags($result, $expected);
1755
 
1756
		$this->Paginator->request->params['paging'] = array(
1757
			'Client' => array(
1758
				'page' => 37,
1759
				'current' => 15,
1760
				'count' => 623,
1761
				'prevPage' => 1,
1762
				'nextPage' => 1,
1763
				'pageCount' => 42,
1764
				'options' => array(
1765
					'page' => 37,
1766
				),
1767
				'paramType' => 'named'
1768
			)
1769
		);
1770
 
1771
		$result = $this->Paginator->numbers(array('first' => 1, 'last' => 1));
1772
		$expected = array(
1773
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1774
			'...',
1775
			array('span' => array()), array('a' => array('href' => '/index/page:33')), '33', '/a', '/span',
1776
			' | ',
1777
			array('span' => array()), array('a' => array('href' => '/index/page:34')), '34', '/a', '/span',
1778
			' | ',
1779
			array('span' => array()), array('a' => array('href' => '/index/page:35')), '35', '/a', '/span',
1780
			' | ',
1781
			array('span' => array()), array('a' => array('href' => '/index/page:36')), '36', '/a', '/span',
1782
			' | ',
1783
			array('span' => array('class' => 'current')), '37', '/span',
1784
			' | ',
1785
			array('span' => array()), array('a' => array('href' => '/index/page:38')), '38', '/a', '/span',
1786
			' | ',
1787
			array('span' => array()), array('a' => array('href' => '/index/page:39')), '39', '/a', '/span',
1788
			' | ',
1789
			array('span' => array()), array('a' => array('href' => '/index/page:40')), '40', '/a', '/span',
1790
			' | ',
1791
			array('span' => array()), array('a' => array('href' => '/index/page:41')), '41', '/a', '/span',
1792
			' | ',
1793
			array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span',
1794
		);
1795
		$this->assertTags($result, $expected);
1796
 
1797
		$this->Paginator->request->params['paging'] = array(
1798
			'Client' => array(
1799
				'page' => 1,
1800
				'current' => 10,
1801
				'count' => 30,
1802
				'prevPage' => false,
1803
				'nextPage' => 2,
1804
				'pageCount' => 3,
1805
				'options' => array(
1806
					'page' => 1,
1807
				),
1808
				'paramType' => 'named'
1809
			)
1810
		);
1811
		$options = array('modulus' => 10);
1812
		$result = $this->Paginator->numbers($options);
1813
		$expected = array(
1814
			array('span' => array('class' => 'current')), '1', '/span',
1815
			' | ',
1816
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1817
			' | ',
1818
			array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1819
		);
1820
		$this->assertTags($result, $expected);
1821
 
1822
		$result = $this->Paginator->numbers(array('modulus' => 3, 'currentTag' => 'span', 'tag' => 'li'));
1823
		$expected = array(
1824
			array('li' => array('class' => 'current')), array('span' => array()), '1', '/span', '/li',
1825
			' | ',
1826
			array('li' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/li',
1827
			' | ',
1828
			array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li',
1829
		);
1830
		$this->assertTags($result, $expected);
1831
 
1832
		$this->Paginator->request->params['paging'] = array(
1833
			'Client' => array(
1834
				'page' => 2,
1835
				'current' => 10,
1836
				'count' => 31,
1837
				'prevPage' => true,
1838
				'nextPage' => true,
1839
				'pageCount' => 4,
1840
				'options' => array(
1841
					'page' => 1,
1842
					'order' => array('Client.name' => 'DESC'),
1843
				),
1844
				'paramType' => 'named'
1845
			)
1846
		);
1847
		$result = $this->Paginator->numbers(array('class' => 'page-link'));
1848
		$expected = array(
1849
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/sort:Client.name/direction:DESC')), '1', '/a', '/span',
1850
			' | ',
1851
			array('span' => array('class' => 'current page-link')), '2', '/span',
1852
			' | ',
1853
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span',
1854
			' | ',
1855
			array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span',
1856
		);
1857
		$this->assertTags($result, $expected);
1858
 
1859
		$this->Paginator->request->params['paging'] = array(
1860
			'Client' => array(
1861
				'page' => 4895,
1862
				'current' => 10,
1863
				'count' => 48962,
1864
				'prevPage' => 1,
1865
				'nextPage' => 1,
1866
				'pageCount' => 4897,
1867
				'options' => array(
1868
					'page' => 4894,
1869
				),
1870
				'paramType' => 'named'
1871
			)
1872
		);
1873
 
1874
		$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
1875
		$expected = array(
1876
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1877
			' | ',
1878
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1879
			'...',
1880
			array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
1881
			' | ',
1882
			array('span' => array('class' => 'current')), '4895', '/span',
1883
			' | ',
1884
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1885
			' | ',
1886
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1887
		);
1888
		$this->assertTags($result, $expected);
1889
 
1890
		$this->Paginator->request->params['paging']['Client']['page'] = 3;
1891
 
1892
		$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2));
1893
		$expected = array(
1894
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1895
			' | ',
1896
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1897
			' | ',
1898
			array('span' => array('class' => 'current')), '3', '/span',
1899
			' | ',
1900
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1901
			'...',
1902
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1903
			' | ',
1904
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1905
		);
1906
		$this->assertTags($result, $expected);
1907
 
1908
		$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - '));
1909
		$expected = array(
1910
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1911
			' - ',
1912
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1913
			' - ',
1914
			array('span' => array('class' => 'current')), '3', '/span',
1915
			' - ',
1916
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1917
			'...',
1918
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1919
			' - ',
1920
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1921
		);
1922
		$this->assertTags($result, $expected);
1923
 
1924
		$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 5, 'last' => 5, 'separator' => ' - '));
1925
		$expected = array(
1926
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1927
			' - ',
1928
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1929
			' - ',
1930
			array('span' => array('class' => 'current')), '3', '/span',
1931
			' - ',
1932
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1933
			' - ',
1934
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1935
			' - ',
1936
			array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
1937
			'...',
1938
			array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
1939
			' - ',
1940
			array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
1941
			' - ',
1942
			array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
1943
			' - ',
1944
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1945
			' - ',
1946
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1947
		);
1948
		$this->assertTags($result, $expected);
1949
 
1950
		$this->Paginator->request->params['paging']['Client']['page'] = 4893;
1951
		$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
1952
		$expected = array(
1953
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1954
			' - ',
1955
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1956
			' - ',
1957
			array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1958
			' - ',
1959
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1960
			' - ',
1961
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1962
			'...',
1963
			array('span' => array()), array('a' => array('href' => '/index/page:4891')), '4891', '/a', '/span',
1964
			' - ',
1965
			array('span' => array()), array('a' => array('href' => '/index/page:4892')), '4892', '/a', '/span',
1966
			' - ',
1967
			array('span' => array('class' => 'current')), '4893', '/span',
1968
			' - ',
1969
			array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
1970
			' - ',
1971
			array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
1972
			' - ',
1973
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
1974
			' - ',
1975
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
1976
		);
1977
		$this->assertTags($result, $expected);
1978
 
1979
		$this->Paginator->request->params['paging']['Client']['page'] = 58;
1980
		$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
1981
		$expected = array(
1982
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
1983
			' - ',
1984
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
1985
			' - ',
1986
			array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
1987
			' - ',
1988
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
1989
			' - ',
1990
			array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
1991
			'...',
1992
			array('span' => array()), array('a' => array('href' => '/index/page:56')), '56', '/a', '/span',
1993
			' - ',
1994
			array('span' => array()), array('a' => array('href' => '/index/page:57')), '57', '/a', '/span',
1995
			' - ',
1996
			array('span' => array('class' => 'current')), '58', '/span',
1997
			' - ',
1998
			array('span' => array()), array('a' => array('href' => '/index/page:59')), '59', '/a', '/span',
1999
			' - ',
2000
			array('span' => array()), array('a' => array('href' => '/index/page:60')), '60', '/a', '/span',
2001
			'...',
2002
			array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
2003
			' - ',
2004
			array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
2005
			' - ',
2006
			array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
2007
			' - ',
2008
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
2009
			' - ',
2010
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
2011
		);
2012
		$this->assertTags($result, $expected);
2013
 
2014
		$this->Paginator->request->params['paging']['Client']['page'] = 5;
2015
		$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
2016
		$expected = array(
2017
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
2018
			' - ',
2019
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
2020
			' - ',
2021
			array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
2022
			' - ',
2023
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
2024
			' - ',
2025
			array('span' => array('class' => 'current')), '5', '/span',
2026
			' - ',
2027
			array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
2028
			' - ',
2029
			array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
2030
			'...',
2031
			array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span',
2032
			' - ',
2033
			array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span',
2034
			' - ',
2035
			array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span',
2036
			' - ',
2037
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
2038
			' - ',
2039
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
2040
		);
2041
		$this->assertTags($result, $expected);
2042
 
2043
		$this->Paginator->request->params['paging']['Client']['page'] = 3;
2044
		$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - ', 'ellipsis' => ' ~~~ '));
2045
		$expected = array(
2046
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
2047
			' - ',
2048
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
2049
			' - ',
2050
			array('span' => array('class' => 'current')), '3', '/span',
2051
			' - ',
2052
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
2053
			' ~~~ ',
2054
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
2055
			' - ',
2056
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
2057
		);
2058
		$this->assertTags($result, $expected);
2059
 
2060
		$this->Paginator->request->params['paging']['Client']['page'] = 3;
2061
		$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - ', 'ellipsis' => '<span class="ellipsis">...</span>'));
2062
		$expected = array(
2063
			array('span' => array()), array('a' => array('href' => '/')), '1', '/a', '/span',
2064
			' - ',
2065
			array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
2066
			' - ',
2067
			array('span' => array('class' => 'current')), '3', '/span',
2068
			' - ',
2069
			array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
2070
			array('span' => array('class' => 'ellipsis')), '...', '/span',
2071
			array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span',
2072
			' - ',
2073
			array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
2074
		);
2075
		$this->assertTags($result, $expected);
2076
 
2077
		$this->Paginator->request->params['paging'] = array(
2078
			'Client' => array(
2079
				'page' => 2,
2080
				'current' => 2,
2081
				'count' => 30,
2082
				'prevPage' => false,
2083
				'nextPage' => 3,
2084
				'pageCount' => 3,
2085
				'options' => array(
2086
					'page' => 1,
2087
				),
2088
				'paramType' => 'named'
2089
			)
2090
		);
2091
 
2092
		$request = new CakeRequest();
2093
		$request->addParams(array(
2094
			'controller' => 'clients', 'action' => 'index', 'plugin' => null, 'page' => 2
2095
		));
2096
		$request->base = '';
2097
		$request->here = '/clients/index/page:2';
2098
		$request->webroot = '/';
2099
 
2100
		Router::setRequestInfo($request);
2101
 
2102
		$result = $this->Paginator->numbers();
2103
		$expected = array(
2104
			array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span',
2105
			' | ',
2106
			array('span' => array('class' => 'current')), '2', '/span',
2107
			' | ',
2108
			array('span' => array()), array('a' => array('href' => '/clients/index/page:3')), '3', '/a', '/span',
2109
 
2110
		);
2111
		$this->assertTags($result, $expected);
2112
 
2113
		$this->Paginator->request->params['paging'] = array(
2114
			'Client' => array(
2115
				'page' => 2,
2116
				'current' => 2,
2117
				'count' => 30,
2118
				'prevPage' => false,
2119
				'nextPage' => 3,
2120
				'pageCount' => 3,
2121
				'options' => array(
2122
					'page' => 1,
2123
				),
2124
				'paramType' => 'querystring'
2125
			)
2126
		);
2127
 
2128
		$request = new CakeRequest();
2129
		$request->addParams(array(
2130
			'controller' => 'clients', 'action' => 'index', 'plugin' => null
2131
		));
2132
		$request->base = '';
2133
		$request->here = '/clients?page=2';
2134
		$request->webroot = '/';
2135
 
2136
		Router::setRequestInfo($request);
2137
 
2138
		$result = $this->Paginator->numbers();
2139
		$expected = array(
2140
			array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span',
2141
			' | ',
2142
			array('span' => array('class' => 'current')), '2', '/span',
2143
			' | ',
2144
			array('span' => array()), array('a' => array('href' => '/clients?page=3')), '3', '/a', '/span',
2145
 
2146
		);
2147
		$this->assertTags($result, $expected);
2148
	}
2149
 
2150
/**
2151
 * test first() and last() with tag options
2152
 *
2153
 * @return void
2154
 */
2155
	public function testFirstAndLastTag() {
2156
		$result = $this->Paginator->first('<<', array('tag' => 'li', 'class' => 'first'));
2157
		$expected = array(
2158
			'li' => array('class' => 'first'),
2159
			'a' => array('href' => '/', 'rel' => 'first'),
2160
			'&lt;&lt;',
2161
			'/a',
2162
			'/li'
2163
		);
2164
		$this->assertTags($result, $expected);
2165
 
2166
		$result = $this->Paginator->last(2, array('tag' => 'li', 'class' => 'last'));
2167
		$expected = array(
2168
			'...',
2169
			'li' => array('class' => 'last'),
2170
			array('a' => array('href' => '/index/page:6')), '6', '/a',
2171
			'/li',
2172
			' | ',
2173
			array('li' => array('class' => 'last')),
2174
			array('a' => array('href' => '/index/page:7')), '7', '/a',
2175
			'/li',
2176
		);
2177
		$this->assertTags($result, $expected);
2178
	}
2179
 
2180
/**
2181
 * test that on the last page you don't get a link ot the last page.
2182
 *
2183
 * @return void
2184
 */
2185
	public function testLastNoOutput() {
2186
		$this->Paginator->request->params['paging']['Article']['page'] = 15;
2187
		$this->Paginator->request->params['paging']['Article']['pageCount'] = 15;
2188
 
2189
		$result = $this->Paginator->last();
2190
		$expected = '';
2191
		$this->assertEquals($expected, $result);
2192
	}
2193
 
2194
/**
2195
 * test first() on the first page.
2196
 *
2197
 * @return void
2198
 */
2199
	public function testFirstEmpty() {
2200
		$this->Paginator->request->params['paging']['Article']['page'] = 1;
2201
 
2202
		$result = $this->Paginator->first();
2203
		$expected = '';
2204
		$this->assertEquals($expected, $result);
2205
	}
2206
 
2207
/**
2208
 * test first() and options()
2209
 *
2210
 * @return void
2211
 */
2212
	public function testFirstFullBaseUrl() {
2213
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'DESC');
2214
 
2215
		$this->Paginator->options(array('url' => array('full_base' => true)));
2216
 
2217
		$result = $this->Paginator->first();
2218
		$expected = array(
2219
			'<span',
2220
			array('a' => array(
2221
				'href' => FULL_BASE_URL . '/index/sort:Article.title/direction:DESC', 'rel' => 'first'
2222
			)),
2223
			'&lt;&lt; first',
2224
			'/a',
2225
			'/span',
2226
		);
2227
		$this->assertTags($result, $expected);
2228
	}
2229
 
2230
/**
2231
 * test first() on the fence-post
2232
 *
2233
 * @return void
2234
 */
2235
	public function testFirstBoundaries() {
2236
		$result = $this->Paginator->first();
2237
		$expected = array(
2238
			'<span',
2239
			'a' => array('href' => '/', 'rel' => 'first'),
2240
			'&lt;&lt; first',
2241
			'/a',
2242
			'/span'
2243
		);
2244
		$this->assertTags($result, $expected);
2245
 
2246
		$result = $this->Paginator->first(2);
2247
		$expected = array(
2248
			'<span',
2249
			array('a' => array('href' => '/')), '1', '/a',
2250
			'/span',
2251
			' | ',
2252
			'<span',
2253
			array('a' => array('href' => '/index/page:2')), '2', '/a',
2254
			'/span'
2255
		);
2256
		$this->assertTags($result, $expected);
2257
 
2258
		$this->Paginator->request->params['paging']['Article']['page'] = 2;
2259
		$result = $this->Paginator->first(3);
2260
		$this->assertEquals('', $result, 'When inside the first links range, no links should be made');
2261
	}
2262
 
2263
/**
2264
 * test params() method
2265
 *
2266
 * @return void
2267
 */
2268
	public function testParams() {
2269
		$result = $this->Paginator->params();
2270
		$this->assertArrayHasKey('page', $result);
2271
		$this->assertArrayHasKey('pageCount', $result);
2272
	}
2273
 
2274
/**
2275
 * test param() method
2276
 *
2277
 * @return void
2278
 */
2279
	public function testParam() {
2280
		$result = $this->Paginator->param('count');
2281
		$this->assertSame(62, $result);
2282
 
2283
		$result = $this->Paginator->param('imaginary');
2284
		$this->assertNull($result);
2285
	}
2286
 
2287
/**
2288
 * test last() method
2289
 *
2290
 * @return void
2291
 */
2292
	public function testLast() {
2293
		$result = $this->Paginator->last();
2294
		$expected = array(
2295
			'<span',
2296
			'a' => array('href' => '/index/page:7', 'rel' => 'last'),
2297
			'last &gt;&gt;',
2298
			'/a',
2299
			'/span'
2300
		);
2301
		$this->assertTags($result, $expected);
2302
 
2303
		$result = $this->Paginator->last(1);
2304
		$expected = array(
2305
			'...',
2306
			'<span',
2307
			'a' => array('href' => '/index/page:7'),
2308
			'7',
2309
			'/a',
2310
			'/span'
2311
		);
2312
		$this->assertTags($result, $expected);
2313
 
2314
		$this->Paginator->request->params['paging']['Article']['page'] = 6;
2315
 
2316
		$result = $this->Paginator->last(2);
2317
		$expected = array(
2318
			'...',
2319
			'<span',
2320
			array('a' => array('href' => '/index/page:6')), '6', '/a',
2321
			'/span',
2322
			' | ',
2323
			'<span',
2324
			array('a' => array('href' => '/index/page:7')), '7', '/a',
2325
			'/span',
2326
		);
2327
		$this->assertTags($result, $expected);
2328
 
2329
		$result = $this->Paginator->last(3);
2330
		$this->assertEquals('', $result, 'When inside the last links range, no links should be made');
2331
	}
2332
 
2333
/**
2334
 * undocumented function
2335
 *
2336
 * @return void
2337
 */
2338
	public function testLastOptions() {
2339
		$this->Paginator->request->params['paging'] = array(
2340
			'Client' => array(
2341
				'page' => 4,
2342
				'current' => 3,
2343
				'count' => 30,
2344
				'prevPage' => false,
2345
				'nextPage' => 2,
2346
				'pageCount' => 15,
2347
				'options' => array(
2348
					'page' => 1,
2349
					'order' => array('Client.name' => 'DESC'),
2350
				),
2351
				'paramType' => 'named'
2352
			)
2353
		);
2354
 
2355
		$result = $this->Paginator->last();
2356
		$expected = array(
2357
			'<span',
2358
			array('a' => array(
2359
				'href' => '/index/page:15/sort:Client.name/direction:DESC',
2360
				'rel' => 'last'
2361
			)),
2362
				'last &gt;&gt;', '/a',
2363
			'/span',
2364
		);
2365
		$this->assertTags($result, $expected);
2366
 
2367
		$result = $this->Paginator->last(1);
2368
		$expected = array(
2369
			'...',
2370
			'<span',
2371
			array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
2372
			'/span',
2373
		);
2374
		$this->assertTags($result, $expected);
2375
 
2376
		$result = $this->Paginator->last(2);
2377
		$expected = array(
2378
			'...',
2379
			'<span',
2380
			array('a' => array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a',
2381
			'/span',
2382
			' | ',
2383
			'<span',
2384
			array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
2385
			'/span',
2386
		);
2387
		$this->assertTags($result, $expected);
2388
 
2389
		$result = $this->Paginator->last(2, array('ellipsis' => '<span class="ellipsis">...</span>'));
2390
		$expected = array(
2391
			array('span' => array('class' => 'ellipsis')), '...', '/span',
2392
			'<span',
2393
			array('a' => array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a',
2394
			'/span',
2395
			' | ',
2396
			'<span',
2397
			array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
2398
			'/span',
2399
		);
2400
		$this->assertTags($result, $expected);
2401
	}
2402
 
2403
/**
2404
 * testCounter method
2405
 *
2406
 * @return void
2407
 */
2408
	public function testCounter() {
2409
		$this->Paginator->request->params['paging'] = array(
2410
			'Client' => array(
2411
				'page' => 1,
2412
				'current' => 3,
2413
				'count' => 13,
2414
				'prevPage' => false,
2415
				'nextPage' => true,
2416
				'pageCount' => 5,
2417
				'limit' => 3,
2418
				'options' => array(
2419
					'page' => 1,
2420
					'order' => array('Client.name' => 'DESC'),
2421
				),
2422
				'paramType' => 'named'
2423
			)
2424
		);
2425
		$input = 'Page %page% of %pages%, showing %current% records out of %count% total, ';
2426
		$input .= 'starting on record %start%, ending on %end%';
2427
		$result = $this->Paginator->counter($input);
2428
		$expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ';
2429
		$expected .= 'ending on 3';
2430
		$this->assertEquals($expected, $result);
2431
 
2432
		$input = 'Page {:page} of {:pages}, showing {:current} records out of {:count} total, ';
2433
		$input .= 'starting on record {:start}, ending on {:end}';
2434
		$result = $this->Paginator->counter($input);
2435
		$this->assertEquals($expected, $result);
2436
 
2437
		$input = 'Page %page% of %pages%';
2438
		$result = $this->Paginator->counter($input);
2439
		$expected = 'Page 1 of 5';
2440
		$this->assertEquals($expected, $result);
2441
 
2442
		$result = $this->Paginator->counter(array('format' => $input));
2443
		$expected = 'Page 1 of 5';
2444
		$this->assertEquals($expected, $result);
2445
 
2446
		$result = $this->Paginator->counter(array('format' => 'pages'));
2447
		$expected = '1 of 5';
2448
		$this->assertEquals($expected, $result);
2449
 
2450
		$result = $this->Paginator->counter(array('format' => 'range'));
2451
		$expected = '1 - 3 of 13';
2452
		$this->assertEquals($expected, $result);
2453
 
2454
		$result = $this->Paginator->counter('Showing %page% of %pages% %model%');
2455
		$this->assertEquals('Showing 1 of 5 clients', $result);
2456
	}
2457
 
2458
/**
2459
 * testHasPage method
2460
 *
2461
 * @return void
2462
 */
2463
	public function testHasPage() {
2464
		$result = $this->Paginator->hasPage('Article', 15);
2465
		$this->assertFalse($result);
2466
 
2467
		$result = $this->Paginator->hasPage('UndefinedModel', 2);
2468
		$this->assertFalse($result);
2469
 
2470
		$result = $this->Paginator->hasPage('Article', 2);
2471
		$this->assertTrue($result);
2472
 
2473
		$result = $this->Paginator->hasPage(2);
2474
		$this->assertTrue($result);
2475
	}
2476
 
2477
/**
2478
 * testWithPlugin method
2479
 *
2480
 * @return void
2481
 */
2482
	public function testWithPlugin() {
2483
		Router::reload();
2484
		Router::setRequestInfo(array(
2485
			array(
2486
				'pass' => array(), 'named' => array(), 'prefix' => null, 'form' => array(),
2487
				'controller' => 'magazines', 'plugin' => 'my_plugin', 'action' => 'index',
2488
				'url' => array('ext' => 'html', 'url' => 'my_plugin/magazines')),
2489
			array('base' => '', 'here' => '/my_plugin/magazines', 'webroot' => '/')
2490
		));
2491
 
2492
		$result = $this->Paginator->link('Page 3', array('page' => 3));
2493
		$expected = array(
2494
			'a' => array('href' => '/my_plugin/magazines/index/page:3'), 'Page 3', '/a'
2495
		);
2496
		$this->assertTags($result, $expected);
2497
 
2498
		$this->Paginator->options(array('url' => array('action' => 'another_index')));
2499
		$result = $this->Paginator->link('Page 3', array('page' => 3));
2500
		$expected = array(
2501
			'a' => array('href' => '/my_plugin/magazines/another_index/page:3'), 'Page 3', '/a'
2502
		);
2503
		$this->assertTags($result, $expected);
2504
 
2505
		$this->Paginator->options(array('url' => array('controller' => 'issues')));
2506
		$result = $this->Paginator->link('Page 3', array('page' => 3));
2507
		$expected = array(
2508
			'a' => array('href' => '/my_plugin/issues/index/page:3'), 'Page 3', '/a'
2509
		);
2510
		$this->assertTags($result, $expected);
2511
 
2512
		$this->Paginator->options(array('url' => array('plugin' => null)));
2513
		$result = $this->Paginator->link('Page 3', array('page' => 3));
2514
		$expected = array(
2515
			'a' => array('href' => '/magazines/index/page:3'), 'Page 3', '/a'
2516
		);
2517
		$this->assertTags($result, $expected);
2518
 
2519
		$this->Paginator->options(array('url' => array('plugin' => null, 'controller' => 'issues')));
2520
		$result = $this->Paginator->link('Page 3', array('page' => 3));
2521
		$expected = array(
2522
			'a' => array('href' => '/issues/index/page:3'), 'Page 3', '/a'
2523
		);
2524
		$this->assertTags($result, $expected);
2525
	}
2526
 
2527
/**
2528
 * testNextLinkUsingDotNotation method
2529
 *
2530
 * @return void
2531
 */
2532
	public function testNextLinkUsingDotNotation() {
2533
		Router::reload();
2534
		Router::parse('/');
2535
		Router::setRequestInfo(array(
2536
			array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')),
2537
			array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
2538
		));
2539
 
2540
		$this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
2541
		$this->Paginator->request->params['paging']['Article']['page'] = 1;
2542
 
2543
		$test = array('url' => array(
2544
			'page' => '1',
2545
			'sort' => 'Article.title',
2546
			'direction' => 'asc',
2547
		));
2548
		$this->Paginator->options($test);
2549
 
2550
		$result = $this->Paginator->next('Next');
2551
		$expected = array(
2552
			'span' => array('class' => 'next'),
2553
			'a' => array(
2554
				'href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc',
2555
				'rel' => 'next'
2556
			),
2557
			'Next',
2558
			'/a',
2559
			'/span',
2560
		);
2561
		$this->assertTags($result, $expected);
2562
	}
2563
 
2564
/**
2565
 * Ensure that the internal link class object is called when the update key is present
2566
 *
2567
 * @return void
2568
 */
2569
	public function testAjaxLinkGenerationNumbers() {
2570
		$this->Paginator->Js->expectCallCount('link', 2);
2571
		$this->Paginator->numbers(array(
2572
			'modulus' => '2',
2573
			'url' => array('controller' => 'projects', 'action' => 'sort'),
2574
			'update' => 'list'
2575
		));
2576
	}
2577
 
2578
/**
2579
 * test that paginatorHelper::link() uses JsHelper to make links when 'update' key is present
2580
 *
2581
 * @return void
2582
 */
2583
	public function testAjaxLinkGenerationLink() {
2584
		$this->Paginator->Js->expects($this->once())
2585
			->method('link')
2586
			->will($this->returnValue('I am a link'));
2587
 
2588
		$result = $this->Paginator->link('test', array('controller' => 'posts'), array('update' => '#content'));
2589
		$this->assertEquals('I am a link', $result);
2590
	}
2591
 
2592
/**
2593
 * test that mock classes injected into paginatorHelper are called when using link()
2594
 *
2595
 * @expectedException CakeException
2596
 * @return void
2597
 */
2598
	public function testMockAjaxProviderClassInjection() {
2599
		$mock = $this->getMock('PaginatorHelper', array(), array($this->View), 'PaginatorMockJsHelper');
2600
		$Paginator = new PaginatorHelper($this->View, array('ajax' => 'PaginatorMockJs'));
2601
		$Paginator->request->params['paging'] = array(
2602
			'Article' => array(
2603
				'current' => 9,
2604
				'count' => 62,
2605
				'prevPage' => false,
2606
				'nextPage' => true,
2607
				'pageCount' => 7,
2608
				'defaults' => array(),
2609
				'options' => array(),
2610
				'paramType' => 'named'
2611
			)
2612
		);
2613
		$Paginator->PaginatorMockJs = $mock;
2614
		$Paginator->PaginatorMockJs->expects($this->once())->method('link');
2615
		$Paginator->link('Page 2', array('page' => 2), array('update' => '#content'));
2616
 
2617
		new PaginatorHelper($this->View, array('ajax' => 'Form'));
2618
	}
2619
 
2620
/**
2621
 * test that query string URLs can be generated.
2622
 *
2623
 * @return void
2624
 */
2625
	public function testQuerystringUrlGeneration() {
2626
		$this->Paginator->request->params['paging']['Article']['paramType'] = 'querystring';
2627
		$result = $this->Paginator->url(array('page' => '1'));
2628
		$expected = '/';
2629
		$this->assertEquals($expected, $result);
2630
 
2631
		$result = $this->Paginator->url(array('page' => '1', 'limit' => 10, 'something' => 'else'));
2632
		$expected = '/index/something:else?limit=10';
2633
		$this->assertEquals($expected, $result);
2634
 
2635
		$result = $this->Paginator->url(array('page' => '4'));
2636
		$expected = '/?page=4';
2637
		$this->assertEquals($expected, $result);
2638
 
2639
		$result = $this->Paginator->url(array('page' => '4', 'limit' => 10, 'something' => 'else'));
2640
		$expected = '/index/something:else?page=4&amp;limit=10';
2641
		$this->assertEquals($expected, $result);
2642
	}
2643
 
2644
/**
2645
 * test query string paging link.
2646
 *
2647
 * @return void
2648
 */
2649
	public function testQuerystringNextAndPrev() {
2650
		$this->Paginator->request->params['paging']['Article']['paramType'] = 'querystring';
2651
		$this->Paginator->request->params['paging']['Article']['page'] = 2;
2652
		$this->Paginator->request->params['paging']['Article']['nextPage'] = true;
2653
		$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
2654
 
2655
		$result = $this->Paginator->next('Next');
2656
		$expected = array(
2657
			'span' => array('class' => 'next'),
2658
			'a' => array('href' => '/?page=3', 'rel' => 'next'),
2659
			'Next',
2660
			'/a',
2661
			'/span'
2662
		);
2663
		$this->assertTags($result, $expected);
2664
 
2665
		$result = $this->Paginator->prev('Prev');
2666
		$expected = array(
2667
			'span' => array('class' => 'prev'),
2668
			'a' => array('href' => '/', 'rel' => 'prev'),
2669
			'Prev',
2670
			'/a',
2671
			'/span'
2672
		);
2673
		$this->assertTags($result, $expected);
2674
	}
2675
 
2676
/**
2677
 * test that additional keys can be flagged as query string args.
2678
 *
2679
 * @return void
2680
 */
2681
	public function testOptionsConvertKeys() {
2682
		$this->Paginator->options(array(
2683
			'convertKeys' => array('something'),
2684
			'Article' => array('paramType' => 'querystring')
2685
		));
2686
		$result = $this->Paginator->url(array('page' => '4', 'something' => 'bar'));
2687
		$expected = '/?page=4&amp;something=bar';
2688
		$this->assertEquals($expected, $result);
2689
	}
2690
 
2691
/**
2692
 * test the current() method
2693
 *
2694
 * @return void
2695
 */
2696
	public function testCurrent() {
2697
		$result = $this->Paginator->current();
2698
		$this->assertEquals($this->Paginator->request->params['paging']['Article']['page'], $result);
2699
 
2700
		$result = $this->Paginator->current('Incorrect');
2701
		$this->assertEquals(1, $result);
2702
	}
2703
 
2704
/**
2705
 * test the defaultModel() method
2706
 *
2707
 * @return void
2708
 */
2709
	public function testNoDefaultModel() {
2710
		$this->Paginator->request = new CakeRequest(null, false);
2711
		$this->assertNull($this->Paginator->defaultModel());
2712
	}
2713
 
2714
/**
2715
 * test the numbers() method when there is only one page
2716
 *
2717
 * @return void
2718
 */
2719
	public function testWithOnePage() {
2720
		$this->Paginator->request['paging'] = array(
2721
			'Article' => array(
2722
				'page' => 1,
2723
				'current' => 2,
2724
				'count' => 2,
2725
				'prevPage' => false,
2726
				'nextPage' => true,
2727
				'pageCount' => 1,
2728
				'options' => array(
2729
					'page' => 1,
2730
				),
2731
				'paramType' => 'named',
2732
			)
2733
		);
2734
		$this->assertFalse($this->Paginator->numbers());
2735
		$this->assertFalse($this->Paginator->first());
2736
		$this->assertFalse($this->Paginator->last());
2737
	}
2738
 
2739
/**
2740
 * test the numbers() method when there is only one page
2741
 *
2742
 * @return void
2743
 */
2744
	public function testWithZeroPages() {
2745
		$this->Paginator->request['paging'] = array(
2746
			'Article' => array(
2747
				'page' => 0,
2748
				'current' => 0,
2749
				'count' => 0,
2750
				'prevPage' => false,
2751
				'nextPage' => false,
2752
				'pageCount' => 0,
2753
				'limit' => 10,
2754
				'options' => array(
2755
					'page' => 0,
2756
					'conditions' => array()
2757
				),
2758
				'paramType' => 'named',
2759
			)
2760
		);
2761
 
2762
		$result = $this->Paginator->counter(array('format' => 'pages'));
2763
		$expected = '0 of 1';
2764
		$this->assertEquals($expected, $result);
2765
	}
2766
}