PageRenderTime 55ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php

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