PaginatorHelperTest.php 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  1. <?php
  2. /**
  3. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  12. * @since 1.2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\View\Helper;
  16. use Cake\Core\Configure;
  17. use Cake\I18n\I18n;
  18. use Cake\Network\Request;
  19. use Cake\Routing\Router;
  20. use Cake\TestSuite\TestCase;
  21. use Cake\View\Helper\PaginatorHelper;
  22. use Cake\View\View;
  23. /**
  24. * PaginatorHelperTest class
  25. *
  26. */
  27. class PaginatorHelperTest extends TestCase
  28. {
  29. /**
  30. * setUp method
  31. *
  32. * @return void
  33. */
  34. public function setUp()
  35. {
  36. parent::setUp();
  37. Configure::write('Config.language', 'eng');
  38. $this->View = new View();
  39. $this->Paginator = new PaginatorHelper($this->View);
  40. $this->Paginator->Js = $this->getMock('Cake\View\Helper\PaginatorHelper', [], [$this->View]);
  41. $this->Paginator->request = new Request();
  42. $this->Paginator->request->addParams([
  43. 'paging' => [
  44. 'Article' => [
  45. 'page' => 1,
  46. 'current' => 9,
  47. 'count' => 62,
  48. 'prevPage' => false,
  49. 'nextPage' => true,
  50. 'pageCount' => 7,
  51. 'sort' => null,
  52. 'direction' => null,
  53. 'limit' => null,
  54. ]
  55. ]
  56. ]);
  57. Configure::write('Routing.prefixes', []);
  58. Router::reload();
  59. Router::connect('/:controller/:action/*');
  60. Router::connect('/:plugin/:controller/:action/*');
  61. $this->locale = I18n::locale();
  62. }
  63. /**
  64. * tearDown method
  65. *
  66. * @return void
  67. */
  68. public function tearDown()
  69. {
  70. parent::tearDown();
  71. unset($this->View, $this->Paginator);
  72. I18n::locale($this->locale);
  73. }
  74. /**
  75. * Test the templates method.
  76. *
  77. * @return void
  78. */
  79. public function testTemplates()
  80. {
  81. $result = $this->Paginator->templates([
  82. 'test' => 'val'
  83. ]);
  84. $this->assertSame(
  85. $this->Paginator,
  86. $result,
  87. 'Setting should return the same object'
  88. );
  89. $result = $this->Paginator->templates();
  90. $this->assertArrayHasKey('test', $result);
  91. $this->assertEquals('val', $result['test']);
  92. $this->assertEquals('val', $this->Paginator->templates('test'));
  93. }
  94. /**
  95. * testHasPrevious method
  96. *
  97. * @return void
  98. */
  99. public function testHasPrevious()
  100. {
  101. $this->assertFalse($this->Paginator->hasPrev());
  102. $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
  103. $this->assertTrue($this->Paginator->hasPrev());
  104. $this->Paginator->request->params['paging']['Article']['prevPage'] = false;
  105. }
  106. /**
  107. * testHasNext method
  108. *
  109. * @return void
  110. */
  111. public function testHasNext()
  112. {
  113. $this->assertTrue($this->Paginator->hasNext());
  114. $this->Paginator->request->params['paging']['Article']['nextPage'] = false;
  115. $this->assertFalse($this->Paginator->hasNext());
  116. $this->Paginator->request->params['paging']['Article']['nextPage'] = true;
  117. }
  118. /**
  119. * testSortLinks method
  120. *
  121. * @return void
  122. */
  123. public function testSortLinks()
  124. {
  125. Router::setRequestInfo([
  126. ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'url' => ['url' => 'accounts/']],
  127. ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
  128. ]);
  129. $this->Paginator->options(['url' => ['param']]);
  130. $this->Paginator->request['paging'] = [
  131. 'Article' => [
  132. 'current' => 9,
  133. 'count' => 62,
  134. 'prevPage' => false,
  135. 'nextPage' => true,
  136. 'pageCount' => 7,
  137. 'sort' => 'date',
  138. 'direction' => 'asc',
  139. 'page' => 1,
  140. ]
  141. ];
  142. $result = $this->Paginator->sort('title');
  143. $expected = [
  144. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=asc'],
  145. 'Title',
  146. '/a'
  147. ];
  148. $this->assertHtml($expected, $result);
  149. $result = $this->Paginator->sort('title', null, ['model' => 'Nope']);
  150. $this->assertHtml($expected, $result);
  151. $result = $this->Paginator->sort('title', null, ['model' => 'Article']);
  152. $this->assertHtml($expected, $result);
  153. $result = $this->Paginator->sort('date');
  154. $expected = [
  155. 'a' => ['href' => '/accounts/index/param?sort=date&amp;direction=desc', 'class' => 'asc'],
  156. 'Date',
  157. '/a'
  158. ];
  159. $this->assertHtml($expected, $result);
  160. $result = $this->Paginator->sort('title', 'TestTitle');
  161. $expected = [
  162. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=asc'],
  163. 'TestTitle',
  164. '/a'
  165. ];
  166. $this->assertHtml($expected, $result);
  167. $result = $this->Paginator->sort('title', ['asc' => 'ascending', 'desc' => 'descending']);
  168. $expected = [
  169. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=asc'],
  170. 'ascending',
  171. '/a'
  172. ];
  173. $this->assertHtml($expected, $result);
  174. $this->Paginator->request->params['paging']['Article']['sort'] = 'title';
  175. $result = $this->Paginator->sort('title', ['asc' => 'ascending', 'desc' => 'descending']);
  176. $expected = [
  177. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=desc', 'class' => 'asc'],
  178. 'descending',
  179. '/a'
  180. ];
  181. $this->assertHtml($expected, $result);
  182. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  183. $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
  184. $result = $this->Paginator->sort('title');
  185. $expected = [
  186. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=asc', 'class' => 'desc'],
  187. 'Title',
  188. '/a'
  189. ];
  190. $this->assertHtml($expected, $result);
  191. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  192. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  193. $result = $this->Paginator->sort('title');
  194. $expected = [
  195. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=desc', 'class' => 'asc'],
  196. 'Title',
  197. '/a'
  198. ];
  199. $this->assertHtml($expected, $result);
  200. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  201. $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
  202. $result = $this->Paginator->sort('title', 'Title', ['direction' => 'desc']);
  203. $expected = [
  204. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=asc', 'class' => 'desc'],
  205. 'Title',
  206. '/a'
  207. ];
  208. $this->assertHtml($expected, $result);
  209. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  210. $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
  211. $result = $this->Paginator->sort('title', 'Title', ['direction' => 'asc']);
  212. $expected = [
  213. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=asc', 'class' => 'desc'],
  214. 'Title',
  215. '/a'
  216. ];
  217. $this->assertHtml($expected, $result);
  218. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  219. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  220. $result = $this->Paginator->sort('title', 'Title', ['direction' => 'asc']);
  221. $expected = [
  222. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=desc', 'class' => 'asc'],
  223. 'Title',
  224. '/a'
  225. ];
  226. $this->assertHtml($expected, $result);
  227. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  228. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  229. $result = $this->Paginator->sort('title', 'Title', ['direction' => 'desc']);
  230. $expected = [
  231. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=desc', 'class' => 'asc'],
  232. 'Title',
  233. '/a'
  234. ];
  235. $this->assertHtml($expected, $result);
  236. }
  237. /**
  238. * test sort() with escape option
  239. */
  240. public function testSortEscape()
  241. {
  242. $result = $this->Paginator->sort('title', 'TestTitle >');
  243. $expected = [
  244. 'a' => ['href' => '/index?sort=title&amp;direction=asc'],
  245. 'TestTitle &gt;',
  246. '/a'
  247. ];
  248. $this->assertHtml($expected, $result);
  249. $result = $this->Paginator->sort('title', 'TestTitle >', ['escape' => true]);
  250. $this->assertHtml($expected, $result);
  251. $result = $this->Paginator->sort('title', 'TestTitle >', ['escape' => false]);
  252. $expected = [
  253. 'a' => ['href' => '/index?sort=title&amp;direction=asc'],
  254. 'TestTitle >',
  255. '/a'
  256. ];
  257. $this->assertHtml($expected, $result);
  258. }
  259. /**
  260. * test that sort() works with virtual field order options.
  261. *
  262. * @return void
  263. */
  264. public function testSortLinkWithVirtualField()
  265. {
  266. Router::setRequestInfo([
  267. ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'form' => [], 'url' => ['url' => 'accounts/']],
  268. ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
  269. ]);
  270. $this->Paginator->request->params['paging']['Article']['sort'] = 'full_name';
  271. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  272. $result = $this->Paginator->sort('Article.full_name');
  273. $expected = [
  274. 'a' => ['href' => '/accounts/index?sort=Article.full_name&amp;direction=desc', 'class' => 'asc'],
  275. 'Article Full Name',
  276. '/a'
  277. ];
  278. $this->assertHtml($expected, $result);
  279. $result = $this->Paginator->sort('full_name');
  280. $expected = [
  281. 'a' => ['href' => '/accounts/index?sort=full_name&amp;direction=desc', 'class' => 'asc'],
  282. 'Full Name',
  283. '/a'
  284. ];
  285. $this->assertHtml($expected, $result);
  286. $this->Paginator->request->params['paging']['Article']['sort'] = 'full_name';
  287. $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
  288. $result = $this->Paginator->sort('Article.full_name');
  289. $expected = [
  290. 'a' => ['href' => '/accounts/index?sort=Article.full_name&amp;direction=asc', 'class' => 'desc'],
  291. 'Article Full Name',
  292. '/a'
  293. ];
  294. $this->assertHtml($expected, $result);
  295. $result = $this->Paginator->sort('full_name');
  296. $expected = [
  297. 'a' => ['href' => '/accounts/index?sort=full_name&amp;direction=asc', 'class' => 'desc'],
  298. 'Full Name',
  299. '/a'
  300. ];
  301. $this->assertHtml($expected, $result);
  302. }
  303. /**
  304. * testSortLinksUsingDirectionOption method
  305. *
  306. * @return void
  307. */
  308. public function testSortLinksUsingDirectionOption()
  309. {
  310. Router::setRequestInfo([
  311. ['plugin' => null, 'controller' => 'accounts', 'action' => 'index',
  312. 'url' => ['url' => 'accounts/', 'mod_rewrite' => 'true']],
  313. ['base' => '/', 'here' => '/accounts/', 'webroot' => '/']
  314. ]);
  315. $this->Paginator->options(['url' => ['param']]);
  316. $result = $this->Paginator->sort('title', 'TestTitle', ['direction' => 'desc']);
  317. $expected = [
  318. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=desc'],
  319. 'TestTitle',
  320. '/a'
  321. ];
  322. $this->assertHtml($expected, $result);
  323. $result = $this->Paginator->sort('title', ['asc' => 'ascending', 'desc' => 'descending'], ['direction' => 'desc']);
  324. $expected = [
  325. 'a' => ['href' => '/accounts/index/param?sort=title&amp;direction=desc'],
  326. 'descending',
  327. '/a'
  328. ];
  329. $this->assertHtml($expected, $result);
  330. }
  331. /**
  332. * testSortLinksUsingDotNotation method
  333. *
  334. * @return void
  335. */
  336. public function testSortLinksUsingDotNotation()
  337. {
  338. Router::setRequestInfo([
  339. ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []],
  340. ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
  341. ]);
  342. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  343. $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
  344. $result = $this->Paginator->sort('Article.title');
  345. $expected = [
  346. 'a' => ['href' => '/accounts/index?sort=Article.title&amp;direction=asc', 'class' => 'desc'],
  347. 'Article Title',
  348. '/a'
  349. ];
  350. $this->assertHtml($expected, $result);
  351. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  352. $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
  353. $result = $this->Paginator->sort('Article.title', 'Title');
  354. $expected = [
  355. 'a' => ['href' => '/accounts/index?sort=Article.title&amp;direction=asc', 'class' => 'desc'],
  356. 'Title',
  357. '/a'
  358. ];
  359. $this->assertHtml($expected, $result);
  360. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  361. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  362. $result = $this->Paginator->sort('Article.title', 'Title');
  363. $expected = [
  364. 'a' => ['href' => '/accounts/index?sort=Article.title&amp;direction=desc', 'class' => 'asc'],
  365. 'Title',
  366. '/a'
  367. ];
  368. $this->assertHtml($expected, $result);
  369. $this->Paginator->request->params['paging']['Article']['sort'] = 'Account.title';
  370. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  371. $result = $this->Paginator->sort('title');
  372. $expected = [
  373. 'a' => ['href' => '/accounts/index?sort=title&amp;direction=asc'],
  374. 'Title',
  375. '/a'
  376. ];
  377. $this->assertHtml($expected, $result);
  378. }
  379. /**
  380. * Test creating paging links for missing models.
  381. *
  382. * @return void
  383. */
  384. public function testPagingLinksMissingModel()
  385. {
  386. $result = $this->Paginator->sort('title', 'Title', ['model' => 'Missing']);
  387. $expected = [
  388. 'a' => ['href' => '/index?sort=title&amp;direction=asc'],
  389. 'Title',
  390. '/a'
  391. ];
  392. $this->assertHtml($expected, $result);
  393. $result = $this->Paginator->next('Next', ['model' => 'Missing']);
  394. $expected = [
  395. 'li' => ['class' => 'next disabled'],
  396. 'a' => ['href' => '', 'onclick' => 'return false;'],
  397. 'Next',
  398. '/a',
  399. '/li'
  400. ];
  401. $this->assertHtml($expected, $result);
  402. $result = $this->Paginator->prev('Prev', ['model' => 'Missing']);
  403. $expected = [
  404. 'li' => ['class' => 'prev disabled'],
  405. 'a' => ['href' => '', 'onclick' => 'return false;'],
  406. 'Prev',
  407. '/a',
  408. '/li'
  409. ];
  410. $this->assertHtml($expected, $result);
  411. }
  412. /**
  413. * testSortKey method
  414. *
  415. * @return void
  416. */
  417. public function testSortKey()
  418. {
  419. $result = $this->Paginator->sortKey('Article', ['sort' => 'Article.title']);
  420. $this->assertEquals('Article.title', $result);
  421. $result = $this->Paginator->sortKey('Article', ['sort' => 'Article']);
  422. $this->assertEquals('Article', $result);
  423. }
  424. /**
  425. * Test that sortKey falls back to the default sorting options set
  426. * in the $params which are the default pagination options.
  427. *
  428. * @return void
  429. */
  430. public function testSortKeyFallbackToParams()
  431. {
  432. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.body';
  433. $result = $this->Paginator->sortKey();
  434. $this->assertEquals('Article.body', $result);
  435. $result = $this->Paginator->sortKey('Article');
  436. $this->assertEquals('Article.body', $result);
  437. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.body';
  438. $this->Paginator->request->params['paging']['Article']['order'] = 'DESC';
  439. $result = $this->Paginator->sortKey();
  440. $this->assertEquals('Article.body', $result);
  441. $result = $this->Paginator->sortKey('Article');
  442. $this->assertEquals('Article.body', $result);
  443. }
  444. /**
  445. * testSortDir method
  446. *
  447. * @return void
  448. */
  449. public function testSortDir()
  450. {
  451. $result = $this->Paginator->sortDir();
  452. $expected = 'asc';
  453. $this->assertEquals($expected, $result);
  454. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  455. $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
  456. $result = $this->Paginator->sortDir();
  457. $this->assertEquals('desc', $result);
  458. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  459. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  460. $result = $this->Paginator->sortDir();
  461. $this->assertEquals('asc', $result);
  462. $this->Paginator->request->params['paging']['Article']['sort'] = 'title';
  463. $this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
  464. $result = $this->Paginator->sortDir();
  465. $this->assertEquals('desc', $result);
  466. $this->Paginator->request->params['paging']['Article']['sort'] = 'title';
  467. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  468. $result = $this->Paginator->sortDir();
  469. $this->assertEquals('asc', $result);
  470. unset($this->Paginator->request->params['paging']['Article']['direction']);
  471. $result = $this->Paginator->sortDir('Article', ['direction' => 'asc']);
  472. $this->assertEquals('asc', $result);
  473. $result = $this->Paginator->sortDir('Article', ['direction' => 'desc']);
  474. $this->assertEquals('desc', $result);
  475. $result = $this->Paginator->sortDir('Article', ['direction' => 'asc']);
  476. $this->assertEquals('asc', $result);
  477. }
  478. /**
  479. * Test that sortDir falls back to the default sorting options set
  480. * in the $params which are the default pagination options.
  481. *
  482. * @return void
  483. */
  484. public function testSortDirFallbackToParams()
  485. {
  486. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.body';
  487. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  488. $result = $this->Paginator->sortDir();
  489. $this->assertEquals('asc', $result);
  490. $result = $this->Paginator->sortDir('Article');
  491. $this->assertEquals('asc', $result);
  492. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.body';
  493. $this->Paginator->request->params['paging']['Article']['direction'] = 'DESC';
  494. $result = $this->Paginator->sortDir();
  495. $this->assertEquals('desc', $result);
  496. $result = $this->Paginator->sortDir('Article');
  497. $this->assertEquals('desc', $result);
  498. }
  499. /**
  500. * testSortAdminLinks method
  501. *
  502. * @return void
  503. */
  504. public function testSortAdminLinks()
  505. {
  506. Configure::write('Routing.prefixes', ['admin']);
  507. Router::reload();
  508. Router::connect('/admin/:controller/:action/*', ['prefix' => 'admin']);
  509. Router::setRequestInfo([
  510. ['controller' => 'users', 'plugin' => null, 'action' => 'index', 'prefix' => 'admin'],
  511. ['base' => '', 'here' => '/admin/users', 'webroot' => '/']
  512. ]);
  513. $this->Paginator->request->params['paging']['Article']['page'] = 1;
  514. $result = $this->Paginator->next('Next');
  515. $expected = [
  516. 'li' => ['class' => 'next'],
  517. 'a' => ['href' => '/admin/users/index?page=2', 'rel' => 'next'],
  518. 'Next',
  519. '/a',
  520. '/li'
  521. ];
  522. $this->assertHtml($expected, $result);
  523. $this->Paginator->options(['url' => ['param']]);
  524. $result = $this->Paginator->sort('title');
  525. $expected = [
  526. 'a' => ['href' => '/admin/users/index/param?sort=title&amp;direction=asc'],
  527. 'Title',
  528. '/a'
  529. ];
  530. $this->assertHtml($expected, $result);
  531. $this->Paginator->options(['url' => ['param']]);
  532. $result = $this->Paginator->sort('Article.title', 'Title');
  533. $expected = [
  534. 'a' => ['href' => '/admin/users/index/param?sort=Article.title&amp;direction=asc'],
  535. 'Title',
  536. '/a'
  537. ];
  538. $this->assertHtml($expected, $result);
  539. }
  540. /**
  541. * Test that generated URLs work without sort defined within the request
  542. *
  543. * @return void
  544. */
  545. public function testDefaultSortAndNoSort()
  546. {
  547. Router::setRequestInfo([
  548. ['plugin' => null, 'controller' => 'articles', 'action' => 'index'],
  549. ['base' => '/', 'here' => '/articles/', 'webroot' => '/']
  550. ]);
  551. $this->Paginator->request->params['paging'] = [
  552. 'Article' => [
  553. 'page' => 1, 'current' => 3, 'count' => 13,
  554. 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
  555. 'sortDefault' => 'Article.title', 'directionDefault' => 'ASC',
  556. 'sort' => null
  557. ]
  558. ];
  559. $result = $this->Paginator->next('Next');
  560. $expected = [
  561. 'li' => ['class' => 'next'],
  562. 'a' => ['rel' => 'next', 'href' => '/articles/index?page=2'],
  563. 'Next',
  564. '/a',
  565. '/li'
  566. ];
  567. $this->assertHtml($expected, $result);
  568. }
  569. /**
  570. * testUrlGeneration method
  571. *
  572. * @return void
  573. */
  574. public function testUrlGeneration()
  575. {
  576. $result = $this->Paginator->sort('controller');
  577. $expected = [
  578. 'a' => ['href' => '/index?sort=controller&amp;direction=asc'],
  579. 'Controller',
  580. '/a'
  581. ];
  582. $this->assertHtml($expected, $result);
  583. $result = $this->Paginator->generateUrl();
  584. $this->assertEquals('/index', $result);
  585. $this->Paginator->request->params['paging']['Article']['page'] = 2;
  586. $result = $this->Paginator->generateUrl();
  587. $this->assertEquals('/index?page=2', $result);
  588. $options = ['sort' => 'Article', 'direction' => 'desc'];
  589. $result = $this->Paginator->generateUrl($options);
  590. $this->assertEquals('/index?page=2&amp;sort=Article&amp;direction=desc', $result);
  591. $this->Paginator->request->params['paging']['Article']['page'] = 3;
  592. $options = ['sort' => 'Article.name', 'direction' => 'desc'];
  593. $result = $this->Paginator->generateUrl($options);
  594. $this->assertEquals('/index?page=3&amp;sort=Article.name&amp;direction=desc', $result);
  595. }
  596. /**
  597. * test URL generation with prefix routes
  598. *
  599. * @return void
  600. */
  601. public function testUrlGenerationWithPrefixes()
  602. {
  603. Configure::write('Routing.prefixes', ['members']);
  604. Router::reload();
  605. Router::connect('/members/:controller/:action/*', ['prefix' => 'members']);
  606. Router::connect('/:controller/:action/*');
  607. Router::setRequestInfo([
  608. ['controller' => 'posts', 'action' => 'index', 'plugin' => null],
  609. ['base' => '', 'here' => 'posts/index', 'webroot' => '/']
  610. ]);
  611. $this->Paginator->request->params['paging']['Article']['page'] = 2;
  612. $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
  613. $options = ['prefix' => 'members'];
  614. $result = $this->Paginator->generateUrl($options);
  615. $expected = '/members/posts/index?page=2';
  616. $this->assertEquals($expected, $result);
  617. $result = $this->Paginator->sort('name', null, ['url' => $options]);
  618. $expected = [
  619. 'a' => ['href' => '/members/posts/index?page=2&amp;sort=name&amp;direction=asc'],
  620. 'Name',
  621. '/a'
  622. ];
  623. $this->assertHtml($expected, $result);
  624. $result = $this->Paginator->next('next', ['url' => $options]);
  625. $expected = [
  626. 'li' => ['class' => 'next'],
  627. 'a' => ['href' => '/members/posts/index?page=3', 'rel' => 'next'],
  628. 'next',
  629. '/a',
  630. '/li'
  631. ];
  632. $this->assertHtml($expected, $result);
  633. $result = $this->Paginator->prev('prev', ['url' => $options]);
  634. $expected = [
  635. 'li' => ['class' => 'prev'],
  636. 'a' => ['href' => '/members/posts/index', 'rel' => 'prev'],
  637. 'prev',
  638. '/a',
  639. '/li'
  640. ];
  641. $this->assertHtml($expected, $result);
  642. $options = ['prefix' => 'members', 'controller' => 'posts', 'sort' => 'name', 'direction' => 'desc'];
  643. $result = $this->Paginator->generateUrl($options);
  644. $expected = '/members/posts/index?page=2&amp;sort=name&amp;direction=desc';
  645. $this->assertEquals($expected, $result);
  646. $options = ['controller' => 'posts', 'sort' => 'Article.name', 'direction' => 'desc'];
  647. $result = $this->Paginator->generateUrl($options);
  648. $expected = '/posts/index?page=2&amp;sort=Article.name&amp;direction=desc';
  649. $this->assertEquals($expected, $result);
  650. }
  651. /**
  652. * testOptions method
  653. *
  654. * @return void
  655. */
  656. public function testOptions()
  657. {
  658. $this->Paginator->options = [];
  659. $this->Paginator->request->params = [];
  660. $options = ['paging' => ['Article' => [
  661. 'direction' => 'desc',
  662. 'sort' => 'title'
  663. ]]];
  664. $this->Paginator->options($options);
  665. $expected = ['Article' => [
  666. 'direction' => 'desc',
  667. 'sort' => 'title'
  668. ]];
  669. $this->assertEquals($expected, $this->Paginator->request->params['paging']);
  670. $this->Paginator->options = [];
  671. $this->Paginator->request->params = [];
  672. $options = ['Article' => [
  673. 'direction' => 'desc',
  674. 'sort' => 'title'
  675. ]];
  676. $this->Paginator->options($options);
  677. $this->assertEquals($expected, $this->Paginator->request->params['paging']);
  678. $options = ['paging' => ['Article' => [
  679. 'direction' => 'desc',
  680. 'sort' => 'Article.title'
  681. ]]];
  682. $this->Paginator->options($options);
  683. $expected = ['Article' => [
  684. 'direction' => 'desc',
  685. 'sort' => 'Article.title'
  686. ]];
  687. $this->assertEquals($expected, $this->Paginator->request->params['paging']);
  688. }
  689. /**
  690. * testPassedArgsMergingWithUrlOptions method
  691. *
  692. * @return void
  693. */
  694. public function testPassedArgsMergingWithUrlOptions()
  695. {
  696. Router::setRequestInfo([
  697. ['plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => ['2']],
  698. ['base' => '/', 'here' => '/articles/', 'webroot' => '/']
  699. ]);
  700. $this->Paginator->request->params['paging'] = [
  701. 'Article' => [
  702. 'page' => 1, 'current' => 3, 'count' => 13,
  703. 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
  704. 'sort' => null, 'direction' => null,
  705. ]
  706. ];
  707. $this->Paginator->request->params['pass'] = [2];
  708. $this->Paginator->request->query = ['page' => 1, 'foo' => 'bar', 'x' => 'y', 'num' => 0, 'empty' => ''];
  709. $this->View->request = $this->Paginator->request;
  710. $this->Paginator = new PaginatorHelper($this->View);
  711. $result = $this->Paginator->sort('title');
  712. $expected = [
  713. 'a' => ['href' => '/articles/index/2?foo=bar&amp;x=y&amp;num=0&amp;sort=title&amp;direction=asc'],
  714. 'Title',
  715. '/a'
  716. ];
  717. $this->assertHtml($expected, $result);
  718. $result = $this->Paginator->numbers();
  719. $expected = [
  720. ['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
  721. ['li' => []], ['a' => ['href' => '/articles/index/2?page=2&amp;foo=bar&amp;x=y&amp;num=0']], '2', '/a', '/li',
  722. ['li' => []], ['a' => ['href' => '/articles/index/2?page=3&amp;foo=bar&amp;x=y&amp;num=0']], '3', '/a', '/li',
  723. ['li' => []], ['a' => ['href' => '/articles/index/2?page=4&amp;foo=bar&amp;x=y&amp;num=0']], '4', '/a', '/li',
  724. ['li' => []], ['a' => ['href' => '/articles/index/2?page=5&amp;foo=bar&amp;x=y&amp;num=0']], '5', '/a', '/li',
  725. ['li' => []], ['a' => ['href' => '/articles/index/2?page=6&amp;foo=bar&amp;x=y&amp;num=0']], '6', '/a', '/li',
  726. ['li' => []], ['a' => ['href' => '/articles/index/2?page=7&amp;foo=bar&amp;x=y&amp;num=0']], '7', '/a', '/li',
  727. ];
  728. $this->assertHtml($expected, $result);
  729. $result = $this->Paginator->next('Next');
  730. $expected = [
  731. 'li' => ['class' => 'next'],
  732. 'a' => ['href' => '/articles/index/2?page=2&amp;foo=bar&amp;x=y&amp;num=0', 'rel' => 'next'],
  733. 'Next',
  734. '/a',
  735. '/li'
  736. ];
  737. $this->assertHtml($expected, $result);
  738. }
  739. /**
  740. * Test that generated URLs don't include sort and direction parameters
  741. *
  742. * @return void
  743. */
  744. public function testDefaultSortRemovedFromUrl()
  745. {
  746. Router::setRequestInfo([
  747. ['plugin' => null, 'controller' => 'articles', 'action' => 'index'],
  748. ['base' => '/', 'here' => '/articles/', 'webroot' => '/']
  749. ]);
  750. $this->Paginator->request->params['paging'] = [
  751. 'Article' => [
  752. 'page' => 1, 'current' => 3, 'count' => 13,
  753. 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
  754. 'sort' => 'Article.title', 'direction' => 'ASC',
  755. 'sortDefault' => 'Article.title', 'directionDefault' => 'ASC'
  756. ]
  757. ];
  758. $result = $this->Paginator->next('Next');
  759. $expected = [
  760. 'li' => ['class' => 'next'],
  761. 'a' => ['rel' => 'next', 'href' => '/articles/index?page=2'],
  762. 'Next',
  763. '/a',
  764. '/li'
  765. ];
  766. $this->assertHtml($expected, $result);
  767. }
  768. /**
  769. * Test the prev() method.
  770. *
  771. * @return void
  772. */
  773. public function testPrev()
  774. {
  775. $this->Paginator->request->params['paging'] = [
  776. 'Client' => [
  777. 'page' => 1,
  778. 'current' => 3,
  779. 'count' => 13,
  780. 'prevPage' => false,
  781. 'nextPage' => true,
  782. 'pageCount' => 5,
  783. ]
  784. ];
  785. $result = $this->Paginator->prev('<< Previous');
  786. $expected = [
  787. 'li' => ['class' => 'prev disabled'],
  788. 'a' => ['href' => '', 'onclick' => 'return false;'],
  789. '&lt;&lt; Previous',
  790. '/a',
  791. '/li'
  792. ];
  793. $this->assertHtml($expected, $result);
  794. $result = $this->Paginator->prev('<< Previous', ['disabledTitle' => 'Prev']);
  795. $expected = [
  796. 'li' => ['class' => 'prev disabled'],
  797. 'a' => ['href' => '', 'onclick' => 'return false;'],
  798. 'Prev',
  799. '/a',
  800. '/li'
  801. ];
  802. $this->assertHtml($expected, $result);
  803. $result = $this->Paginator->prev('<< Previous', ['disabledTitle' => false]);
  804. $this->assertEquals('', $result, 'disabled + no text = no link');
  805. $this->Paginator->request->params['paging']['Client']['page'] = 2;
  806. $this->Paginator->request->params['paging']['Client']['prevPage'] = true;
  807. $result = $this->Paginator->prev('<< Previous');
  808. $expected = [
  809. 'li' => ['class' => 'prev'],
  810. 'a' => ['href' => '/index', 'rel' => 'prev'],
  811. '&lt;&lt; Previous',
  812. '/a',
  813. '/li'
  814. ];
  815. $this->assertHtml($expected, $result);
  816. }
  817. /**
  818. * Test that prev() and the shared implementation underneath picks up from optins
  819. *
  820. * @return void
  821. */
  822. public function testPrevWithOptions()
  823. {
  824. $this->Paginator->request->params['paging'] = [
  825. 'Client' => [
  826. 'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
  827. 'nextPage' => false, 'pageCount' => 2,
  828. 'limit' => 10,
  829. ]
  830. ];
  831. $this->Paginator->options(['url' => [12, 'page' => 3]]);
  832. $result = $this->Paginator->prev('Prev', ['url' => ['foo' => 'bar']]);
  833. $expected = [
  834. 'li' => ['class' => 'prev'],
  835. 'a' => ['href' => '/index/12?limit=10&amp;foo=bar', 'rel' => 'prev'],
  836. 'Prev',
  837. '/a',
  838. '/li'
  839. ];
  840. $this->assertHtml($expected, $result);
  841. }
  842. /**
  843. * test the next() method.
  844. *
  845. * @return void
  846. */
  847. public function testNext()
  848. {
  849. $result = $this->Paginator->next('Next >>');
  850. $expected = [
  851. 'li' => ['class' => 'next'],
  852. 'a' => ['href' => '/index?page=2', 'rel' => 'next'],
  853. 'Next &gt;&gt;',
  854. '/a',
  855. '/li'
  856. ];
  857. $this->assertHtml($expected, $result);
  858. $result = $this->Paginator->next('Next >>', ['escape' => false]);
  859. $expected = [
  860. 'li' => ['class' => 'next'],
  861. 'a' => ['href' => '/index?page=2', 'rel' => 'next'],
  862. 'preg:/Next >>/',
  863. '/a',
  864. '/li'
  865. ];
  866. $this->assertHtml($expected, $result);
  867. }
  868. /**
  869. * test next() with disabled links
  870. *
  871. * @return void
  872. */
  873. public function testNextDisabled()
  874. {
  875. $this->Paginator->request->params['paging'] = [
  876. 'Client' => [
  877. 'page' => 5,
  878. 'current' => 3,
  879. 'count' => 13,
  880. 'prevPage' => true,
  881. 'nextPage' => false,
  882. 'pageCount' => 5,
  883. ]
  884. ];
  885. $result = $this->Paginator->next('Next >>');
  886. $expected = [
  887. 'li' => ['class' => 'next disabled'],
  888. 'a' => ['href' => '', 'onclick' => 'return false;'],
  889. 'Next &gt;&gt;',
  890. '/a',
  891. '/li'
  892. ];
  893. $this->assertHtml($expected, $result);
  894. $result = $this->Paginator->next('Next >>', ['disabledTitle' => 'Next']);
  895. $expected = [
  896. 'li' => ['class' => 'next disabled'],
  897. 'a' => ['href' => '', 'onclick' => 'return false;'],
  898. 'Next',
  899. '/a',
  900. '/li'
  901. ];
  902. $this->assertHtml($expected, $result);
  903. $result = $this->Paginator->next('Next >>', ['disabledTitle' => false]);
  904. $this->assertEquals('', $result, 'disabled + no text = no link');
  905. }
  906. /**
  907. * Test next() with a model argument.
  908. *
  909. * @return void
  910. */
  911. public function testNextAndPrevNonDefaultModel()
  912. {
  913. $this->Paginator->request->params['paging'] = [
  914. 'Client' => [
  915. 'page' => 1,
  916. 'current' => 3,
  917. 'count' => 13,
  918. 'prevPage' => false,
  919. 'nextPage' => true,
  920. 'pageCount' => 5,
  921. ],
  922. 'Server' => [
  923. 'page' => 5,
  924. 'current' => 1,
  925. 'count' => 5,
  926. 'prevPage' => true,
  927. 'nextPage' => false,
  928. 'pageCount' => 5,
  929. ]
  930. ];
  931. $result = $this->Paginator->next('Next', [
  932. 'model' => 'Client'
  933. ]);
  934. $expected = [
  935. 'li' => ['class' => 'next'],
  936. 'a' => ['href' => '/index?page=2', 'rel' => 'next'],
  937. 'Next',
  938. '/a',
  939. '/li'
  940. ];
  941. $this->assertHtml($expected, $result);
  942. $result = $this->Paginator->prev('Prev', [
  943. 'model' => 'Client'
  944. ]);
  945. $expected = '<li class="prev disabled"><a href="" onclick="return false;">Prev</a></li>';
  946. $this->assertEquals($expected, $result);
  947. $result = $this->Paginator->next('Next', [
  948. 'model' => 'Server'
  949. ]);
  950. $expected = '<li class="next disabled"><a href="" onclick="return false;">Next</a></li>';
  951. $this->assertEquals($expected, $result);
  952. $result = $this->Paginator->prev('Prev', [
  953. 'model' => 'Server'
  954. ]);
  955. $expected = [
  956. 'li' => ['class' => 'prev'],
  957. 'a' => ['href' => '/index?page=4', 'rel' => 'prev'],
  958. 'Prev',
  959. '/a',
  960. '/li'
  961. ];
  962. $this->assertHtml($expected, $result);
  963. }
  964. /**
  965. * testNumbers method
  966. *
  967. * @return void
  968. */
  969. public function testNumbers()
  970. {
  971. $this->Paginator->request->params['paging'] = [
  972. 'Client' => [
  973. 'page' => 8,
  974. 'current' => 3,
  975. 'count' => 30,
  976. 'prevPage' => false,
  977. 'nextPage' => 2,
  978. 'pageCount' => 15,
  979. ]
  980. ];
  981. $result = $this->Paginator->numbers();
  982. $expected = [
  983. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  984. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  985. ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
  986. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  987. ['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
  988. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  989. ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
  990. ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
  991. ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
  992. ];
  993. $this->assertHtml($expected, $result);
  994. $result = $this->Paginator->numbers(['first' => 'first', 'last' => 'last']);
  995. $expected = [
  996. ['li' => ['class' => 'first']], ['a' => ['href' => '/index']], 'first', '/a', '/li',
  997. ['li' => ['class' => 'ellipsis']], '...', '/li',
  998. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  999. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  1000. ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
  1001. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1002. ['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
  1003. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  1004. ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
  1005. ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
  1006. ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
  1007. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1008. ['li' => ['class' => 'last']], ['a' => ['href' => '/index?page=15']], 'last', '/a', '/li',
  1009. ];
  1010. $this->assertHtml($expected, $result);
  1011. $this->Paginator->request->params['paging'] = [
  1012. 'Client' => [
  1013. 'page' => 1,
  1014. 'current' => 3,
  1015. 'count' => 30,
  1016. 'prevPage' => false,
  1017. 'nextPage' => 2,
  1018. 'pageCount' => 15,
  1019. ]
  1020. ];
  1021. $result = $this->Paginator->numbers();
  1022. $expected = [
  1023. ['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
  1024. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1025. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1026. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1027. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  1028. ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
  1029. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1030. ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
  1031. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  1032. ];
  1033. $this->assertHtml($expected, $result);
  1034. $this->Paginator->request->params['paging'] = [
  1035. 'Client' => [
  1036. 'page' => 14,
  1037. 'current' => 3,
  1038. 'count' => 30,
  1039. 'prevPage' => false,
  1040. 'nextPage' => 2,
  1041. 'pageCount' => 15,
  1042. ]
  1043. ];
  1044. $result = $this->Paginator->numbers();
  1045. $expected = [
  1046. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1047. ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
  1048. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  1049. ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
  1050. ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
  1051. ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
  1052. ['li' => []], ['a' => ['href' => '/index?page=13']], '13', '/a', '/li',
  1053. ['li' => ['class' => 'active']], '<a href=""', '14', '/a', '/li',
  1054. ['li' => []], ['a' => ['href' => '/index?page=15']], '15', '/a', '/li',
  1055. ];
  1056. $this->assertHtml($expected, $result);
  1057. $this->Paginator->request->params['paging'] = [
  1058. 'Client' => [
  1059. 'page' => 2,
  1060. 'current' => 3,
  1061. 'count' => 27,
  1062. 'prevPage' => false,
  1063. 'nextPage' => 2,
  1064. 'pageCount' => 9,
  1065. ]
  1066. ];
  1067. $result = $this->Paginator->numbers(['first' => 1]);
  1068. $expected = [
  1069. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1070. ['li' => ['class' => 'active']], '<a href=""', '2', '/a', '/li',
  1071. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1072. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1073. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  1074. ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
  1075. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1076. ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
  1077. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  1078. ];
  1079. $this->assertHtml($expected, $result);
  1080. $result = $this->Paginator->numbers(['last' => 1]);
  1081. $expected = [
  1082. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1083. ['li' => ['class' => 'active']], '<a href=""', '2', '/a', '/li',
  1084. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1085. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1086. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  1087. ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
  1088. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1089. ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
  1090. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  1091. ];
  1092. $this->assertHtml($expected, $result);
  1093. $this->Paginator->request->params['paging'] = [
  1094. 'Client' => [
  1095. 'page' => 15,
  1096. 'current' => 3,
  1097. 'count' => 30,
  1098. 'prevPage' => false,
  1099. 'nextPage' => 2,
  1100. 'pageCount' => 15,
  1101. ]
  1102. ];
  1103. $result = $this->Paginator->numbers(['first' => 1]);
  1104. $expected = [
  1105. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1106. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1107. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1108. ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
  1109. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  1110. ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
  1111. ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
  1112. ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
  1113. ['li' => []], ['a' => ['href' => '/index?page=13']], '13', '/a', '/li',
  1114. ['li' => []], ['a' => ['href' => '/index?page=14']], '14', '/a', '/li',
  1115. ['li' => ['class' => 'active']], '<a href=""', '15', '/a', '/li',
  1116. ];
  1117. $this->assertHtml($expected, $result);
  1118. $this->Paginator->request->params['paging'] = [
  1119. 'Client' => [
  1120. 'page' => 10,
  1121. 'current' => 3,
  1122. 'count' => 30,
  1123. 'prevPage' => false,
  1124. 'nextPage' => 2,
  1125. 'pageCount' => 15,
  1126. ]
  1127. ];
  1128. $result = $this->Paginator->numbers(['first' => 1, 'last' => 1]);
  1129. $expected = [
  1130. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1131. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1132. ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
  1133. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1134. ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
  1135. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  1136. ['li' => ['class' => 'active']], '<a href=""', '10', '/a', '/li',
  1137. ['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
  1138. ['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
  1139. ['li' => []], ['a' => ['href' => '/index?page=13']], '13', '/a', '/li',
  1140. ['li' => []], ['a' => ['href' => '/index?page=14']], '14', '/a', '/li',
  1141. ['li' => []], ['a' => ['href' => '/index?page=15']], '15', '/a', '/li',
  1142. ];
  1143. $this->assertHtml($expected, $result);
  1144. $this->Paginator->request->params['paging'] = [
  1145. 'Client' => [
  1146. 'page' => 6,
  1147. 'current' => 15,
  1148. 'count' => 623,
  1149. 'prevPage' => 1,
  1150. 'nextPage' => 1,
  1151. 'pageCount' => 42,
  1152. ]
  1153. ];
  1154. $result = $this->Paginator->numbers(['first' => 1, 'last' => 1]);
  1155. $expected = [
  1156. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1157. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1158. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1159. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1160. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  1161. ['li' => ['class' => 'active']], '<a href=""', '6', '/a', '/li',
  1162. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1163. ['li' => []], ['a' => ['href' => '/index?page=8']], '8', '/a', '/li',
  1164. ['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
  1165. ['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
  1166. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1167. ['li' => []], ['a' => ['href' => '/index?page=42']], '42', '/a', '/li',
  1168. ];
  1169. $this->assertHtml($expected, $result);
  1170. $this->Paginator->request->params['paging'] = [
  1171. 'Client' => [
  1172. 'page' => 37,
  1173. 'current' => 15,
  1174. 'count' => 623,
  1175. 'prevPage' => 1,
  1176. 'nextPage' => 1,
  1177. 'pageCount' => 42,
  1178. ]
  1179. ];
  1180. $result = $this->Paginator->numbers(['first' => 1, 'last' => 1]);
  1181. $expected = [
  1182. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1183. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1184. ['li' => []], ['a' => ['href' => '/index?page=33']], '33', '/a', '/li',
  1185. ['li' => []], ['a' => ['href' => '/index?page=34']], '34', '/a', '/li',
  1186. ['li' => []], ['a' => ['href' => '/index?page=35']], '35', '/a', '/li',
  1187. ['li' => []], ['a' => ['href' => '/index?page=36']], '36', '/a', '/li',
  1188. ['li' => ['class' => 'active']], '<a href=""', '37', '/a', '/li',
  1189. ['li' => []], ['a' => ['href' => '/index?page=38']], '38', '/a', '/li',
  1190. ['li' => []], ['a' => ['href' => '/index?page=39']], '39', '/a', '/li',
  1191. ['li' => []], ['a' => ['href' => '/index?page=40']], '40', '/a', '/li',
  1192. ['li' => []], ['a' => ['href' => '/index?page=41']], '41', '/a', '/li',
  1193. ['li' => []], ['a' => ['href' => '/index?page=42']], '42', '/a', '/li',
  1194. ];
  1195. $this->assertHtml($expected, $result);
  1196. }
  1197. /**
  1198. * Test that numbers() lets you overwrite templates.
  1199. *
  1200. * The templates file has no li elements.
  1201. *
  1202. * @return void
  1203. */
  1204. public function testNumbersTemplates()
  1205. {
  1206. $this->Paginator->request->params['paging'] = [
  1207. 'Client' => [
  1208. 'page' => 8,
  1209. 'current' => 3,
  1210. 'count' => 30,
  1211. 'prevPage' => false,
  1212. 'nextPage' => 2,
  1213. 'pageCount' => 15,
  1214. ]
  1215. ];
  1216. $result = $this->Paginator->numbers(['templates' => 'htmlhelper_tags']);
  1217. $expected = [
  1218. ['a' => ['href' => '/index?page=4']], '4', '/a',
  1219. ['a' => ['href' => '/index?page=5']], '5', '/a',
  1220. ['a' => ['href' => '/index?page=6']], '6', '/a',
  1221. ['a' => ['href' => '/index?page=7']], '7', '/a',
  1222. 'span' => ['class' => 'active'], '8', '/span',
  1223. ['a' => ['href' => '/index?page=9']], '9', '/a',
  1224. ['a' => ['href' => '/index?page=10']], '10', '/a',
  1225. ['a' => ['href' => '/index?page=11']], '11', '/a',
  1226. ['a' => ['href' => '/index?page=12']], '12', '/a',
  1227. ];
  1228. $this->assertHtml($expected, $result);
  1229. $this->assertContains(
  1230. '<li',
  1231. $this->Paginator->templater()->get('current'),
  1232. 'Templates were not restored.'
  1233. );
  1234. }
  1235. /**
  1236. * Test modulus option for numbers()
  1237. *
  1238. * @return void
  1239. */
  1240. public function testNumbersModulus()
  1241. {
  1242. $this->Paginator->request->params['paging'] = [
  1243. 'Client' => [
  1244. 'page' => 1,
  1245. 'current' => 10,
  1246. 'count' => 30,
  1247. 'prevPage' => false,
  1248. 'nextPage' => 2,
  1249. 'pageCount' => 3,
  1250. ]
  1251. ];
  1252. $options = ['modulus' => 10];
  1253. $result = $this->Paginator->numbers($options);
  1254. $expected = [
  1255. ['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
  1256. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1257. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1258. ];
  1259. $this->assertHtml($expected, $result);
  1260. $result = $this->Paginator->numbers(['modulus' => 3]);
  1261. $expected = [
  1262. ['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
  1263. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1264. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1265. ];
  1266. $this->assertHtml($expected, $result);
  1267. $this->Paginator->request->params['paging'] = [
  1268. 'Client' => [
  1269. 'page' => 4895,
  1270. 'current' => 10,
  1271. 'count' => 48962,
  1272. 'prevPage' => 1,
  1273. 'nextPage' => 1,
  1274. 'pageCount' => 4897,
  1275. ]
  1276. ];
  1277. $result = $this->Paginator->numbers(['first' => 2, 'modulus' => 2, 'last' => 2]);
  1278. $expected = [
  1279. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1280. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1281. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1282. ['li' => []], ['a' => ['href' => '/index?page=4894']], '4894', '/a', '/li',
  1283. ['li' => ['class' => 'active']], '<a href=""', '4895', '/a', '/li',
  1284. ['li' => []], ['a' => ['href' => '/index?page=4896']], '4896', '/a', '/li',
  1285. ['li' => []], ['a' => ['href' => '/index?page=4897']], '4897', '/a', '/li',
  1286. ];
  1287. $this->assertHtml($expected, $result);
  1288. $this->Paginator->request->params['paging']['Client']['page'] = 3;
  1289. $result = $this->Paginator->numbers(['first' => 2, 'modulus' => 2, 'last' => 2]);
  1290. $expected = [
  1291. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1292. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1293. ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
  1294. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1295. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1296. ['li' => []], ['a' => ['href' => '/index?page=4896']], '4896', '/a', '/li',
  1297. ['li' => []], ['a' => ['href' => '/index?page=4897']], '4897', '/a', '/li',
  1298. ];
  1299. $this->assertHtml($expected, $result);
  1300. $result = $this->Paginator->numbers(['first' => 2, 'modulus' => 2, 'last' => 2]);
  1301. $expected = [
  1302. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1303. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1304. ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
  1305. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1306. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1307. ['li' => []], ['a' => ['href' => '/index?page=4896']], '4896', '/a', '/li',
  1308. ['li' => []], ['a' => ['href' => '/index?page=4897']], '4897', '/a', '/li',
  1309. ];
  1310. $this->assertHtml($expected, $result);
  1311. $result = $this->Paginator->numbers(['first' => 5, 'modulus' => 5, 'last' => 5]);
  1312. $expected = [
  1313. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1314. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1315. ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
  1316. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1317. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  1318. ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
  1319. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1320. ['li' => []], ['a' => ['href' => '/index?page=4893']], '4893', '/a', '/li',
  1321. ['li' => []], ['a' => ['href' => '/index?page=4894']], '4894', '/a', '/li',
  1322. ['li' => []], ['a' => ['href' => '/index?page=4895']], '4895', '/a', '/li',
  1323. ['li' => []], ['a' => ['href' => '/index?page=4896']], '4896', '/a', '/li',
  1324. ['li' => []], ['a' => ['href' => '/index?page=4897']], '4897', '/a', '/li',
  1325. ];
  1326. $this->assertHtml($expected, $result);
  1327. $this->Paginator->request->params['paging']['Client']['page'] = 4893;
  1328. $result = $this->Paginator->numbers(['first' => 5, 'modulus' => 4, 'last' => 5]);
  1329. $expected = [
  1330. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1331. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1332. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1333. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1334. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  1335. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1336. ['li' => []], ['a' => ['href' => '/index?page=4891']], '4891', '/a', '/li',
  1337. ['li' => []], ['a' => ['href' => '/index?page=4892']], '4892', '/a', '/li',
  1338. ['li' => ['class' => 'active']], '<a href=""', '4893', '/a', '/li',
  1339. ['li' => []], ['a' => ['href' => '/index?page=4894']], '4894', '/a', '/li',
  1340. ['li' => []], ['a' => ['href' => '/index?page=4895']], '4895', '/a', '/li',
  1341. ['li' => []], ['a' => ['href' => '/index?page=4896']], '4896', '/a', '/li',
  1342. ['li' => []], ['a' => ['href' => '/index?page=4897']], '4897', '/a', '/li',
  1343. ];
  1344. $this->assertHtml($expected, $result);
  1345. $this->Paginator->request->params['paging']['Client']['page'] = 58;
  1346. $result = $this->Paginator->numbers(['first' => 5, 'modulus' => 4, 'last' => 5]);
  1347. $expected = [
  1348. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1349. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1350. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1351. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1352. ['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
  1353. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1354. ['li' => []], ['a' => ['href' => '/index?page=56']], '56', '/a', '/li',
  1355. ['li' => []], ['a' => ['href' => '/index?page=57']], '57', '/a', '/li',
  1356. ['li' => ['class' => 'active']], '<a href=""', '58', '/a', '/li',
  1357. ['li' => []], ['a' => ['href' => '/index?page=59']], '59', '/a', '/li',
  1358. ['li' => []], ['a' => ['href' => '/index?page=60']], '60', '/a', '/li',
  1359. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1360. ['li' => []], ['a' => ['href' => '/index?page=4893']], '4893', '/a', '/li',
  1361. ['li' => []], ['a' => ['href' => '/index?page=4894']], '4894', '/a', '/li',
  1362. ['li' => []], ['a' => ['href' => '/index?page=4895']], '4895', '/a', '/li',
  1363. ['li' => []], ['a' => ['href' => '/index?page=4896']], '4896', '/a', '/li',
  1364. ['li' => []], ['a' => ['href' => '/index?page=4897']], '4897', '/a', '/li',
  1365. ];
  1366. $this->assertHtml($expected, $result);
  1367. $this->Paginator->request->params['paging']['Client']['page'] = 5;
  1368. $result = $this->Paginator->numbers(['first' => 5, 'modulus' => 4, 'last' => 5]);
  1369. $expected = [
  1370. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1371. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1372. ['li' => []], ['a' => ['href' => '/index?page=3']], '3', '/a', '/li',
  1373. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1374. ['li' => ['class' => 'active']], '<a href=""', '5', '/a', '/li',
  1375. ['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
  1376. ['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
  1377. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1378. ['li' => []], ['a' => ['href' => '/index?page=4893']], '4893', '/a', '/li',
  1379. ['li' => []], ['a' => ['href' => '/index?page=4894']], '4894', '/a', '/li',
  1380. ['li' => []], ['a' => ['href' => '/index?page=4895']], '4895', '/a', '/li',
  1381. ['li' => []], ['a' => ['href' => '/index?page=4896']], '4896', '/a', '/li',
  1382. ['li' => []], ['a' => ['href' => '/index?page=4897']], '4897', '/a', '/li',
  1383. ];
  1384. $this->assertHtml($expected, $result);
  1385. $this->Paginator->request->params['paging']['Client']['page'] = 3;
  1386. $result = $this->Paginator->numbers(['first' => 2, 'modulus' => 2, 'last' => 2]);
  1387. $expected = [
  1388. ['li' => []], ['a' => ['href' => '/index']], '1', '/a', '/li',
  1389. ['li' => []], ['a' => ['href' => '/index?page=2']], '2', '/a', '/li',
  1390. ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
  1391. ['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
  1392. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1393. ['li' => []], ['a' => ['href' => '/index?page=4896']], '4896', '/a', '/li',
  1394. ['li' => []], ['a' => ['href' => '/index?page=4897']], '4897', '/a', '/li',
  1395. ];
  1396. $this->assertHtml($expected, $result);
  1397. }
  1398. /**
  1399. * Test that numbers() with url options.
  1400. *
  1401. * @return void
  1402. */
  1403. public function testNumbersWithUrlOptions()
  1404. {
  1405. $this->Paginator->request->params['paging'] = [
  1406. 'Client' => [
  1407. 'page' => 8,
  1408. 'current' => 3,
  1409. 'count' => 30,
  1410. 'prevPage' => false,
  1411. 'nextPage' => 2,
  1412. 'pageCount' => 15,
  1413. ]
  1414. ];
  1415. $result = $this->Paginator->numbers(['url' => ['#' => 'foo']]);
  1416. $expected = [
  1417. ['li' => []], ['a' => ['href' => '/index?page=4#foo']], '4', '/a', '/li',
  1418. ['li' => []], ['a' => ['href' => '/index?page=5#foo']], '5', '/a', '/li',
  1419. ['li' => []], ['a' => ['href' => '/index?page=6#foo']], '6', '/a', '/li',
  1420. ['li' => []], ['a' => ['href' => '/index?page=7#foo']], '7', '/a', '/li',
  1421. ['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
  1422. ['li' => []], ['a' => ['href' => '/index?page=9#foo']], '9', '/a', '/li',
  1423. ['li' => []], ['a' => ['href' => '/index?page=10#foo']], '10', '/a', '/li',
  1424. ['li' => []], ['a' => ['href' => '/index?page=11#foo']], '11', '/a', '/li',
  1425. ['li' => []], ['a' => ['href' => '/index?page=12#foo']], '12', '/a', '/li',
  1426. ];
  1427. $this->assertHtml($expected, $result);
  1428. $this->Paginator->request->params['paging'] = [
  1429. 'Client' => [
  1430. 'page' => 3,
  1431. 'current' => 10,
  1432. 'count' => 48962,
  1433. 'prevPage' => 1,
  1434. 'nextPage' => 1,
  1435. 'pageCount' => 4897,
  1436. ]
  1437. ];
  1438. $result = $this->Paginator->numbers([
  1439. 'first' => 2,
  1440. 'modulus' => 2,
  1441. 'last' => 2,
  1442. 'url' => ['foo' => 'bar']]);
  1443. $expected = [
  1444. ['li' => []], ['a' => ['href' => '/index?foo=bar']], '1', '/a', '/li',
  1445. ['li' => []], ['a' => ['href' => '/index?page=2&amp;foo=bar']], '2', '/a', '/li',
  1446. ['li' => ['class' => 'active']], '<a href=""', '3', '/a', '/li',
  1447. ['li' => []], ['a' => ['href' => '/index?page=4&amp;foo=bar']], '4', '/a', '/li',
  1448. ['li' => ['class' => 'ellipsis']], '...', '/li',
  1449. ['li' => []], ['a' => ['href' => '/index?page=4896&amp;foo=bar']], '4896', '/a', '/li',
  1450. ['li' => []], ['a' => ['href' => '/index?page=4897&amp;foo=bar']], '4897', '/a', '/li',
  1451. ];
  1452. $this->assertHtml($expected, $result);
  1453. }
  1454. /**
  1455. * test numbers() with routing parameters.
  1456. *
  1457. * @return void
  1458. */
  1459. public function testNumbersRouting()
  1460. {
  1461. $this->Paginator->request->params['paging'] = [
  1462. 'Client' => [
  1463. 'page' => 2,
  1464. 'current' => 2,
  1465. 'count' => 30,
  1466. 'prevPage' => false,
  1467. 'nextPage' => 3,
  1468. 'pageCount' => 3,
  1469. ]
  1470. ];
  1471. $request = new Request();
  1472. $request->addParams([
  1473. 'controller' => 'clients', 'action' => 'index', 'plugin' => null
  1474. ]);
  1475. $request->base = '';
  1476. $request->here = '/clients/index?page=2';
  1477. $request->webroot = '/';
  1478. Router::setRequestInfo($request);
  1479. $result = $this->Paginator->numbers();
  1480. $expected = [
  1481. ['li' => []], ['a' => ['href' => '/clients/index']], '1', '/a', '/li',
  1482. ['li' => ['class' => 'active']], '<a href=""', '2', '/a', '/li',
  1483. ['li' => []], ['a' => ['href' => '/clients/index?page=3']], '3', '/a', '/li',
  1484. ];
  1485. $this->assertHtml($expected, $result);
  1486. }
  1487. /**
  1488. * Test that numbers() works with the non default model.
  1489. *
  1490. * @return void
  1491. */
  1492. public function testNumbersNonDefaultModel()
  1493. {
  1494. $this->Paginator->request->params['paging'] = [
  1495. 'Client' => [
  1496. 'page' => 1,
  1497. 'current' => 3,
  1498. 'count' => 13,
  1499. 'prevPage' => false,
  1500. 'nextPage' => true,
  1501. 'pageCount' => 5,
  1502. ],
  1503. 'Server' => [
  1504. 'page' => 5,
  1505. 'current' => 1,
  1506. 'count' => 5,
  1507. 'prevPage' => true,
  1508. 'nextPage' => false,
  1509. 'pageCount' => 5,
  1510. ]
  1511. ];
  1512. $result = $this->Paginator->numbers(['model' => 'Server']);
  1513. $this->assertContains('<li class="active"><a href="">5</a></li>', $result);
  1514. $this->assertNotContains('<li class="active"><a href="">1</a></li>', $result);
  1515. $result = $this->Paginator->numbers(['model' => 'Client']);
  1516. $this->assertContains('<li class="active"><a href="">1</a></li>', $result);
  1517. $this->assertNotContains('<li class="active"><a href="">5</a></li>', $result);
  1518. }
  1519. /**
  1520. * test first() and last() with tag options
  1521. *
  1522. * @return void
  1523. */
  1524. public function testFirstAndLastTag()
  1525. {
  1526. $this->Paginator->request->params['paging']['Article']['page'] = 2;
  1527. $result = $this->Paginator->first('<<');
  1528. $expected = [
  1529. 'li' => ['class' => 'first'],
  1530. 'a' => ['href' => '/index'],
  1531. '&lt;&lt;',
  1532. '/a',
  1533. '/li'
  1534. ];
  1535. $this->assertHtml($expected, $result);
  1536. $result = $this->Paginator->last(2);
  1537. $expected = [
  1538. '<li',
  1539. ['a' => ['href' => '/index?page=6']], '6', '/a',
  1540. '/li',
  1541. '<li',
  1542. ['a' => ['href' => '/index?page=7']], '7', '/a',
  1543. '/li',
  1544. ];
  1545. $this->assertHtml($expected, $result);
  1546. }
  1547. /**
  1548. * test that on the last page you don't get a link ot the last page.
  1549. *
  1550. * @return void
  1551. */
  1552. public function testLastNoOutput()
  1553. {
  1554. $this->Paginator->request->params['paging']['Article']['page'] = 15;
  1555. $this->Paginator->request->params['paging']['Article']['pageCount'] = 15;
  1556. $result = $this->Paginator->last();
  1557. $expected = '';
  1558. $this->assertEquals($expected, $result);
  1559. }
  1560. /**
  1561. * test first() with a the model parameter.
  1562. *
  1563. * @return void
  1564. */
  1565. public function testFirstNonDefaultModel()
  1566. {
  1567. $this->Paginator->request->params['paging']['Article']['page'] = 1;
  1568. $this->Paginator->request->params['paging']['Client'] = [
  1569. 'page' => 3,
  1570. 'current' => 3,
  1571. 'count' => 13,
  1572. 'prevPage' => false,
  1573. 'nextPage' => true,
  1574. 'pageCount' => 5,
  1575. ];
  1576. $result = $this->Paginator->first('first', ['model' => 'Article']);
  1577. $this->assertEquals('', $result);
  1578. $result = $this->Paginator->first('first', ['model' => 'Client']);
  1579. $expected = [
  1580. 'li' => ['class' => 'first'],
  1581. 'a' => ['href' => '/index'],
  1582. 'first',
  1583. '/a',
  1584. '/li'
  1585. ];
  1586. $this->assertHtml($expected, $result);
  1587. }
  1588. /**
  1589. * test first() on the first page.
  1590. *
  1591. * @return void
  1592. */
  1593. public function testFirstEmpty()
  1594. {
  1595. $this->Paginator->request->params['paging']['Article']['page'] = 1;
  1596. $result = $this->Paginator->first();
  1597. $expected = '';
  1598. $this->assertEquals($expected, $result);
  1599. }
  1600. /**
  1601. * test first() and options()
  1602. *
  1603. * @return void
  1604. */
  1605. public function testFirstFullBaseUrl()
  1606. {
  1607. $this->Paginator->request->params['paging']['Article']['page'] = 3;
  1608. $this->Paginator->request->params['paging']['Article']['direction'] = 'DESC';
  1609. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  1610. $this->Paginator->options(['url' => ['_full' => true]]);
  1611. $result = $this->Paginator->first();
  1612. $expected = [
  1613. 'li' => ['class' => 'first'],
  1614. ['a' => [
  1615. 'href' => Configure::read('App.fullBaseUrl') . '/index?sort=Article.title&amp;direction=DESC'
  1616. ]],
  1617. '&lt;&lt; first',
  1618. '/a',
  1619. '/li',
  1620. ];
  1621. $this->assertHtml($expected, $result);
  1622. }
  1623. /**
  1624. * test first() on the fence-post
  1625. *
  1626. * @return void
  1627. */
  1628. public function testFirstBoundaries()
  1629. {
  1630. $this->Paginator->request->params['paging']['Article']['page'] = 3;
  1631. $result = $this->Paginator->first();
  1632. $expected = [
  1633. 'li' => ['class' => 'first'],
  1634. 'a' => ['href' => '/index'],
  1635. '&lt;&lt; first',
  1636. '/a',
  1637. '/li'
  1638. ];
  1639. $this->assertHtml($expected, $result);
  1640. $result = $this->Paginator->first(2);
  1641. $expected = [
  1642. '<li',
  1643. ['a' => ['href' => '/index']], '1', '/a',
  1644. '/li',
  1645. '<li',
  1646. ['a' => ['href' => '/index?page=2']], '2', '/a',
  1647. '/li'
  1648. ];
  1649. $this->assertHtml($expected, $result);
  1650. $this->Paginator->request->params['paging']['Article']['page'] = 2;
  1651. $result = $this->Paginator->first(3);
  1652. $this->assertEquals('', $result, 'When inside the first links range, no links should be made');
  1653. }
  1654. /**
  1655. * test params() method
  1656. *
  1657. * @return void
  1658. */
  1659. public function testParams()
  1660. {
  1661. $result = $this->Paginator->params();
  1662. $this->assertArrayHasKey('page', $result);
  1663. $this->assertArrayHasKey('pageCount', $result);
  1664. $result = $this->Paginator->params('Nope');
  1665. $this->assertEquals([], $result);
  1666. }
  1667. /**
  1668. * test param() method
  1669. *
  1670. * @return void
  1671. */
  1672. public function testParam()
  1673. {
  1674. $result = $this->Paginator->param('count');
  1675. $this->assertSame(62, $result);
  1676. $result = $this->Paginator->param('imaginary');
  1677. $this->assertNull($result);
  1678. }
  1679. /**
  1680. * test last() method
  1681. *
  1682. * @return void
  1683. */
  1684. public function testLast()
  1685. {
  1686. $result = $this->Paginator->last();
  1687. $expected = [
  1688. 'li' => ['class' => 'last'],
  1689. 'a' => ['href' => '/index?page=7'],
  1690. 'last &gt;&gt;',
  1691. '/a',
  1692. '/li'
  1693. ];
  1694. $this->assertHtml($expected, $result);
  1695. $result = $this->Paginator->last(1);
  1696. $expected = [
  1697. '<li',
  1698. 'a' => ['href' => '/index?page=7'],
  1699. '7',
  1700. '/a',
  1701. '/li'
  1702. ];
  1703. $this->assertHtml($expected, $result);
  1704. $this->Paginator->request->params['paging']['Article']['page'] = 6;
  1705. $result = $this->Paginator->last(2);
  1706. $expected = [
  1707. '<li',
  1708. ['a' => ['href' => '/index?page=6']], '6', '/a',
  1709. '/li',
  1710. '<li',
  1711. ['a' => ['href' => '/index?page=7']], '7', '/a',
  1712. '/li',
  1713. ];
  1714. $this->assertHtml($expected, $result);
  1715. $result = $this->Paginator->last(3);
  1716. $this->assertEquals('', $result, 'When inside the last links range, no links should be made');
  1717. }
  1718. /**
  1719. * test the options for last()
  1720. *
  1721. * @return void
  1722. */
  1723. public function testLastOptions()
  1724. {
  1725. $this->Paginator->request->params['paging'] = [
  1726. 'Client' => [
  1727. 'page' => 4,
  1728. 'current' => 3,
  1729. 'count' => 30,
  1730. 'prevPage' => false,
  1731. 'nextPage' => 2,
  1732. 'pageCount' => 15,
  1733. 'sort' => 'Client.name',
  1734. 'direction' => 'DESC',
  1735. ]
  1736. ];
  1737. $result = $this->Paginator->last();
  1738. $expected = [
  1739. 'li' => ['class' => 'last'],
  1740. 'a' => [
  1741. 'href' => '/index?page=15&amp;sort=Client.name&amp;direction=DESC',
  1742. ],
  1743. 'last &gt;&gt;', '/a',
  1744. '/li',
  1745. ];
  1746. $this->assertHtml($expected, $result);
  1747. $result = $this->Paginator->last(1);
  1748. $expected = [
  1749. '<li',
  1750. ['a' => ['href' => '/index?page=15&amp;sort=Client.name&amp;direction=DESC']], '15', '/a',
  1751. '/li',
  1752. ];
  1753. $this->assertHtml($expected, $result);
  1754. $result = $this->Paginator->last(2);
  1755. $expected = [
  1756. '<li',
  1757. ['a' => ['href' => '/index?page=14&amp;sort=Client.name&amp;direction=DESC']], '14', '/a',
  1758. '/li',
  1759. '<li',
  1760. ['a' => ['href' => '/index?page=15&amp;sort=Client.name&amp;direction=DESC']], '15', '/a',
  1761. '/li',
  1762. ];
  1763. $this->assertHtml($expected, $result);
  1764. }
  1765. /**
  1766. * test last() with a the model parameter.
  1767. *
  1768. * @return void
  1769. */
  1770. public function testLastNonDefaultModel()
  1771. {
  1772. $this->Paginator->request->params['paging']['Article']['page'] = 7;
  1773. $this->Paginator->request->params['paging']['Client'] = [
  1774. 'page' => 3,
  1775. 'current' => 3,
  1776. 'count' => 13,
  1777. 'prevPage' => false,
  1778. 'nextPage' => true,
  1779. 'pageCount' => 5,
  1780. ];
  1781. $result = $this->Paginator->last('last', ['model' => 'Article']);
  1782. $this->assertEquals('', $result);
  1783. $result = $this->Paginator->last('last', ['model' => 'Client']);
  1784. $expected = [
  1785. 'li' => ['class' => 'last'],
  1786. 'a' => ['href' => '/index?page=5'],
  1787. 'last',
  1788. '/a',
  1789. '/li'
  1790. ];
  1791. $this->assertHtml($expected, $result);
  1792. }
  1793. /**
  1794. * testCounter method
  1795. *
  1796. * @return void
  1797. */
  1798. public function testCounter()
  1799. {
  1800. $this->Paginator->request->params['paging'] = [
  1801. 'Client' => [
  1802. 'page' => 1,
  1803. 'current' => 3,
  1804. 'count' => 13,
  1805. 'perPage' => 3,
  1806. 'prevPage' => false,
  1807. 'nextPage' => true,
  1808. 'pageCount' => 5,
  1809. 'limit' => 3,
  1810. 'sort' => 'Client.name',
  1811. 'order' => 'DESC',
  1812. ]
  1813. ];
  1814. $input = 'Page {{page}} of {{pages}}, showing {{current}} records out of {{count}} total, ';
  1815. $input .= 'starting on record {{start}}, ending on {{end}}';
  1816. $expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ';
  1817. $expected .= 'ending on 3';
  1818. $result = $this->Paginator->counter($input);
  1819. $this->assertEquals($expected, $result);
  1820. $result = $this->Paginator->counter(['format' => 'pages']);
  1821. $expected = '1 of 5';
  1822. $this->assertEquals($expected, $result);
  1823. $result = $this->Paginator->counter(['format' => 'range']);
  1824. $expected = '1 - 3 of 13';
  1825. $this->assertEquals($expected, $result);
  1826. $result = $this->Paginator->counter('Showing {{page}} of {{pages}} {{model}}');
  1827. $this->assertEquals('Showing 1 of 5 clients', $result);
  1828. }
  1829. /**
  1830. * Tests that numbers are formatted according to the locale when using counter()
  1831. *
  1832. * @return void
  1833. */
  1834. public function testCounterBigNumbers()
  1835. {
  1836. $this->Paginator->request->params['paging'] = [
  1837. 'Client' => [
  1838. 'page' => 1523,
  1839. 'current' => 1230,
  1840. 'count' => 234567,
  1841. 'perPage' => 3000,
  1842. 'prevPage' => false,
  1843. 'nextPage' => true,
  1844. 'pageCount' => 1000,
  1845. 'limit' => 5000,
  1846. 'sort' => 'Client.name',
  1847. 'order' => 'DESC',
  1848. ]
  1849. ];
  1850. $input = 'Page {{page}} of {{pages}}, showing {{current}} records out of {{count}} total, ';
  1851. $input .= 'starting on record {{start}}, ending on {{end}}';
  1852. $expected = 'Page 1,523 of 1,000, showing 1,230 records out of 234,567 total, ';
  1853. $expected .= 'starting on record 4,566,001, ending on 234,567';
  1854. $result = $this->Paginator->counter($input);
  1855. $this->assertEquals($expected, $result);
  1856. I18n::locale('de-DE');
  1857. $expected = 'Page 1.523 of 1.000, showing 1.230 records out of 234.567 total, ';
  1858. $expected .= 'starting on record 4.566.001, ending on 234.567';
  1859. $result = $this->Paginator->counter($input);
  1860. $this->assertEquals($expected, $result);
  1861. }
  1862. /**
  1863. * testHasPage method
  1864. *
  1865. * @return void
  1866. */
  1867. public function testHasPage()
  1868. {
  1869. $result = $this->Paginator->hasPage('Article', 15);
  1870. $this->assertFalse($result);
  1871. $result = $this->Paginator->hasPage('UndefinedModel', 2);
  1872. $this->assertFalse($result);
  1873. $result = $this->Paginator->hasPage('Article', 2);
  1874. $this->assertTrue($result);
  1875. $result = $this->Paginator->hasPage(2);
  1876. $this->assertTrue($result);
  1877. }
  1878. /**
  1879. * testNextLinkUsingDotNotation method
  1880. *
  1881. * @return void
  1882. */
  1883. public function testNextLinkUsingDotNotation()
  1884. {
  1885. Router::setRequestInfo([
  1886. ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []],
  1887. ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
  1888. ]);
  1889. $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
  1890. $this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
  1891. $this->Paginator->request->params['paging']['Article']['page'] = 1;
  1892. $test = ['url' => [
  1893. 'page' => '1',
  1894. 'sort' => 'Article.title',
  1895. 'direction' => 'asc',
  1896. ]];
  1897. $this->Paginator->options($test);
  1898. $result = $this->Paginator->next('Next');
  1899. $expected = [
  1900. 'li' => ['class' => 'next'],
  1901. 'a' => [
  1902. 'href' => '/accounts/index?page=2&amp;sort=Article.title&amp;direction=asc',
  1903. 'rel' => 'next'
  1904. ],
  1905. 'Next',
  1906. '/a',
  1907. '/li',
  1908. ];
  1909. $this->assertHtml($expected, $result);
  1910. }
  1911. /**
  1912. * test the current() method
  1913. *
  1914. * @return void
  1915. */
  1916. public function testCurrent()
  1917. {
  1918. $result = $this->Paginator->current();
  1919. $this->assertEquals($this->Paginator->request->params['paging']['Article']['page'], $result);
  1920. $result = $this->Paginator->current('Incorrect');
  1921. $this->assertEquals(1, $result);
  1922. }
  1923. /**
  1924. * test the defaultModel() method
  1925. *
  1926. * @return void
  1927. */
  1928. public function testNoDefaultModel()
  1929. {
  1930. $this->Paginator->request = new Request();
  1931. $this->assertNull($this->Paginator->defaultModel());
  1932. }
  1933. /**
  1934. * test the numbers() method when there is only one page
  1935. *
  1936. * @return void
  1937. */
  1938. public function testWithOnePage()
  1939. {
  1940. $this->Paginator->request['paging'] = [
  1941. 'Article' => [
  1942. 'page' => 1,
  1943. 'current' => 2,
  1944. 'count' => 2,
  1945. 'prevPage' => false,
  1946. 'nextPage' => true,
  1947. 'pageCount' => 1,
  1948. ]
  1949. ];
  1950. $this->assertFalse($this->Paginator->numbers());
  1951. $this->assertFalse($this->Paginator->first());
  1952. $this->assertFalse($this->Paginator->last());
  1953. }
  1954. /**
  1955. * test the numbers() method when there is only one page
  1956. *
  1957. * @return void
  1958. */
  1959. public function testWithZeroPages()
  1960. {
  1961. $this->Paginator->request['paging'] = [
  1962. 'Article' => [
  1963. 'page' => 0,
  1964. 'current' => 0,
  1965. 'count' => 0,
  1966. 'perPage' => 10,
  1967. 'prevPage' => false,
  1968. 'nextPage' => false,
  1969. 'pageCount' => 0,
  1970. 'limit' => 10,
  1971. ]
  1972. ];
  1973. $result = $this->Paginator->counter(['format' => 'pages']);
  1974. $expected = '0 of 1';
  1975. $this->assertEquals($expected, $result);
  1976. }
  1977. /**
  1978. * Verifies that no next and prev links are created for single page results.
  1979. *
  1980. * @return void
  1981. */
  1982. public function testMetaPage0()
  1983. {
  1984. $this->Paginator->request['paging'] = [
  1985. 'Article' => [
  1986. 'page' => 1,
  1987. 'prevPage' => false,
  1988. 'nextPage' => false,
  1989. 'pageCount' => 1,
  1990. ]
  1991. ];
  1992. $expected = '';
  1993. $result = $this->Paginator->meta();
  1994. $this->assertSame($expected, $result);
  1995. }
  1996. /**
  1997. * Verifies that page 1 only has a next link.
  1998. *
  1999. * @return void
  2000. */
  2001. public function testMetaPage1()
  2002. {
  2003. $this->Paginator->request['paging'] = [
  2004. 'Article' => [
  2005. 'page' => 1,
  2006. 'prevPage' => false,
  2007. 'nextPage' => true,
  2008. 'pageCount' => 2,
  2009. ]
  2010. ];
  2011. $expected = '<link rel="next" href="http://localhost/index?page=2"/>';
  2012. $result = $this->Paginator->meta();
  2013. $this->assertSame($expected, $result);
  2014. }
  2015. /**
  2016. * Verifies that the method will append to a block.
  2017. *
  2018. * @return void
  2019. */
  2020. public function testMetaPage1InlineFalse()
  2021. {
  2022. $this->Paginator->request['paging'] = [
  2023. 'Article' => [
  2024. 'page' => 1,
  2025. 'prevPage' => false,
  2026. 'nextPage' => true,
  2027. 'pageCount' => 2,
  2028. ]
  2029. ];
  2030. $expected = '<link rel="next" href="http://localhost/index?page=2"/>';
  2031. $this->Paginator->meta(['block' => true]);
  2032. $result = $this->View->fetch('meta');
  2033. $this->assertSame($expected, $result);
  2034. }
  2035. /**
  2036. * Verifies that the last page only has a prev link.
  2037. *
  2038. * @return void
  2039. */
  2040. public function testMetaPage1Last()
  2041. {
  2042. $this->Paginator->request['paging'] = [
  2043. 'Article' => [
  2044. 'page' => 2,
  2045. 'prevPage' => true,
  2046. 'nextPage' => false,
  2047. 'pageCount' => 2,
  2048. ]
  2049. ];
  2050. $expected = '<link rel="prev" href="http://localhost/index"/>';
  2051. $result = $this->Paginator->meta();
  2052. $this->assertSame($expected, $result);
  2053. }
  2054. /**
  2055. * Verifies that a page in the middle has both links.
  2056. *
  2057. * @return void
  2058. */
  2059. public function testMetaPage10Last()
  2060. {
  2061. $this->Paginator->request['paging'] = [
  2062. 'Article' => [
  2063. 'page' => 5,
  2064. 'prevPage' => true,
  2065. 'nextPage' => true,
  2066. 'pageCount' => 10,
  2067. ]
  2068. ];
  2069. $expected = '<link rel="prev" href="http://localhost/index?page=4"/>';
  2070. $expected .= '<link rel="next" href="http://localhost/index?page=6"/>';
  2071. $result = $this->Paginator->meta();
  2072. $this->assertSame($expected, $result);
  2073. }
  2074. }