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

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

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