PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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