PageRenderTime 54ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/sommers/cs295
PHP | 2614 lines | 2122 code | 232 blank | 260 comment | 1 complexity | 6d202869ff4c9475f82b53b95894f757 MD5 | raw file

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

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

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