PageRenderTime 70ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

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