PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/praveen_excell/opshop
PHP | 2501 lines | 2017 code | 225 blank | 259 comment | 1 complexity | e349ce7621a06b37bdc037de7b5f6a58 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full 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 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  15. * @package Cake.Test.Case.View.Helper
  16. * @since CakePHP(tm) v 1.2.0.4206
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('View', 'View');
  20. App::uses('HtmlHelper', 'View/Helper');
  21. App::uses('JsHelper', 'View/Helper');
  22. App::uses('PaginatorHelper', 'View/Helper');
  23. App::uses('FormHelper', 'View/Helper');
  24. if (!defined('FULL_BASE_URL')) {
  25. define('FULL_BASE_URL', 'http://cakephp.org');
  26. }
  27. /**
  28. * PaginatorHelperTest class
  29. *
  30. * @package Cake.Test.Case.View.Helper
  31. */
  32. class PaginatorHelperTest extends CakeTestCase {
  33. /**
  34. * setUp method
  35. *
  36. * @return void
  37. */
  38. public function setUp() {
  39. $controller = null;
  40. $this->View = new View($controller);
  41. $this->Paginator = new PaginatorHelper($this->View);
  42. $this->Paginator->Js = $this->getMock('PaginatorHelper', array(), array($this->View));
  43. $this->Paginator->request = new CakeRequest(null, false);
  44. $this->Paginator->request->addParams(array(
  45. 'paging' => array(
  46. 'Article' => array(
  47. 'page' => 2,
  48. 'current' => 9,
  49. 'count' => 62,
  50. 'prevPage' => false,
  51. 'nextPage' => true,
  52. 'pageCount' => 7,
  53. 'order' => null,
  54. 'limit' => 20,
  55. 'options' => array(
  56. 'page' => 1,
  57. 'conditions' => array()
  58. ),
  59. 'paramType' => 'named'
  60. )
  61. )
  62. ));
  63. $this->Paginator->Html = new HtmlHelper($this->View);
  64. Configure::write('Routing.prefixes', array());
  65. Router::reload();
  66. }
  67. /**
  68. * tearDown method
  69. *
  70. * @return void
  71. */
  72. public function tearDown() {
  73. unset($this->View, $this->Paginator);
  74. }
  75. /**
  76. * testHasPrevious method
  77. *
  78. * @return void
  79. */
  80. public function testHasPrevious() {
  81. $this->assertSame($this->Paginator->hasPrev(), false);
  82. $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
  83. $this->assertSame($this->Paginator->hasPrev(), true);
  84. $this->Paginator->request->params['paging']['Article']['prevPage'] = false;
  85. }
  86. /**
  87. * testHasNext method
  88. *
  89. * @return void
  90. */
  91. public function testHasNext() {
  92. $this->assertSame($this->Paginator->hasNext(), true);
  93. $this->Paginator->request->params['paging']['Article']['nextPage'] = false;
  94. $this->assertSame($this->Paginator->hasNext(), false);
  95. $this->Paginator->request->params['paging']['Article']['nextPage'] = true;
  96. }
  97. /**
  98. * testDisabledLink method
  99. *
  100. * @return void
  101. */
  102. public function testDisabledLink() {
  103. $this->Paginator->request->params['paging']['Article']['nextPage'] = false;
  104. $this->Paginator->request->params['paging']['Article']['page'] = 1;
  105. $result = $this->Paginator->next('Next', array(), true);
  106. $expected = '<span class="next">Next</span>';
  107. $this->assertEquals($expected, $result);
  108. $this->Paginator->request->params['paging']['Article']['prevPage'] = false;
  109. $result = $this->Paginator->prev('prev', array('update' => 'theList', 'indicator' => 'loading', 'url' => array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span'));
  110. $expected = array(
  111. 'span' => array('class' => 'disabled'), 'prev', '/span'
  112. );
  113. $this->assertTags($result, $expected);
  114. }
  115. /**
  116. * testSortLinks method
  117. *
  118. * @return void
  119. */
  120. public function testSortLinks() {
  121. Router::reload();
  122. Router::parse('/');
  123. Router::setRequestInfo(array(
  124. array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'url' => array('url' => 'accounts/')),
  125. array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
  126. ));
  127. $this->Paginator->options(array('url' => array('param')));
  128. $this->Paginator->request['paging'] = array(
  129. 'Article' => array(
  130. 'current' => 9,
  131. 'count' => 62,
  132. 'prevPage' => false,
  133. 'nextPage' => true,
  134. 'pageCount' => 7,
  135. 'options' => array(
  136. 'page' => 1,
  137. 'order' => array('date' => 'asc'),
  138. 'conditions' => array()
  139. ),
  140. 'paramType' => 'named'
  141. )
  142. );
  143. $result = $this->Paginator->sort('title');
  144. $expected = array(
  145. 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
  146. 'Title',
  147. '/a'
  148. );
  149. $this->assertTags($result, $expected);
  150. $result = $this->Paginator->sort('date');
  151. $expected = array(
  152. 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc', 'class' => 'asc'),
  153. 'Date',
  154. '/a'
  155. );
  156. $this->assertTags($result, $expected);
  157. $result = $this->Paginator->sort('title', 'TestTitle');
  158. $expected = array(
  159. 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
  160. 'TestTitle',
  161. '/a'
  162. );
  163. $this->assertTags($result, $expected);
  164. $result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'));
  165. $expected = array(
  166. 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
  167. 'ascending',
  168. '/a'
  169. );
  170. $this->assertTags($result, $expected);
  171. $this->Paginator->request->params['paging']['Article']['options']['sort'] = 'title';
  172. $result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'));
  173. $expected = array(
  174. 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc', 'class' => 'asc'),
  175. 'descending',
  176. '/a'
  177. );
  178. $this->assertTags($result, $expected);
  179. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
  180. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  181. $result = $this->Paginator->sort('title');
  182. $this->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
  183. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  184. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  185. $result = $this->Paginator->sort('title');
  186. $this->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
  187. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
  188. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  189. $result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc'));
  190. $this->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
  191. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
  192. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  193. $result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc'));
  194. $this->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
  195. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  196. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  197. $result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc'));
  198. $this->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
  199. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  200. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  201. $result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc'));
  202. $this->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
  203. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  204. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  205. $result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc', 'class' => 'foo'));
  206. $this->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="foo asc">Title<\/a>$/', $result);
  207. }
  208. /**
  209. * test that sort() works with virtual field order options.
  210. *
  211. * @return void
  212. */
  213. public function testSortLinkWithVirtualField() {
  214. Router::setRequestInfo(array(
  215. array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')),
  216. array('base' => '', 'here' => '/accounts/', 'webroot' => '/')
  217. ));
  218. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('full_name' => 'asc');
  219. $result = $this->Paginator->sort('Article.full_name');
  220. $expected = array(
  221. 'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:desc', 'class' => 'asc'),
  222. 'Article.full Name',
  223. '/a'
  224. );
  225. $this->assertTags($result, $expected);
  226. $result = $this->Paginator->sort('full_name');
  227. $expected = array(
  228. 'a' => array('href' => '/accounts/index/page:1/sort:full_name/direction:desc', 'class' => 'asc'),
  229. 'Full Name',
  230. '/a'
  231. );
  232. $this->assertTags($result, $expected);
  233. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('full_name' => 'desc');
  234. $result = $this->Paginator->sort('Article.full_name');
  235. $expected = array(
  236. 'a' => array('href' => '/accounts/index/page:1/sort:Article.full_name/direction:asc', 'class' => 'desc'),
  237. 'Article.full Name',
  238. '/a'
  239. );
  240. $this->assertTags($result, $expected);
  241. $result = $this->Paginator->sort('full_name');
  242. $expected = array(
  243. 'a' => array('href' => '/accounts/index/page:1/sort:full_name/direction:asc', 'class' => 'desc'),
  244. 'Full Name',
  245. '/a'
  246. );
  247. $this->assertTags($result, $expected);
  248. }
  249. /**
  250. * testSortLinksUsingDirectionOption method
  251. *
  252. * @return void
  253. */
  254. public function testSortLinksUsingDirectionOption() {
  255. Router::reload();
  256. Router::parse('/');
  257. Router::setRequestInfo(array(
  258. array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(),
  259. 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true')),
  260. array('base' => '/', 'here' => '/accounts/', 'webroot' => '/',)
  261. ));
  262. $this->Paginator->options(array('url' => array('param')));
  263. $result = $this->Paginator->sort('title', 'TestTitle', array('direction' => 'desc'));
  264. $expected = array(
  265. 'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'),
  266. 'TestTitle',
  267. '/a'
  268. );
  269. $this->assertTags($result, $expected);
  270. $result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'), array('direction' => 'desc'));
  271. $expected = array(
  272. 'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'),
  273. 'descending',
  274. '/a'
  275. );
  276. $this->assertTags($result, $expected);
  277. }
  278. /**
  279. * testSortLinksUsingDotNotation method
  280. *
  281. * @return void
  282. */
  283. public function testSortLinksUsingDotNotation() {
  284. Router::reload();
  285. Router::parse('/');
  286. Router::setRequestInfo(array(
  287. array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
  288. array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
  289. ));
  290. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
  291. $result = $this->Paginator->sort('Article.title', 'Title');
  292. $expected = array(
  293. 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc', 'class' => 'desc'),
  294. 'Title',
  295. '/a'
  296. );
  297. $this->assertTags($result, $expected);
  298. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  299. $result = $this->Paginator->sort('Article.title', 'Title');
  300. $expected = array(
  301. 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc', 'class' => 'asc'),
  302. 'Title',
  303. '/a'
  304. );
  305. $this->assertTags($result, $expected);
  306. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Account.title' => 'asc');
  307. $result = $this->Paginator->sort('title');
  308. $expected = array(
  309. 'a' => array('href' => '/officespace/accounts/index/page:1/sort:title/direction:asc'),
  310. 'Title',
  311. '/a'
  312. );
  313. $this->assertTags($result, $expected);
  314. }
  315. /**
  316. * testSortKey method
  317. *
  318. * @return void
  319. */
  320. public function testSortKey() {
  321. $result = $this->Paginator->sortKey(null, array(
  322. 'order' => array('Article.title' => 'desc'
  323. )));
  324. $this->assertEquals('Article.title', $result);
  325. $result = $this->Paginator->sortKey('Article', array('order' => 'Article.title'));
  326. $this->assertEquals('Article.title', $result);
  327. $result = $this->Paginator->sortKey('Article', array('sort' => 'Article.title'));
  328. $this->assertEquals('Article.title', $result);
  329. $result = $this->Paginator->sortKey('Article', array('sort' => 'Article'));
  330. $this->assertEquals('Article', $result);
  331. }
  332. /**
  333. * Test that sortKey falls back to the default sorting options set
  334. * in the $params which are the default pagination options.
  335. *
  336. * @return void
  337. */
  338. public function testSortKeyFallbackToParams() {
  339. $this->Paginator->request->params['paging']['Article']['order'] = 'Article.body';
  340. $result = $this->Paginator->sortKey();
  341. $this->assertEquals('Article.body', $result);
  342. $result = $this->Paginator->sortKey('Article');
  343. $this->assertEquals('Article.body', $result);
  344. $this->Paginator->request->params['paging']['Article']['order'] = array(
  345. 'Article.body' => 'DESC'
  346. );
  347. $result = $this->Paginator->sortKey();
  348. $this->assertEquals('Article.body', $result);
  349. $result = $this->Paginator->sortKey('Article');
  350. $this->assertEquals('Article.body', $result);
  351. }
  352. /**
  353. * testSortDir method
  354. *
  355. * @return void
  356. */
  357. public function testSortDir() {
  358. $result = $this->Paginator->sortDir();
  359. $expected = 'asc';
  360. $this->assertEquals($expected, $result);
  361. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
  362. $result = $this->Paginator->sortDir();
  363. $expected = 'desc';
  364. $this->assertEquals($expected, $result);
  365. unset($this->Paginator->request->params['paging']['Article']['options']);
  366. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  367. $result = $this->Paginator->sortDir();
  368. $expected = 'asc';
  369. $this->assertEquals($expected, $result);
  370. unset($this->Paginator->request->params['paging']['Article']['options']);
  371. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('title' => 'desc');
  372. $result = $this->Paginator->sortDir();
  373. $expected = 'desc';
  374. $this->assertEquals($expected, $result);
  375. unset($this->Paginator->request->params['paging']['Article']['options']);
  376. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('title' => 'asc');
  377. $result = $this->Paginator->sortDir();
  378. $expected = 'asc';
  379. $this->assertEquals($expected, $result);
  380. unset($this->Paginator->request->params['paging']['Article']['options']);
  381. $this->Paginator->request->params['paging']['Article']['options']['direction'] = 'asc';
  382. $result = $this->Paginator->sortDir();
  383. $expected = 'asc';
  384. $this->assertEquals($expected, $result);
  385. unset($this->Paginator->request->params['paging']['Article']['options']);
  386. $this->Paginator->request->params['paging']['Article']['options']['direction'] = 'desc';
  387. $result = $this->Paginator->sortDir();
  388. $expected = 'desc';
  389. $this->assertEquals($expected, $result);
  390. unset($this->Paginator->request->params['paging']['Article']['options']);
  391. $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
  392. $expected = 'asc';
  393. $this->assertEquals($expected, $result);
  394. $result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
  395. $expected = 'desc';
  396. $this->assertEquals($expected, $result);
  397. $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
  398. $expected = 'asc';
  399. $this->assertEquals($expected, $result);
  400. }
  401. /**
  402. * Test that sortDir falls back to the default sorting options set
  403. * in the $params which are the default pagination options.
  404. *
  405. * @return void
  406. */
  407. public function testSortDirFallbackToParams() {
  408. $this->Paginator->request->params['paging']['Article']['order'] = array(
  409. 'Article.body' => 'ASC'
  410. );
  411. $result = $this->Paginator->sortDir();
  412. $this->assertEquals('asc', $result);
  413. $result = $this->Paginator->sortDir('Article');
  414. $this->assertEquals('asc', $result);
  415. $this->Paginator->request->params['paging']['Article']['order'] = array(
  416. 'Article.body' => 'DESC'
  417. );
  418. $result = $this->Paginator->sortDir();
  419. $this->assertEquals('desc', $result);
  420. $result = $this->Paginator->sortDir('Article');
  421. $this->assertEquals('desc', $result);
  422. }
  423. /**
  424. * testSortAdminLinks method
  425. *
  426. * @return void
  427. */
  428. public function testSortAdminLinks() {
  429. Configure::write('Routing.prefixes', array('admin'));
  430. Router::reload();
  431. Router::setRequestInfo(array(
  432. array('pass' => array(), 'named' => array(), 'controller' => 'users', 'plugin' => null, 'action' => 'admin_index', 'prefix' => 'admin', 'admin' => true, 'url' => array('ext' => 'html', 'url' => 'admin/users')),
  433. array('base' => '', 'here' => '/admin/users', 'webroot' => '/')
  434. ));
  435. Router::parse('/admin/users');
  436. $this->Paginator->request->params['paging']['Article']['page'] = 1;
  437. $result = $this->Paginator->next('Next');
  438. $expected = array(
  439. 'span' => array('class' => 'next'),
  440. 'a' => array('href' => '/admin/users/index/page:2', 'rel' => 'next'),
  441. 'Next',
  442. '/a',
  443. '/span'
  444. );
  445. $this->assertTags($result, $expected);
  446. Router::reload();
  447. Router::setRequestInfo(array(
  448. array('plugin' => null, 'controller' => 'test', 'action' => 'admin_index', 'pass' => array(), 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/test')),
  449. array('base' => '', 'here' => '/admin/test', 'webroot' => '/')
  450. ));
  451. Router::parse('/');
  452. $this->Paginator->options(array('url' => array('param')));
  453. $result = $this->Paginator->sort('title');
  454. $expected = array(
  455. 'a' => array('href' => '/admin/test/index/param/page:1/sort:title/direction:asc'),
  456. 'Title',
  457. '/a'
  458. );
  459. $this->assertTags($result, $expected);
  460. $this->Paginator->options(array('url' => array('param')));
  461. $result = $this->Paginator->sort('Article.title', 'Title');
  462. $expected = array(
  463. 'a' => array('href' => '/admin/test/index/param/page:1/sort:Article.title/direction:asc'),
  464. 'Title',
  465. '/a'
  466. );
  467. $this->assertTags($result, $expected);
  468. }
  469. /**
  470. * testUrlGeneration method
  471. *
  472. * @return void
  473. */
  474. public function testUrlGeneration() {
  475. $result = $this->Paginator->sort('controller');
  476. $expected = array(
  477. 'a' => array('href' => '/index/page:1/sort:controller/direction:asc'),
  478. 'Controller',
  479. '/a'
  480. );
  481. $this->assertTags($result, $expected);
  482. $result = $this->Paginator->url();
  483. $this->assertEquals('/index/page:1', $result);
  484. $this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
  485. $result = $this->Paginator->url();
  486. $this->assertEquals('/index/page:2', $result);
  487. $options = array('order' => array('Article' => 'desc'));
  488. $result = $this->Paginator->url($options);
  489. $this->assertEquals('/index/page:2/sort:Article/direction:desc', $result);
  490. $this->Paginator->request->params['paging']['Article']['options']['page'] = 3;
  491. $options = array('order' => array('Article.name' => 'desc'));
  492. $result = $this->Paginator->url($options);
  493. $this->assertEquals('/index/page:3/sort:Article.name/direction:desc', $result);
  494. }
  495. /**
  496. * test URL generation with prefix routes
  497. *
  498. * @return void
  499. */
  500. public function testUrlGenerationWithPrefixes() {
  501. $_back = Configure::read('Routing');
  502. Configure::write('Routing.prefixes', array('members'));
  503. Router::reload();
  504. Router::parse('/');
  505. Router::setRequestInfo(array(
  506. array('controller' => 'posts', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null),
  507. array('base' => '', 'here' => 'posts/index', 'webroot' => '/')
  508. ));
  509. $this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
  510. $this->Paginator->request->params['paging']['Article']['page'] = 2;
  511. $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
  512. $options = array('members' => true);
  513. $result = $this->Paginator->url($options);
  514. $expected = '/members/posts/index/page:2';
  515. $this->assertEquals($expected, $result);
  516. $result = $this->Paginator->sort('name', null, array('url' => $options));
  517. $expected = array(
  518. 'a' => array('href' => '/members/posts/index/page:2/sort:name/direction:asc'),
  519. 'Name',
  520. '/a'
  521. );
  522. $this->assertTags($result, $expected);
  523. $result = $this->Paginator->next('next', array('url' => $options));
  524. $expected = array(
  525. 'span' => array('class' => 'next'),
  526. 'a' => array('href' => '/members/posts/index/page:3', 'rel' => 'next'),
  527. 'next',
  528. '/a',
  529. '/span'
  530. );
  531. $this->assertTags($result, $expected);
  532. $result = $this->Paginator->prev('prev', array('url' => $options));
  533. $expected = array(
  534. 'span' => array('class' => 'prev'),
  535. 'a' => array('href' => '/members/posts/index/page:1', 'rel' => 'prev'),
  536. 'prev',
  537. '/a',
  538. '/span'
  539. );
  540. $this->assertTags($result, $expected);
  541. $options = array('members' => true, 'controller' => 'posts', 'order' => array('name' => 'desc'));
  542. $result = $this->Paginator->url($options);
  543. $expected = '/members/posts/index/page:2/sort:name/direction:desc';
  544. $this->assertEquals($expected, $result);
  545. $options = array('controller' => 'posts', 'order' => array('Article.name' => 'desc'));
  546. $result = $this->Paginator->url($options);
  547. $expected = '/posts/index/page:2/sort:Article.name/direction:desc';
  548. $this->assertEquals($expected, $result);
  549. Configure::write('Routing', $_back);
  550. }
  551. /**
  552. * testOptions method
  553. *
  554. * @return void
  555. */
  556. public function testOptions() {
  557. $this->Paginator->options('myDiv');
  558. $this->assertEquals('myDiv', $this->Paginator->options['update']);
  559. $this->Paginator->options = array();
  560. $this->Paginator->request->params = array();
  561. $options = array('paging' => array('Article' => array(
  562. 'order' => 'desc',
  563. 'sort' => 'title'
  564. )));
  565. $this->Paginator->options($options);
  566. $expected = array('Article' => array(
  567. 'order' => 'desc',
  568. 'sort' => 'title'
  569. ));
  570. $this->assertEquals($expected, $this->Paginator->request->params['paging']);
  571. $this->Paginator->options = array();
  572. $this->Paginator->request->params = array();
  573. $options = array('Article' => array(
  574. 'order' => 'desc',
  575. 'sort' => 'title'
  576. ));
  577. $this->Paginator->options($options);
  578. $this->assertEquals($expected, $this->Paginator->request->params['paging']);
  579. $options = array('paging' => array('Article' => array(
  580. 'order' => 'desc',
  581. 'sort' => 'Article.title'
  582. )));
  583. $this->Paginator->options($options);
  584. $expected = array('Article' => array(
  585. 'order' => 'desc',
  586. 'sort' => 'Article.title'
  587. ));
  588. $this->assertEquals($expected, $this->Paginator->request->params['paging']);
  589. }
  590. /**
  591. * testPassedArgsMergingWithUrlOptions method
  592. *
  593. * @return void
  594. */
  595. public function testPassedArgsMergingWithUrlOptions() {
  596. Router::reload();
  597. Router::parse('/');
  598. Router::setRequestInfo(array(
  599. array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'url' => array('url' => 'articles/index/2/foo:bar')),
  600. array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
  601. ));
  602. $this->Paginator->request->params['paging'] = array(
  603. 'Article' => array(
  604. 'page' => 1, 'current' => 3, 'count' => 13,
  605. 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
  606. 'options' => array(
  607. 'page' => 1,
  608. 'order' => array(),
  609. 'conditions' => array()
  610. ),
  611. 'paramType' => 'named'
  612. )
  613. );
  614. $this->Paginator->request->params['pass'] = array(2);
  615. $this->Paginator->request->params['named'] = array('foo' => 'bar');
  616. $this->Paginator->request->query = array('x' => 'y');
  617. $this->Paginator->beforeRender('posts/index');
  618. $result = $this->Paginator->sort('title');
  619. $expected = array(
  620. 'a' => array('href' => '/articles/index/2/page:1/foo:bar/sort:title/direction:asc?x=y'),
  621. 'Title',
  622. '/a'
  623. );
  624. $this->assertTags($result, $expected);
  625. $result = $this->Paginator->numbers();
  626. $expected = array(
  627. array('span' => array('class' => 'current')), '1', '/span',
  628. ' | ',
  629. array('span' => array()), array('a' => array('href' => '/articles/index/2/page:2/foo:bar?x=y')), '2', '/a', '/span',
  630. ' | ',
  631. array('span' => array()), array('a' => array('href' => '/articles/index/2/page:3/foo:bar?x=y')), '3', '/a', '/span',
  632. ' | ',
  633. array('span' => array()), array('a' => array('href' => '/articles/index/2/page:4/foo:bar?x=y')), '4', '/a', '/span',
  634. ' | ',
  635. array('span' => array()), array('a' => array('href' => '/articles/index/2/page:5/foo:bar?x=y')), '5', '/a', '/span',
  636. ' | ',
  637. array('span' => array()), array('a' => array('href' => '/articles/index/2/page:6/foo:bar?x=y')), '6', '/a', '/span',
  638. ' | ',
  639. array('span' => array()), array('a' => array('href' => '/articles/index/2/page:7/foo:bar?x=y')), '7', '/a', '/span',
  640. );
  641. $this->assertTags($result, $expected);
  642. $result = $this->Paginator->next('Next');
  643. $expected = array(
  644. 'span' => array('class' => 'next'),
  645. 'a' => array('href' => '/articles/index/2/page:2/foo:bar?x=y', 'rel' => 'next'),
  646. 'Next',
  647. '/a',
  648. '/span'
  649. );
  650. $this->assertTags($result, $expected);
  651. }
  652. /**
  653. * testPassedArgsMergingWithUrlOptionsParamTypeQuerystring method
  654. *
  655. * @return void
  656. */
  657. public function testPassedArgsMergingWithUrlOptionsParamTypeQuerystring() {
  658. Router::reload();
  659. Router::parse('/');
  660. Router::setRequestInfo(array(
  661. array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'url' => array('url' => 'articles/index/2/foo:bar')),
  662. array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
  663. ));
  664. $this->Paginator->request->params['paging'] = array(
  665. 'Article' => array(
  666. 'page' => 1, 'current' => 3, 'count' => 13,
  667. 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
  668. 'options' => array(
  669. 'page' => 1,
  670. 'order' => array(),
  671. 'conditions' => array()
  672. ),
  673. 'paramType' => 'querystring'
  674. )
  675. );
  676. $this->Paginator->request->params['pass'] = array(2);
  677. $this->Paginator->request->params['named'] = array('foo' => 'bar');
  678. $this->Paginator->request->query = array('x' => 'y');
  679. $this->Paginator->beforeRender('posts/index');
  680. $result = $this->Paginator->sort('title');
  681. $expected = array(
  682. 'a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=1&amp;sort=title&amp;direction=asc'),
  683. 'Title',
  684. '/a'
  685. );
  686. $this->assertTags($result, $expected);
  687. $result = $this->Paginator->numbers();
  688. $expected = array(
  689. array('span' => array('class' => 'current')), '1', '/span',
  690. ' | ',
  691. array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=2')), '2', '/a', '/span',
  692. ' | ',
  693. array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=3')), '3', '/a', '/span',
  694. ' | ',
  695. array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=4')), '4', '/a', '/span',
  696. ' | ',
  697. array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=5')), '5', '/a', '/span',
  698. ' | ',
  699. array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=6')), '6', '/a', '/span',
  700. ' | ',
  701. array('span' => array()), array('a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=7')), '7', '/a', '/span',
  702. );
  703. $this->assertTags($result, $expected);
  704. $result = $this->Paginator->next('Next');
  705. $expected = array(
  706. 'span' => array('class' => 'next'),
  707. 'a' => array('href' => '/articles/index/2/foo:bar?x=y&amp;page=2', 'rel' => 'next'),
  708. 'Next',
  709. '/a',
  710. '/span'
  711. );
  712. $this->assertTags($result, $expected);
  713. }
  714. /**
  715. * testPagingLinks method
  716. *
  717. * @return void
  718. */
  719. public function testPagingLinks() {
  720. $this->Paginator->request->params['paging'] = array(
  721. 'Client' => array(
  722. 'page' => 1,
  723. 'current' => 3,
  724. 'count' => 13,
  725. 'prevPage' => false,
  726. 'nextPage' => true,
  727. 'pageCount' => 5,
  728. 'options' => array(
  729. 'page' => 1,
  730. ),
  731. 'paramType' => 'named'
  732. )
  733. );
  734. $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
  735. $expected = array(
  736. 'span' => array('class' => 'disabled'),
  737. '&lt;&lt; Previous',
  738. '/span'
  739. );
  740. $this->assertTags($result, $expected);
  741. $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'div'));
  742. $expected = array(
  743. 'div' => array('class' => 'disabled'),
  744. '&lt;&lt; Previous',
  745. '/div'
  746. );
  747. $this->assertTags($result, $expected);
  748. $this->Paginator->request->params['paging']['Client']['page'] = 2;
  749. $this->Paginator->request->params['paging']['Client']['prevPage'] = true;
  750. $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
  751. $expected = array(
  752. 'span' => array('class' => 'prev'),
  753. 'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
  754. '&lt;&lt; Previous',
  755. '/a',
  756. '/span'
  757. );
  758. $this->assertTags($result, $expected);
  759. $result = $this->Paginator->next('Next');
  760. $expected = array(
  761. 'span' => array('class' => 'next'),
  762. 'a' => array('href' => '/index/page:3', 'rel' => 'next'),
  763. 'Next',
  764. '/a',
  765. '/span'
  766. );
  767. $this->assertTags($result, $expected);
  768. $result = $this->Paginator->next('Next', array('tag' => 'li'));
  769. $expected = array(
  770. 'li' => array('class' => 'next'),
  771. 'a' => array('href' => '/index/page:3', 'rel' => 'next'),
  772. 'Next',
  773. '/a',
  774. '/li'
  775. );
  776. $this->assertTags($result, $expected);
  777. $result = $this->Paginator->prev('<< Previous', array('escape' => true));
  778. $expected = array(
  779. 'span' => array('class' => 'prev'),
  780. 'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
  781. '&lt;&lt; Previous',
  782. '/a',
  783. '/span'
  784. );
  785. $this->assertTags($result, $expected);
  786. $result = $this->Paginator->prev('<< Previous', array('escape' => false));
  787. $expected = array(
  788. 'span' => array('class' => 'prev'),
  789. 'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
  790. 'preg:/<< Previous/',
  791. '/a',
  792. '/span'
  793. );
  794. $this->assertTags($result, $expected);
  795. $this->Paginator->request->params['paging'] = array(
  796. 'Client' => array(
  797. 'page' => 1,
  798. 'current' => 1,
  799. 'count' => 13,
  800. 'prevPage' => false,
  801. 'nextPage' => true,
  802. 'pageCount' => 5,
  803. 'options' => array(
  804. 'page' => 1,
  805. ),
  806. 'paramType' => 'named'
  807. )
  808. );
  809. $result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>');
  810. $expected = array(
  811. 'span' => array('class' => 'prev'),
  812. '&lt;strong&gt;Disabled&lt;/strong&gt;',
  813. '/span'
  814. );
  815. $this->assertTags($result, $expected);
  816. $result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => true));
  817. $expected = array(
  818. 'span' => array('class' => 'prev'),
  819. '&lt;strong&gt;Disabled&lt;/strong&gt;',
  820. '/span'
  821. );
  822. $this->assertTags($result, $expected);
  823. $result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => false));
  824. $expected = array(
  825. 'span' => array('class' => 'prev'),
  826. '<strong', 'Disabled', '/strong',
  827. '/span'
  828. );
  829. $this->assertTags($result, $expected);
  830. $this->Paginator->request->params['paging'] = array(
  831. 'Client' => array(
  832. 'page' => 1,
  833. 'current' => 3,
  834. 'count' => 13,
  835. 'prevPage' => false,
  836. 'nextPage' => true,
  837. 'pageCount' => 5,
  838. 'options' => array(
  839. 'page' => 1,
  840. 'limit' => 3,
  841. 'order' => array('Client.name' => 'DESC'),
  842. ),
  843. 'paramType' => 'named'
  844. )
  845. );
  846. $this->Paginator->request->params['paging']['Client']['page'] = 2;
  847. $this->Paginator->request->params['paging']['Client']['prevPage'] = true;
  848. $result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
  849. $expected = array(
  850. 'span' => array('class' => 'prev'),
  851. 'a' => array(
  852. 'href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC',
  853. 'rel' => 'prev'
  854. ),
  855. '&lt;&lt; Previous',
  856. '/a',
  857. '/span'
  858. );
  859. $this->assertTags($result, $expected);
  860. $result = $this->Paginator->next('Next');
  861. $expected = array(
  862. 'span' => array('class' => 'next'),
  863. 'a' => array(
  864. 'href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC',
  865. 'rel' => 'next'
  866. ),
  867. 'Next',
  868. '/a',
  869. '/span'
  870. );
  871. $this->assertTags($result, $expected);
  872. $this->Paginator->request->params['paging'] = array(
  873. 'Client' => array(
  874. 'page' => 2,
  875. 'current' => 1,
  876. 'count' => 13,
  877. 'prevPage' => true,
  878. 'nextPage' => false,
  879. 'pageCount' => 2,
  880. 'options' => array(
  881. 'page' => 2,
  882. 'limit' => 10,
  883. 'order' => array(),
  884. 'conditions' => array()
  885. ),
  886. 'paramType' => 'named'
  887. )
  888. );
  889. $result = $this->Paginator->prev('Prev');
  890. $expected = array(
  891. 'span' => array('class' => 'prev'),
  892. 'a' => array('href' => '/index/page:1/limit:10', 'rel' => 'prev'),
  893. 'Prev',
  894. '/a',
  895. '/span'
  896. );
  897. $this->assertTags($result, $expected);
  898. $this->Paginator->request->params['paging'] = array(
  899. 'Client' => array(
  900. 'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
  901. 'nextPage' => false, 'pageCount' => 2,
  902. 'defaults' => array(),
  903. 'options' => array(
  904. 'page' => 2, 'limit' => 10, 'order' => array(), 'conditions' => array()
  905. ),
  906. 'paramType' => 'named'
  907. )
  908. );
  909. $this->Paginator->options(array('url' => array(12, 'page' => 3)));
  910. $result = $this->Paginator->prev('Prev', array('url' => array('foo' => 'bar')));
  911. $expected = array(
  912. 'span' => array('class' => 'prev'),
  913. 'a' => array('href' => '/index/12/page:1/limit:10/foo:bar', 'rel' => 'prev'),
  914. 'Prev',
  915. '/a',
  916. '/span'
  917. );
  918. $this->assertTags($result, $expected);
  919. }
  920. /**
  921. * test that __pagingLink methods use $options when $disabledOptions is an empty value.
  922. * allowing you to use shortcut syntax
  923. *
  924. * @return void
  925. */
  926. public function testPagingLinksOptionsReplaceEmptyDisabledOptions() {
  927. $this->Paginator->request->params['paging'] = array(
  928. 'Client' => array(
  929. 'page' => 1,
  930. 'current' => 3,
  931. 'count' => 13,
  932. 'prevPage' => false,
  933. 'nextPage' => true,
  934. 'pageCount' => 5,
  935. 'options' => array(
  936. 'page' => 1,
  937. ),
  938. 'paramType' => 'named'
  939. )
  940. );
  941. $result = $this->Paginator->prev('<< Previous', array('escape' => false));
  942. $expected = array(
  943. 'span' => array('class' => 'prev'),
  944. 'preg:/<< Previous/',
  945. '/span'
  946. );
  947. $this->assertTags($result, $expected);
  948. $result = $this->Paginator->next('Next >>', array('escape' => false));
  949. $expected = array(
  950. 'span' => array('class' => 'next'),
  951. 'a' => array('href' => '/index/page:2', 'rel' => 'next'),
  952. 'preg:/Next >>/',
  953. '/a',
  954. '/span'
  955. );
  956. $this->assertTags($result, $expected);
  957. }
  958. /**
  959. * testPagingLinksNotDefaultModel
  960. *
  961. * Test the creation of paging links when the non default model is used.
  962. *
  963. * @return void
  964. */
  965. public function testPagingLinksNotDefaultModel() {
  966. // Multiple Model Paginate
  967. $this->Paginator->request->params['paging'] = array(
  968. 'Client' => array(
  969. 'page' => 1,
  970. 'current' => 3,
  971. 'count' => 13,
  972. 'prevPage' => false,
  973. 'nextPage' => true,
  974. 'pageCount' => 5,
  975. 'options' => array(
  976. 'page' => 1,
  977. ),
  978. 'paramType' => 'named'
  979. ),
  980. 'Server' => array(
  981. 'page' => 1,
  982. 'current' => 1,
  983. 'count' => 5,
  984. 'prevPage' => false,
  985. 'nextPage' => false,
  986. 'pageCount' => 5,
  987. 'options' => array(
  988. 'page' => 1,
  989. ),
  990. 'paramType' => 'named'
  991. )
  992. );
  993. $result = $this->Paginator->next('Next', array('model' => 'Client'));
  994. $expected = array(
  995. 'span' => array('class' => 'next'),
  996. 'a' => array('href' => '/index/page:2', 'rel' => 'next'),
  997. 'Next',
  998. '/a',
  999. '/span'
  1000. );
  1001. $this->assertTags($result, $expected);
  1002. $result = $this->Paginator->next('Next', array('model' => 'Server'), 'No Next', array('model' => 'Server'));
  1003. $expected = array(
  1004. 'span' => array('class' => 'next'), 'No Next', '/span'
  1005. );
  1006. $this->assertTags($result, $expected);
  1007. }
  1008. /**
  1009. * testGenericLinks method
  1010. *
  1011. * @return void
  1012. */
  1013. public function testGenericLinks() {
  1014. $result = $this->Paginator->link('Sort by title on page 5', array('sort' => 'title', 'page' => 5, 'direction' => 'desc'));
  1015. $expected = array(
  1016. 'a' => array('href' => '/index/page:5/sort:title/direction:desc'),
  1017. 'Sort by title on page 5',
  1018. '/a'
  1019. );
  1020. $this->assertTags($result, $expected);
  1021. $this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
  1022. $result = $this->Paginator->link('Sort by title', array('sort' => 'title', 'direction' => 'desc'));
  1023. $expected = array(
  1024. 'a' => array('href' => '/index/page:2/sort:title/direction:desc'),
  1025. 'Sort by title',
  1026. '/a'
  1027. );
  1028. $this->assertTags($result, $expected);
  1029. $this->Paginator->request->params['paging']['Article']['options']['page'] = 4;
  1030. $result = $this->Paginator->link('Sort by title on page 4', array('sort' => 'Article.title', 'direction' => 'desc'));
  1031. $expected = array(
  1032. 'a' => array('href' => '/index/page:4/sort:Article.title/direction:desc'),
  1033. 'Sort by title on page 4',
  1034. '/a'
  1035. );
  1036. $this->assertTags($result, $expected);
  1037. }
  1038. /**
  1039. * Tests generation of generic links with preset options
  1040. *
  1041. * @return void
  1042. */
  1043. public function testGenericLinksWithPresetOptions() {
  1044. $result = $this->Paginator->link('Foo!', array('page' => 1));
  1045. $this->assertTags($result, array('a' => array('href' => '/index/page:1'), 'Foo!', '/a'));
  1046. $this->Paginator->options(array('sort' => 'title', 'direction' => 'desc'));
  1047. $result = $this->Paginator->link('Foo!', array('page' => 1));
  1048. $this->assertTags($result, array(
  1049. 'a' => array(
  1050. 'href' => '/index/page:1',
  1051. 'sort' => 'title',
  1052. 'direction' => 'desc'
  1053. ),
  1054. 'Foo!',
  1055. '/a'
  1056. ));
  1057. $this->Paginator->options(array('sort' => null, 'direction' => null));
  1058. $result = $this->Paginator->link('Foo!', array('page' => 1));
  1059. $this->assertTags($result, array('a' => array('href' => '/index/page:1'), 'Foo!', '/a'));
  1060. $this->Paginator->options(array('url' => array(
  1061. 'sort' => 'title',
  1062. 'direction' => 'desc'
  1063. )));
  1064. $result = $this->Paginator->link('Foo!', array('page' => 1));
  1065. $this->assertTags($result, array(
  1066. 'a' => array('href' => '/index/page:1/sort:title/direction:desc'),
  1067. 'Foo!',
  1068. '/a'
  1069. ));
  1070. }
  1071. /**
  1072. * testNumbers method
  1073. *
  1074. * @return void
  1075. */
  1076. public function testNumbers() {
  1077. $this->Paginator->request->params['paging'] = array(
  1078. 'Client' => array(
  1079. 'page' => 8,
  1080. 'current' => 3,
  1081. 'count' => 30,
  1082. 'prevPage' => false,
  1083. 'nextPage' => 2,
  1084. 'pageCount' => 15,
  1085. 'options' => array(
  1086. 'page' => 1,
  1087. ),
  1088. 'paramType' => 'named'
  1089. )
  1090. );
  1091. $result = $this->Paginator->numbers();
  1092. $expected = array(
  1093. array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
  1094. ' | ',
  1095. array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
  1096. ' | ',
  1097. array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
  1098. ' | ',
  1099. array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
  1100. ' | ',
  1101. array('span' => array('class' => 'current')), '8', '/span',
  1102. ' | ',
  1103. array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
  1104. ' | ',
  1105. array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
  1106. ' | ',
  1107. array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
  1108. ' | ',
  1109. array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
  1110. );
  1111. $this->assertTags($result, $expected);
  1112. $result = $this->Paginator->numbers(array('tag' => 'li'));
  1113. $expected = array(
  1114. array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
  1115. ' | ',
  1116. array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
  1117. ' | ',
  1118. array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
  1119. ' | ',
  1120. array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
  1121. ' | ',
  1122. array('li' => array('class' => 'current')), '8', '/li',
  1123. ' | ',
  1124. array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
  1125. ' | ',
  1126. array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li',
  1127. ' | ',
  1128. array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li',
  1129. ' | ',
  1130. array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li',
  1131. );
  1132. $this->assertTags($result, $expected);
  1133. $result = $this->Paginator->numbers(array('tag' => 'li', 'separator' => false));
  1134. $expected = array(
  1135. array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
  1136. array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
  1137. array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
  1138. array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
  1139. array('li' => array('class' => 'current')), '8', '/li',
  1140. array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
  1141. array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li',
  1142. array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li',
  1143. array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li',
  1144. );
  1145. $this->assertTags($result, $expected);
  1146. $result = $this->Paginator->numbers(true);
  1147. $expected = array(
  1148. array('span' => array()), array('a' => array('href' => '/index/page:1', 'rel' => 'first')), 'first', '/a', '/span',
  1149. ' | ',
  1150. array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
  1151. ' | ',
  1152. array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
  1153. ' | ',
  1154. array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
  1155. ' | ',
  1156. array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
  1157. ' | ',
  1158. array('span' => array('class' => 'current')), '8', '/span',
  1159. ' | ',
  1160. array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
  1161. ' | ',
  1162. array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
  1163. ' | ',
  1164. array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
  1165. ' | ',
  1166. array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
  1167. ' | ',
  1168. array('span' => array()), array('a' => array('href' => '/index/page:15', 'rel' => 'last')), 'last', '/a', '/span',
  1169. );
  1170. $this->assertTags($result, $expected);
  1171. $this->Paginator->request->params['paging'] = array(
  1172. 'Client' => array(
  1173. 'page' => 1,
  1174. 'current' => 3,
  1175. 'count' => 30,
  1176. 'prevPage' => false,
  1177. 'nextPage' => 2,
  1178. 'pageCount' => 15,
  1179. 'options' => array(
  1180. 'page' => 1,
  1181. ),
  1182. 'paramType' => 'named'
  1183. )
  1184. );
  1185. $result = $this->Paginator->numbers();
  1186. $expected = array(
  1187. array('span' => array('class' => 'current')), '1', '/span',
  1188. ' | ',
  1189. array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
  1190. ' | ',
  1191. array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
  1192. ' | ',
  1193. array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
  1194. ' | ',
  1195. array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
  1196. ' | ',
  1197. array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
  1198. ' | ',
  1199. array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
  1200. ' | ',
  1201. array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
  1202. ' | ',
  1203. array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
  1204. );
  1205. $this->assertTags($result, $expected);
  1206. $this->Paginator->request->params['paging'] = array(
  1207. 'Client' => array(
  1208. 'page' => 14,
  1209. 'current' => 3,
  1210. 'count' => 30,
  1211. 'prevPage' => false,
  1212. 'nextPage' => 2,
  1213. 'pageCount' => 15,
  1214. 'options' => array(
  1215. 'page' => 1,
  1216. ),
  1217. 'paramType' => 'named'
  1218. )
  1219. );
  1220. $result = $this->Paginator->numbers();
  1221. $expected = array(
  1222. array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
  1223. ' | ',
  1224. array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
  1225. ' | ',
  1226. array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
  1227. ' | ',
  1228. array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span',
  1229. ' | ',
  1230. array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span',
  1231. ' | ',
  1232. array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span',
  1233. ' | ',
  1234. array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span',
  1235. ' | ',
  1236. array('span' => array('class' => 'current')), '14', '/span',
  1237. ' | ',
  1238. array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span',
  1239. );
  1240. $this->assertTags($result, $expected);
  1241. $this->Paginator->request->params['paging'] = array(
  1242. 'Client' => array(
  1243. 'page' => 2,
  1244. 'current' => 3,
  1245. 'count' => 27,
  1246. 'prevPage' => false,
  1247. 'nextPage' => 2,
  1248. 'pageCount' => 9,
  1249. 'options' => array(
  1250. 'page' => 1,
  1251. ),
  1252. 'paramType' => 'named'
  1253. )
  1254. );
  1255. $result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link'));
  1256. $expected = array(
  1257. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
  1258. ' | ',
  1259. array('span' => array('class' => 'current page-link')), '2', '/span',
  1260. ' | ',
  1261. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
  1262. ' | ',
  1263. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
  1264. ' | ',
  1265. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
  1266. ' | ',
  1267. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
  1268. ' | ',
  1269. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
  1270. ' | ',
  1271. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
  1272. ' | ',
  1273. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
  1274. );
  1275. $this->assertTags($result, $expected);
  1276. $result = $this->Paginator->numbers(array('first' => 1, 'currentClass' => 'active'));
  1277. $expected = array(
  1278. array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
  1279. ' | ',
  1280. array('span' => array('class' => 'active')), '2', '/span',
  1281. ' | ',
  1282. array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
  1283. ' | ',
  1284. array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
  1285. ' | ',
  1286. array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
  1287. ' | ',
  1288. array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
  1289. ' | ',
  1290. array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
  1291. ' | ',
  1292. array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
  1293. ' | ',
  1294. array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
  1295. );
  1296. $this->assertTags($result, $expected);
  1297. $result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link', 'currentClass' => 'active'));
  1298. $expected = array(
  1299. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
  1300. ' | ',
  1301. array('span' => array('class' => 'active page-link')), '2', '/span',
  1302. ' | ',
  1303. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
  1304. ' | ',
  1305. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
  1306. ' | ',
  1307. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
  1308. ' | ',
  1309. array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
  1310. ' | ',
  1311. array('span' => array('class' => '…

Large files files are truncated, but you can click here to view the full file