PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/udeshika/fake_twitter
PHP | 2341 lines | 1884 code | 215 blank | 242 comment | 1 complexity | 038ec9fa0a82543800e12496e55c7be2 MD5 | raw file

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/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->assertSame($this->Paginator->hasPrev(), false);
  80. $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
  81. $this->assertSame($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->assertSame($this->Paginator->hasNext(), true);
  91. $this->Paginator->request->params['paging']['Article']['nextPage'] = false;
  92. $this->assertSame($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->assertEquals($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->assertRegExp('/\/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->assertRegExp('/\/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->assertRegExp('/\/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->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
  193. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  194. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  195. $result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc'));
  196. $this->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction: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->assertRegExp('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
  201. $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  202. $this->Paginator->request->params['paging']['Article']['options']['sort'] = null;
  203. $result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc', 'class' => 'foo'));
  204. $this->assertRegExp('/\/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->assertEquals('Article.title', $result);
  323. $result = $this->Paginator->sortKey('Article', array('order' => 'Article.title'));
  324. $this->assertEquals($result, 'Article.title');
  325. $result = $this->Paginator->sortKey('Article', array('sort' => 'Article.title'));
  326. $this->assertEquals($result, 'Article.title');
  327. $result = $this->Paginator->sortKey('Article', array('sort' => 'Article'));
  328. $this->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals($expected, $result);
  372. $result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
  373. $expected = 'desc';
  374. $this->assertEquals($expected, $result);
  375. $result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
  376. $expected = 'asc';
  377. $this->assertEquals($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->assertEquals($result, '/index/page:1');
  440. $this->Paginator->request->params['paging']['Article']['options']['page'] = 2;
  441. $result = $this->Paginator->url();
  442. $this->assertEquals($result, '/index/page:2');
  443. $options = array('order' => array('Article' => 'desc'));
  444. $result = $this->Paginator->url($options);
  445. $this->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals($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->assertEquals('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->assertEquals($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->assertEquals($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->assertEquals($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',

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