Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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