PageRenderTime 41ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/cake/tests/cases/libs/view/helpers/paginator.test.php

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