PaginatorComponentTest.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  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 CakePHP(tm) v 2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Controller\Component;
  16. use Cake\Controller\Component\PaginatorComponent;
  17. use Cake\Controller\Controller;
  18. use Cake\Core\Configure;
  19. use Cake\Error;
  20. use Cake\Network\Request;
  21. use Cake\TestSuite\TestCase;
  22. use Cake\Utility\Hash;
  23. /**
  24. * PaginatorTestController class
  25. *
  26. */
  27. class PaginatorTestController extends Controller {
  28. /**
  29. * components property
  30. *
  31. * @var array
  32. */
  33. public $components = array('Paginator');
  34. }
  35. class PaginatorComponentTest extends TestCase {
  36. /**
  37. * fixtures property
  38. *
  39. * @var array
  40. */
  41. public $fixtures = array('core.post', 'core.comment', 'core.author');
  42. /**
  43. * setup
  44. *
  45. * @return void
  46. */
  47. public function setUp() {
  48. parent::setUp();
  49. $this->_ns = Configure::read('App.namespace');
  50. Configure::write('App.namespace', 'TestApp');
  51. $this->request = new Request('controller_posts/index');
  52. $this->request->params['pass'] = array();
  53. $this->Controller = new Controller($this->request);
  54. $this->Paginator = new PaginatorComponent($this->getMock('Cake\Controller\ComponentRegistry'), array());
  55. $this->Paginator->Controller = $this->Controller;
  56. $this->Controller->Post = $this->getMock('Cake\Model\Model');
  57. $this->Controller->Post->alias = 'Post';
  58. }
  59. /**
  60. * tearDown
  61. *
  62. * @return void
  63. */
  64. public function tearDown() {
  65. Configure::write('App.namespace', $this->_ns);
  66. parent::tearDown();
  67. }
  68. /**
  69. * testPaginate method
  70. *
  71. * @return void
  72. */
  73. public function testPaginate() {
  74. $this->markTestIncomplete('Need to revisit once models work again.');
  75. $Controller = new PaginatorTestController($this->request);
  76. $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
  77. $Controller->request->params['pass'] = array('1');
  78. $Controller->request->query = array();
  79. $Controller->constructClasses();
  80. $Controller->PaginatorControllerPost->order = null;
  81. $Controller->Paginator->settings = array(
  82. 'order' => array('PaginatorControllerComment.id' => 'ASC')
  83. );
  84. $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id');
  85. $this->assertEquals(array(1, 2, 3, 4, 5, 6), $results);
  86. $Controller->Paginator->settings = array(
  87. 'order' => array('PaginatorControllerPost.id' => 'ASC')
  88. );
  89. $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
  90. $this->assertEquals(array(1, 2, 3), $results);
  91. $Controller->modelClass = null;
  92. $Controller->uses[0] = 'Plugin.PaginatorControllerPost';
  93. $results = Hash::extract($Controller->Paginator->paginate(), '{n}.PaginatorControllerPost.id');
  94. $this->assertEquals(array(1, 2, 3), $results);
  95. $Controller->request->query = array('page' => '-1');
  96. $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
  97. $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  98. $this->assertEquals(array(1, 2, 3), $results);
  99. $Controller->request->query = array('sort' => 'PaginatorControllerPost.id', 'direction' => 'asc');
  100. $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
  101. $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  102. $this->assertEquals(array(1, 2, 3), $results);
  103. $Controller->request->query = array('sort' => 'PaginatorControllerPost.id', 'direction' => 'desc');
  104. $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
  105. $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  106. $this->assertEquals(array(3, 2, 1), $results);
  107. $Controller->request->query = array('sort' => 'id', 'direction' => 'desc');
  108. $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
  109. $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  110. $this->assertEquals(array(3, 2, 1), $results);
  111. $Controller->request->query = array('sort' => 'NotExisting.field', 'direction' => 'desc');
  112. $Controller->Paginator->paginate('PaginatorControllerPost');
  113. $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  114. $this->assertEquals(array(), $Controller->PaginatorControllerPost->lastQueries[1]['order'][0], 'no order should be set.');
  115. $Controller->request->query = array(
  116. 'sort' => 'PaginatorControllerPost.author_id', 'direction' => 'allYourBase'
  117. );
  118. $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
  119. $this->assertEquals(array('PaginatorControllerPost.author_id' => 'asc'), $Controller->PaginatorControllerPost->lastQueries[1]['order'][0]);
  120. $this->assertEquals(array(1, 3, 2), $results);
  121. $Controller->request->query = array();
  122. $Controller->Paginator->settings = array('limit' => 0, 'maxLimit' => 10);
  123. $Controller->Paginator->paginate('PaginatorControllerPost');
  124. $this->assertSame(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  125. $this->assertSame($Controller->request->params['paging']['PaginatorControllerPost']['pageCount'], 3);
  126. $this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']);
  127. $this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']);
  128. $Controller->request->query = array();
  129. $Controller->Paginator->settings = array('limit' => 'garbage!', 'maxLimit' => 10);
  130. $Controller->Paginator->paginate('PaginatorControllerPost');
  131. $this->assertSame(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  132. $this->assertSame($Controller->request->params['paging']['PaginatorControllerPost']['pageCount'], 3);
  133. $this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']);
  134. $this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']);
  135. $Controller->request->query = array();
  136. $Controller->Paginator->settings = array('limit' => '-1', 'maxLimit' => 10);
  137. $Controller->Paginator->paginate('PaginatorControllerPost');
  138. $this->assertSame($Controller->request->params['paging']['PaginatorControllerPost']['limit'], 1);
  139. $this->assertSame(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  140. $this->assertSame($Controller->request->params['paging']['PaginatorControllerPost']['pageCount'], 3);
  141. $this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']);
  142. $this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']);
  143. $Controller->Paginator->settings = array('conditions' => array('PaginatorAuthor.user' => 'mariano'));
  144. $Controller->Paginator->paginate('PaginatorControllerPost');
  145. $this->assertSame(2, $Controller->request->params['paging']['PaginatorControllerPost']['count']);
  146. }
  147. /**
  148. * Test that non-numeric values are rejected for page, and limit
  149. *
  150. * @return void
  151. */
  152. public function testPageParamCasting() {
  153. $this->markTestIncomplete('Need to revisit once models work again.');
  154. $this->Controller->Post->expects($this->at(0))
  155. ->method('hasMethod')
  156. ->with('paginate')
  157. ->will($this->returnValue(false));
  158. $this->Controller->Post->expects($this->at(1))
  159. ->method('find')
  160. ->will($this->returnValue(array('stuff')));
  161. $this->Controller->Post->expects($this->at(2))
  162. ->method('hasMethod')
  163. ->with('paginateCount')
  164. ->will($this->returnValue(false));
  165. $this->Controller->Post->expects($this->at(3))
  166. ->method('find')
  167. ->will($this->returnValue(2));
  168. $this->request->query = array('page' => '1 " onclick="alert(\'xss\');">');
  169. $this->Paginator->settings = array('limit' => 1, 'maxLimit' => 10);
  170. $this->Paginator->paginate('Post');
  171. $this->assertSame(1, $this->request->params['paging']['Post']['page'], 'XSS exploit opened');
  172. }
  173. /**
  174. * testPaginateExtraParams method
  175. *
  176. * @return void
  177. */
  178. public function testPaginateExtraParams() {
  179. $this->markTestIncomplete('Need to revisit once models work again.');
  180. $Controller = new PaginatorTestController($this->request);
  181. $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
  182. $Controller->request->params['pass'] = array('1');
  183. $Controller->request->query = array();
  184. $Controller->constructClasses();
  185. $Controller->request->query = array('page' => '-1', 'contain' => array('PaginatorControllerComment'));
  186. $Controller->Paginator->settings = array(
  187. 'order' => array('PaginatorControllerPost.id' => 'ASC')
  188. );
  189. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  190. $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  191. $this->assertEquals(array(1, 2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
  192. $this->assertTrue(!isset($Controller->PaginatorControllerPost->lastQueries[1]['contain']));
  193. $Controller->request->query = array('page' => '-1');
  194. $Controller->Paginator->settings = array(
  195. 'PaginatorControllerPost' => array(
  196. 'contain' => array('PaginatorControllerComment'),
  197. 'maxLimit' => 10,
  198. 'order' => array('PaginatorControllerPost.id' => 'ASC')
  199. ),
  200. );
  201. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  202. $this->assertEquals(1, $Controller->request->params['paging']['PaginatorControllerPost']['page']);
  203. $this->assertEquals(array(1, 2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
  204. $this->assertTrue(isset($Controller->PaginatorControllerPost->lastQueries[1]['contain']));
  205. $Controller->Paginator->settings = array(
  206. 'PaginatorControllerPost' => array(
  207. 'popular', 'fields' => array('id', 'title'), 'maxLimit' => 10,
  208. ),
  209. );
  210. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  211. $this->assertEquals(array(2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
  212. $this->assertEquals(array('PaginatorControllerPost.id > ' => '1'), $Controller->PaginatorControllerPost->lastQueries[1]['conditions']);
  213. $Controller->request->query = array('limit' => 12);
  214. $Controller->Paginator->settings = array('limit' => 30, 'maxLimit' => 100);
  215. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  216. $paging = $Controller->request->params['paging']['PaginatorControllerPost'];
  217. $this->assertEquals(12, $Controller->PaginatorControllerPost->lastQueries[1]['limit']);
  218. $this->assertEquals(12, $paging['limit']);
  219. $Controller = new PaginatorTestController($this->request);
  220. $Controller->uses = array('ControllerPaginateModel');
  221. $Controller->request->query = array();
  222. $Controller->constructClasses();
  223. $Controller->Paginator->settings = array(
  224. 'ControllerPaginateModel' => array(
  225. 'contain' => array('ControllerPaginateModel'),
  226. 'group' => 'Comment.author_id',
  227. 'maxLimit' => 10,
  228. )
  229. );
  230. $result = $Controller->Paginator->paginate('ControllerPaginateModel');
  231. $expected = array(
  232. 'contain' => array('ControllerPaginateModel'),
  233. 'group' => 'Comment.author_id',
  234. 'maxLimit' => 10,
  235. );
  236. $this->assertEquals($expected, $Controller->ControllerPaginateModel->extra);
  237. $Controller->Paginator->settings = array(
  238. 'ControllerPaginateModel' => array(
  239. 'foo', 'contain' => array('ControllerPaginateModel'),
  240. 'group' => 'Comment.author_id',
  241. 'maxLimit' => 10,
  242. )
  243. );
  244. $Controller->Paginator->paginate('ControllerPaginateModel');
  245. $expected = array(
  246. 'contain' => array('ControllerPaginateModel'),
  247. 'group' => 'Comment.author_id',
  248. 'type' => 'foo',
  249. 'maxLimit' => 10,
  250. );
  251. $this->assertEquals($expected, $Controller->ControllerPaginateModel->extra);
  252. }
  253. /**
  254. * Test that special paginate types are called and that the type param doesn't leak out into defaults or options.
  255. *
  256. * @return void
  257. */
  258. public function testPaginateSpecialType() {
  259. $this->markTestIncomplete('Need to revisit once models work again.');
  260. $Controller = new PaginatorTestController($this->request);
  261. $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
  262. $Controller->request->params['pass'][] = '1';
  263. $Controller->request->query = [];
  264. $Controller->constructClasses();
  265. $Controller->Paginator->settings = array(
  266. 'PaginatorControllerPost' => array(
  267. 'popular',
  268. 'fields' => array('id', 'title'),
  269. 'maxLimit' => 10,
  270. )
  271. );
  272. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  273. $this->assertEquals(array(2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
  274. $this->assertEquals(
  275. $Controller->PaginatorControllerPost->lastQueries[1]['conditions'],
  276. array('PaginatorControllerPost.id > ' => '1')
  277. );
  278. $this->assertEquals('popular', $Controller->request->params['paging']['PaginatorControllerPost']['findType']);
  279. }
  280. /**
  281. * testDefaultPaginateParams method
  282. *
  283. * @return void
  284. */
  285. public function testDefaultPaginateParams() {
  286. $this->markTestIncomplete('Need to revisit once models work again.');
  287. $Controller = new PaginatorTestController($this->request);
  288. $Controller->modelClass = 'PaginatorControllerPost';
  289. $Controller->request->query = [];
  290. $Controller->constructClasses();
  291. $Controller->Paginator->settings = array(
  292. 'order' => 'PaginatorControllerPost.id DESC',
  293. 'maxLimit' => 10,
  294. );
  295. $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
  296. $this->assertEquals('PaginatorControllerPost.id DESC', $Controller->request->params['paging']['PaginatorControllerPost']['order']);
  297. $this->assertEquals(array(3, 2, 1), $results);
  298. }
  299. /**
  300. * test paginate() and model default order
  301. *
  302. * @return void
  303. */
  304. public function testPaginateOrderModelDefault() {
  305. $this->markTestIncomplete('Need to revisit once models work again.');
  306. $Controller = new PaginatorTestController($this->request);
  307. $Controller->uses = array('PaginatorControllerPost');
  308. $Controller->params['url'] = array();
  309. $Controller->constructClasses();
  310. $Controller->PaginatorControllerPost->order = array(
  311. $Controller->PaginatorControllerPost->alias . '.created' => 'desc'
  312. );
  313. $Controller->Paginator->settings = array(
  314. 'fields' => array('id', 'title', 'created'),
  315. 'maxLimit' => 10,
  316. 'paramType' => 'named'
  317. );
  318. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  319. $expected = array('2007-03-18 10:43:23', '2007-03-18 10:41:23', '2007-03-18 10:39:23');
  320. $this->assertEquals($expected, Hash::extract($result, '{n}.PaginatorControllerPost.created'));
  321. $this->assertEquals(
  322. $Controller->PaginatorControllerPost->order,
  323. $Controller->request->paging['PaginatorControllerPost']['order']
  324. );
  325. $Controller->PaginatorControllerPost->order = array('PaginatorControllerPost.id');
  326. $result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
  327. $this->assertEmpty($result['order']);
  328. $Controller->PaginatorControllerPost->order = 'PaginatorControllerPost.id';
  329. $results = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
  330. $this->assertEmpty($result['order']);
  331. $Controller->PaginatorControllerPost->order = array(
  332. 'PaginatorControllerPost.id',
  333. 'PaginatorControllerPost.created' => 'asc'
  334. );
  335. $result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
  336. $expected = array('PaginatorControllerPost.created' => 'asc');
  337. $this->assertEquals($expected, $result['order']);
  338. }
  339. /**
  340. * test paginate() and virtualField interactions
  341. *
  342. * @return void
  343. */
  344. public function testPaginateOrderVirtualField() {
  345. $this->markTestIncomplete('Need to revisit once models work again.');
  346. $Controller = new PaginatorTestController($this->request);
  347. $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
  348. $Controller->request->query = [];
  349. $Controller->constructClasses();
  350. $Controller->PaginatorControllerPost->virtualFields = array(
  351. 'offset_test' => 'PaginatorControllerPost.id + 1'
  352. );
  353. $Controller->Paginator->settings = array(
  354. 'fields' => array('id', 'title', 'offset_test'),
  355. 'order' => array('offset_test' => 'DESC'),
  356. 'maxLimit' => 10,
  357. );
  358. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  359. $this->assertEquals(array(4, 3, 2), Hash::extract($result, '{n}.PaginatorControllerPost.offset_test'));
  360. $Controller->request->query = array('sort' => 'offset_test', 'direction' => 'asc');
  361. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  362. $this->assertEquals(array(2, 3, 4), Hash::extract($result, '{n}.PaginatorControllerPost.offset_test'));
  363. }
  364. /**
  365. * test paginate() and virtualField on joined model
  366. *
  367. * @return void
  368. */
  369. public function testPaginateOrderVirtualFieldJoinedModel() {
  370. $this->markTestIncomplete('Need to revisit once models work again.');
  371. $Controller = new PaginatorTestController($this->request);
  372. $Controller->uses = array('PaginatorControllerPost');
  373. $Controller->request->query = [];
  374. $Controller->constructClasses();
  375. $Controller->PaginatorControllerPost->recursive = 0;
  376. $Controller->Paginator->settings = array(
  377. 'order' => array('PaginatorAuthor.joined_offset' => 'DESC'),
  378. 'maxLimit' => 10,
  379. );
  380. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  381. $this->assertEquals(array(4, 2, 2), Hash::extract($result, '{n}.PaginatorAuthor.joined_offset'));
  382. $Controller->request->query = array('sort' => 'PaginatorAuthor.joined_offset', 'direction' => 'asc');
  383. $result = $Controller->Paginator->paginate('PaginatorControllerPost');
  384. $this->assertEquals(array(2, 2, 4), Hash::extract($result, '{n}.PaginatorAuthor.joined_offset'));
  385. }
  386. /**
  387. * Tests for missing models
  388. *
  389. */
  390. public function testPaginateMissingModel() {
  391. $this->markTestIncomplete('Need to revisit once models work again.');
  392. $Controller = new PaginatorTestController($this->request);
  393. $Controller->constructClasses();
  394. $Controller->Paginator->paginate('MissingModel');
  395. }
  396. /**
  397. * test that option merging prefers specific models
  398. *
  399. * @return void
  400. */
  401. public function testMergeOptionsModelSpecific() {
  402. $this->Paginator->settings = array(
  403. 'page' => 1,
  404. 'limit' => 20,
  405. 'maxLimit' => 100,
  406. 'Post' => array(
  407. 'page' => 1,
  408. 'limit' => 10,
  409. 'maxLimit' => 50,
  410. )
  411. );
  412. $result = $this->Paginator->mergeOptions('Silly');
  413. $this->assertEquals($this->Paginator->settings, $result);
  414. $result = $this->Paginator->mergeOptions('Post');
  415. $expected = array('page' => 1, 'limit' => 10, 'maxLimit' => 50);
  416. $this->assertEquals($expected, $result);
  417. }
  418. /**
  419. * test mergeOptions with customFind key
  420. *
  421. * @return void
  422. */
  423. public function testMergeOptionsCustomFindKey() {
  424. $this->request->query = [
  425. 'page' => 10,
  426. 'limit' => 10
  427. ];
  428. $this->Paginator->settings = [
  429. 'page' => 1,
  430. 'limit' => 20,
  431. 'maxLimit' => 100,
  432. 'findType' => 'myCustomFind'
  433. ];
  434. $result = $this->Paginator->mergeOptions('Post');
  435. $expected = array(
  436. 'page' => 10,
  437. 'limit' => 10,
  438. 'maxLimit' => 100,
  439. 'findType' => 'myCustomFind'
  440. );
  441. $this->assertEquals($expected, $result);
  442. }
  443. /**
  444. * test merging options from the querystring.
  445. *
  446. * @return void
  447. */
  448. public function testMergeOptionsQueryString() {
  449. $this->request->query = array(
  450. 'page' => 99,
  451. 'limit' => 75
  452. );
  453. $this->Paginator->settings = array(
  454. 'page' => 1,
  455. 'limit' => 20,
  456. 'maxLimit' => 100,
  457. );
  458. $result = $this->Paginator->mergeOptions('Post');
  459. $expected = array('page' => 99, 'limit' => 75, 'maxLimit' => 100);
  460. $this->assertEquals($expected, $result);
  461. }
  462. /**
  463. * test that the default whitelist doesn't let people screw with things they should not be allowed to.
  464. *
  465. * @return void
  466. */
  467. public function testMergeOptionsDefaultWhiteList() {
  468. $this->request->query = array(
  469. 'page' => 10,
  470. 'limit' => 10,
  471. 'fields' => array('bad.stuff'),
  472. 'recursive' => 1000,
  473. 'conditions' => array('bad.stuff'),
  474. 'contain' => array('bad')
  475. );
  476. $this->Paginator->settings = array(
  477. 'page' => 1,
  478. 'limit' => 20,
  479. 'maxLimit' => 100,
  480. );
  481. $result = $this->Paginator->mergeOptions('Post');
  482. $expected = array('page' => 10, 'limit' => 10, 'maxLimit' => 100);
  483. $this->assertEquals($expected, $result);
  484. }
  485. /**
  486. * test that modifying the whitelist works.
  487. *
  488. * @return void
  489. */
  490. public function testMergeOptionsExtraWhitelist() {
  491. $this->request->query = array(
  492. 'page' => 10,
  493. 'limit' => 10,
  494. 'fields' => array('bad.stuff'),
  495. 'recursive' => 1000,
  496. 'conditions' => array('bad.stuff'),
  497. 'contain' => array('bad')
  498. );
  499. $this->Paginator->settings = array(
  500. 'page' => 1,
  501. 'limit' => 20,
  502. 'maxLimit' => 100,
  503. );
  504. $this->Paginator->whitelist[] = 'fields';
  505. $result = $this->Paginator->mergeOptions('Post');
  506. $expected = array(
  507. 'page' => 10, 'limit' => 10, 'maxLimit' => 100, 'fields' => array('bad.stuff')
  508. );
  509. $this->assertEquals($expected, $result);
  510. }
  511. /**
  512. * test mergeOptions with limit > maxLimit in code.
  513. *
  514. * @return void
  515. */
  516. public function testMergeOptionsMaxLimit() {
  517. $this->Paginator->settings = array(
  518. 'limit' => 200,
  519. 'paramType' => 'named',
  520. );
  521. $result = $this->Paginator->mergeOptions('Post');
  522. $expected = array('page' => 1, 'limit' => 200, 'maxLimit' => 200, 'paramType' => 'named');
  523. $this->assertEquals($expected, $result);
  524. $this->Paginator->settings = array(
  525. 'maxLimit' => 10,
  526. 'paramType' => 'named',
  527. );
  528. $result = $this->Paginator->mergeOptions('Post');
  529. $expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 10, 'paramType' => 'named');
  530. $this->assertEquals($expected, $result);
  531. $this->request->params['named'] = array(
  532. 'limit' => 500
  533. );
  534. $this->Paginator->settings = array(
  535. 'limit' => 150,
  536. 'paramType' => 'named',
  537. );
  538. $result = $this->Paginator->mergeOptions('Post');
  539. $expected = array('page' => 1, 'limit' => 150, 'maxLimit' => 150, 'paramType' => 'named');
  540. $this->assertEquals($expected, $result);
  541. }
  542. /**
  543. * test that invalid directions are ignored.
  544. *
  545. * @return void
  546. */
  547. public function testValidateSortInvalidDirection() {
  548. $model = $this->getMock('Cake\Model\Model');
  549. $model->alias = 'model';
  550. $model->expects($this->any())->method('hasField')->will($this->returnValue(true));
  551. $options = array('sort' => 'something', 'direction' => 'boogers');
  552. $result = $this->Paginator->validateSort($model, $options);
  553. $this->assertEquals('asc', $result['order']['model.something']);
  554. }
  555. /**
  556. * Test that a really large page number gets clamped to the max page size.
  557. *
  558. * @expectedException Cake\Error\NotFoundException
  559. * @return void
  560. */
  561. public function testOutOfRangePageNumberGetsClamped() {
  562. $this->markTestIncomplete('Need to revisit once models work again.');
  563. $Controller = new PaginatorTestController($this->request);
  564. $Controller->uses = array('PaginatorControllerPost');
  565. $Controller->request->query['page'] = 3000;
  566. $Controller->constructClasses();
  567. $Controller->PaginatorControllerPost->recursive = 0;
  568. $Controller->Paginator->paginate('PaginatorControllerPost');
  569. }
  570. /**
  571. * Test that a really REALLY large page number gets clamped to the max page size.
  572. *
  573. *
  574. * @expectedException Cake\Error\NotFoundException
  575. * @return void
  576. */
  577. public function testOutOfVeryBigPageNumberGetsClamped() {
  578. $this->markTestIncomplete('Need to revisit once models work again.');
  579. $Controller = new PaginatorTestController($this->request);
  580. $Controller->uses = array('PaginatorControllerPost');
  581. $Controller->params['named'] = array(
  582. 'page' => '3000000000000000000000000',
  583. );
  584. $Controller->constructClasses();
  585. $Controller->PaginatorControllerPost->recursive = 0;
  586. $Controller->Paginator->paginate('PaginatorControllerPost');
  587. }
  588. /**
  589. * testOutOfRangePageNumberAndPageCountZero
  590. *
  591. * @expectedException Cake\Error\NotFoundException
  592. * @return void
  593. */
  594. public function testOutOfRangePageNumberAndPageCountZero() {
  595. $this->markTestIncomplete('Need to revisit once models work again.');
  596. $Controller = new PaginatorTestController($this->request);
  597. $Controller->uses = array('PaginatorControllerPost');
  598. $Controller->request->query['page'] = 3000;
  599. $Controller->constructClasses();
  600. $Controller->PaginatorControllerPost->recursive = 0;
  601. $Controller->paginate = array(
  602. 'conditions' => array('PaginatorControllerPost.id >' => 100)
  603. );
  604. try {
  605. $Controller->Paginator->paginate('PaginatorControllerPost');
  606. } catch (Error\NotFoundException $e) {
  607. $this->assertEquals(
  608. 1,
  609. $Controller->request->params['paging']['PaginatorControllerPost']['page'],
  610. 'Page number should not be 0'
  611. );
  612. return;
  613. }
  614. $this->fail();
  615. }
  616. /**
  617. * test that fields not in whitelist won't be part of order conditions.
  618. *
  619. * @return void
  620. */
  621. public function testValidateSortWhitelistFailure() {
  622. $model = $this->getMock('Cake\Model\Model');
  623. $model->alias = 'model';
  624. $model->expects($this->any())->method('hasField')->will($this->returnValue(true));
  625. $options = array('sort' => 'body', 'direction' => 'asc');
  626. $result = $this->Paginator->validateSort($model, $options, array('title', 'id'));
  627. $this->assertNull($result['order']);
  628. }
  629. /**
  630. * test that fields in the whitelist are not validated
  631. *
  632. * @return void
  633. */
  634. public function testValidateSortWhitelistTrusted() {
  635. $model = $this->getMock('Cake\Model\Model');
  636. $model->alias = 'model';
  637. $model->expects($this->never())->method('hasField');
  638. $options = array('sort' => 'body', 'direction' => 'asc');
  639. $result = $this->Paginator->validateSort($model, $options, array('body'));
  640. $expected = array('body' => 'asc');
  641. $this->assertEquals($expected, $result['order']);
  642. }
  643. /**
  644. * test that virtual fields work.
  645. *
  646. * @return void
  647. */
  648. public function testValidateSortVirtualField() {
  649. $model = $this->getMock('Cake\Model\Model');
  650. $model->alias = 'model';
  651. $model->expects($this->at(0))
  652. ->method('hasField')
  653. ->with('something')
  654. ->will($this->returnValue(false));
  655. $model->expects($this->at(1))
  656. ->method('hasField')
  657. ->with('something', true)
  658. ->will($this->returnValue(true));
  659. $options = array('sort' => 'something', 'direction' => 'desc');
  660. $result = $this->Paginator->validateSort($model, $options);
  661. $this->assertEquals('desc', $result['order']['something']);
  662. }
  663. /**
  664. * test that sorting fields is alias specific
  665. *
  666. * @return void
  667. */
  668. public function testValidateSortSharedFields() {
  669. $model = $this->getMock('Cake\Model\Model');
  670. $model->alias = 'Parent';
  671. $model->Child = $this->getMock('Cake\Model\Model');
  672. $model->Child->alias = 'Child';
  673. $model->expects($this->never())
  674. ->method('hasField');
  675. $model->Child->expects($this->at(0))
  676. ->method('hasField')
  677. ->with('something')
  678. ->will($this->returnValue(true));
  679. $options = array('sort' => 'Child.something', 'direction' => 'desc');
  680. $result = $this->Paginator->validateSort($model, $options);
  681. $this->assertEquals('desc', $result['order']['Child.something']);
  682. }
  683. /**
  684. * test that multiple sort works.
  685. *
  686. * @return void
  687. */
  688. public function testValidateSortMultiple() {
  689. $model = $this->getMock('Cake\Model\Model');
  690. $model->alias = 'model';
  691. $model->expects($this->any())->method('hasField')->will($this->returnValue(true));
  692. $options = array(
  693. 'order' => array(
  694. 'author_id' => 'asc',
  695. 'title' => 'asc'
  696. )
  697. );
  698. $result = $this->Paginator->validateSort($model, $options);
  699. $expected = array(
  700. 'model.author_id' => 'asc',
  701. 'model.title' => 'asc'
  702. );
  703. $this->assertEquals($expected, $result['order']);
  704. }
  705. /**
  706. * Test that no sort doesn't trigger an error.
  707. *
  708. * @return void
  709. */
  710. public function testValidateSortNoSort() {
  711. $model = $this->getMock('Cake\Model\Model');
  712. $model->alias = 'model';
  713. $model->expects($this->any())->method('hasField')->will($this->returnValue(true));
  714. $options = array('direction' => 'asc');
  715. $result = $this->Paginator->validateSort($model, $options, array('title', 'id'));
  716. $this->assertFalse(isset($result['order']));
  717. $options = array('order' => 'invalid desc');
  718. $result = $this->Paginator->validateSort($model, $options, array('title', 'id'));
  719. $this->assertEquals($options['order'], $result['order']);
  720. }
  721. /**
  722. * Test sorting with incorrect aliases on valid fields.
  723. *
  724. * @return void
  725. */
  726. public function testValidateSortInvalidAlias() {
  727. $model = $this->getMock('Cake\Model\Model');
  728. $model->alias = 'Model';
  729. $model->expects($this->any())->method('hasField')->will($this->returnValue(true));
  730. $options = array('sort' => 'Derp.id');
  731. $result = $this->Paginator->validateSort($model, $options);
  732. $this->assertEquals(array(), $result['order']);
  733. }
  734. /**
  735. * test that maxLimit is respected
  736. *
  737. * @return void
  738. */
  739. public function testCheckLimit() {
  740. $result = $this->Paginator->checkLimit(array('limit' => 1000000, 'maxLimit' => 100));
  741. $this->assertEquals(100, $result['limit']);
  742. $result = $this->Paginator->checkLimit(array('limit' => 'sheep!', 'maxLimit' => 100));
  743. $this->assertEquals(1, $result['limit']);
  744. $result = $this->Paginator->checkLimit(array('limit' => '-1', 'maxLimit' => 100));
  745. $this->assertEquals(1, $result['limit']);
  746. $result = $this->Paginator->checkLimit(array('limit' => null, 'maxLimit' => 100));
  747. $this->assertEquals(1, $result['limit']);
  748. $result = $this->Paginator->checkLimit(array('limit' => 0, 'maxLimit' => 100));
  749. $this->assertEquals(1, $result['limit']);
  750. }
  751. /**
  752. * testPaginateMaxLimit
  753. *
  754. * @return void
  755. */
  756. public function testPaginateMaxLimit() {
  757. $this->markTestIncomplete('Need to revisit once models work again.');
  758. $Controller = new Controller($this->request);
  759. $Controller->uses = array('PaginatorControllerPost', 'ControllerComment');
  760. $Controller->request->params['pass'][] = '1';
  761. $Controller->constructClasses();
  762. $Controller->request->query = array(
  763. 'contain' => array('ControllerComment'), 'limit' => '1000'
  764. );
  765. $result = $Controller->paginate('PaginatorControllerPost');
  766. $this->assertEquals(100, $Controller->request->params['paging']['PaginatorControllerPost']['limit']);
  767. $Controller->request->query = array(
  768. 'contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000
  769. );
  770. $result = $Controller->paginate('PaginatorControllerPost');
  771. $this->assertEquals(100, $Controller->request->params['paging']['PaginatorControllerPost']['limit']);
  772. $Controller->request->query = array('contain' => array('ControllerComment'), 'limit' => '10');
  773. $result = $Controller->paginate('PaginatorControllerPost');
  774. $this->assertEquals(10, $Controller->request->params['paging']['PaginatorControllerPost']['limit']);
  775. $Controller->request->query = array('contain' => array('ControllerComment'), 'limit' => '1000');
  776. $Controller->paginate = array('maxLimit' => 2000);
  777. $result = $Controller->paginate('PaginatorControllerPost');
  778. $this->assertEquals(1000, $Controller->request->params['paging']['PaginatorControllerPost']['limit']);
  779. $Controller->request->query = array('contain' => array('ControllerComment'), 'limit' => '5000');
  780. $result = $Controller->paginate('PaginatorControllerPost');
  781. $this->assertEquals(2000, $Controller->request->params['paging']['PaginatorControllerPost']['limit']);
  782. }
  783. /**
  784. * test paginate() and virtualField overlapping with real fields.
  785. *
  786. * @return void
  787. */
  788. public function testPaginateOrderVirtualFieldSharedWithRealField() {
  789. $this->markTestIncomplete('Need to revisit once models work again.');
  790. $Controller = new Controller($this->request);
  791. $Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
  792. $Controller->constructClasses();
  793. $Controller->PaginatorControllerComment->virtualFields = array(
  794. 'title' => 'PaginatorControllerComment.comment'
  795. );
  796. $Controller->PaginatorControllerComment->bindModel(array(
  797. 'belongsTo' => array(
  798. 'PaginatorControllerPost' => array(
  799. 'className' => 'PaginatorControllerPost',
  800. 'foreignKey' => 'article_id'
  801. )
  802. )
  803. ), false);
  804. $Controller->paginate = array(
  805. 'fields' => array(
  806. 'PaginatorControllerComment.id',
  807. 'title',
  808. 'PaginatorControllerPost.title'
  809. ),
  810. );
  811. $Controller->request->params['named'] = array(
  812. 'sort' => 'PaginatorControllerPost.title',
  813. 'direction' => 'desc'
  814. );
  815. $result = Hash::extract(
  816. $Controller->paginate('PaginatorControllerComment'),
  817. '{n}.PaginatorControllerComment.id'
  818. );
  819. $result1 = array_splice($result, 0, 2);
  820. sort($result1);
  821. $this->assertEquals(array(5, 6), $result1);
  822. sort($result);
  823. $this->assertEquals(array(1, 2, 3, 4), $result);
  824. }
  825. /**
  826. * test paginate() and custom find, to make sure the correct count is returned.
  827. *
  828. * @return void
  829. */
  830. public function testPaginateCustomFind() {
  831. $this->markTestIncomplete('Need to revisit once models work again.');
  832. $Controller = new Controller($this->request);
  833. $Controller->uses = ['PaginatorCustomPost'];
  834. $Controller->constructClasses();
  835. $data = array('author_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
  836. $Controller->PaginatorCustomPost->create($data);
  837. $result = $Controller->PaginatorCustomPost->save();
  838. $this->assertTrue(!empty($result));
  839. $result = $Controller->paginate();
  840. $this->assertEquals(array(1, 2, 3, 4), Hash::extract($result, '{n}.PaginatorCustomPost.id'));
  841. $result = $Controller->request->params['paging']['PaginatorCustomPost'];
  842. $this->assertEquals(4, $result['current']);
  843. $this->assertEquals(4, $result['count']);
  844. $Controller->paginate = array('published');
  845. $result = $Controller->paginate();
  846. $this->assertEquals(array(1, 2, 3), Hash::extract($result, '{n}.PaginatorCustomPost.id'));
  847. $result = $Controller->request->params['paging']['PaginatorCustomPost'];
  848. $this->assertEquals(3, $result['current']);
  849. $this->assertEquals(3, $result['count']);
  850. $Controller->paginate = array('published', 'limit' => 2);
  851. $result = $Controller->paginate();
  852. $this->assertEquals(array(1, 2), Hash::extract($result, '{n}.PaginatorCustomPost.id'));
  853. $result = $Controller->request->params['paging']['PaginatorCustomPost'];
  854. $this->assertEquals(2, $result['current']);
  855. $this->assertEquals(3, $result['count']);
  856. $this->assertEquals(2, $result['pageCount']);
  857. $this->assertTrue($result['nextPage']);
  858. $this->assertFalse($result['prevPage']);
  859. }
  860. /**
  861. * test paginate() and custom find with fields array, to make sure the correct count is returned.
  862. *
  863. * @return void
  864. */
  865. public function testPaginateCustomFindFieldsArray() {
  866. $this->markTestIncomplete('Need to revisit once models work again.');
  867. $Controller = new Controller($this->request);
  868. $Controller->uses = array('PaginatorCustomPost');
  869. $Controller->constructClasses();
  870. $data = array('author_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
  871. $Controller->PaginatorCustomPost->create($data);
  872. $result = $Controller->PaginatorCustomPost->save();
  873. $this->assertTrue(!empty($result));
  874. $Controller->paginate = array(
  875. 'list',
  876. 'conditions' => array('PaginatorCustomPost.published' => 'Y'),
  877. 'limit' => 2
  878. );
  879. $result = $Controller->paginate();
  880. $expected = array(
  881. 1 => 'First Post',
  882. 2 => 'Second Post',
  883. );
  884. $this->assertEquals($expected, $result);
  885. $result = $Controller->request->params['paging']['PaginatorCustomPost'];
  886. $this->assertEquals(2, $result['current']);
  887. $this->assertEquals(3, $result['count']);
  888. $this->assertEquals(2, $result['pageCount']);
  889. $this->assertTrue($result['nextPage']);
  890. $this->assertFalse($result['prevPage']);
  891. }
  892. /**
  893. * test paginate() and custom find with customFind key, to make sure the correct count is returned.
  894. *
  895. * @return void
  896. */
  897. public function testPaginateCustomFindWithCustomFindKey() {
  898. $this->markTestIncomplete('Need to revisit once models work again.');
  899. $Controller = new Controller($this->request);
  900. $Controller->uses = array('PaginatorCustomPost');
  901. $Controller->constructClasses();
  902. $data = array('author_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
  903. $Controller->PaginatorCustomPost->create($data);
  904. $result = $Controller->PaginatorCustomPost->save();
  905. $this->assertTrue(!empty($result));
  906. $Controller->paginate = array(
  907. 'conditions' => array('PaginatorCustomPost.published' => 'Y'),
  908. 'findType' => 'list',
  909. 'limit' => 2
  910. );
  911. $result = $Controller->paginate();
  912. $expected = array(
  913. 1 => 'First Post',
  914. 2 => 'Second Post',
  915. );
  916. $this->assertEquals($expected, $result);
  917. $result = $Controller->request->params['paging']['PaginatorCustomPost'];
  918. $this->assertEquals(2, $result['current']);
  919. $this->assertEquals(3, $result['count']);
  920. $this->assertEquals(2, $result['pageCount']);
  921. $this->assertTrue($result['nextPage']);
  922. $this->assertFalse($result['prevPage']);
  923. }
  924. /**
  925. * test paginate() and custom find with fields array, to make sure the correct count is returned.
  926. *
  927. * @return void
  928. */
  929. public function testPaginateCustomFindGroupBy() {
  930. $this->markTestIncomplete('Need to revisit once models work again.');
  931. $Controller = new Controller($this->request);
  932. $Controller->uses = array('PaginatorCustomPost');
  933. $Controller->constructClasses();
  934. $data = array('author_id' => 2, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
  935. $Controller->PaginatorCustomPost->create($data);
  936. $result = $Controller->PaginatorCustomPost->save();
  937. $this->assertTrue(!empty($result));
  938. $Controller->paginate = array(
  939. 'totals',
  940. 'limit' => 2
  941. );
  942. $result = $Controller->paginate();
  943. $expected = array(
  944. array(
  945. 'PaginatorCustomPost' => array(
  946. 'author_id' => '1',
  947. 'total_posts' => '2'
  948. )
  949. ),
  950. array(
  951. 'PaginatorCustomPost' => array(
  952. 'author_id' => '2',
  953. 'total_posts' => '1'
  954. )
  955. )
  956. );
  957. $this->assertEquals($expected, $result);
  958. $result = $Controller->request->params['paging']['PaginatorCustomPost'];
  959. $this->assertEquals(2, $result['current']);
  960. $this->assertEquals(3, $result['count']);
  961. $this->assertEquals(2, $result['pageCount']);
  962. $this->assertTrue($result['nextPage']);
  963. $this->assertFalse($result['prevPage']);
  964. $Controller->paginate = array(
  965. 'totals',
  966. 'limit' => 2,
  967. 'page' => 2
  968. );
  969. $result = $Controller->paginate();
  970. $expected = array(
  971. array(
  972. 'PaginatorCustomPost' => array(
  973. 'author_id' => '3',
  974. 'total_posts' => '1'
  975. )
  976. ),
  977. );
  978. $this->assertEquals($expected, $result);
  979. $result = $Controller->request->params['paging']['PaginatorCustomPost'];
  980. $this->assertEquals(1, $result['current']);
  981. $this->assertEquals(3, $result['count']);
  982. $this->assertEquals(2, $result['pageCount']);
  983. $this->assertFalse($result['nextPage']);
  984. $this->assertTrue($result['prevPage']);
  985. }
  986. /**
  987. * test paginate() and custom find with returning other query on count operation,
  988. * to make sure the correct count is returned.
  989. *
  990. * @return void
  991. */
  992. public function testPaginateCustomFindCount() {
  993. $this->markTestIncomplete('Need to revisit once models work again.');
  994. $Controller = new Controller($this->request);
  995. $Controller->uses = array('PaginatorCustomPost');
  996. $Controller->constructClasses();
  997. $data = array('author_id' => 2, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
  998. $Controller->PaginatorCustomPost->create($data);
  999. $result = $Controller->PaginatorCustomPost->save();
  1000. $this->assertTrue(!empty($result));
  1001. $Controller->paginate = array(
  1002. 'totalsOperation',
  1003. 'limit' => 2
  1004. );
  1005. $result = $Controller->paginate();
  1006. $expected = array(
  1007. array(
  1008. 'PaginatorCustomPost' => array(
  1009. 'author_id' => '1',
  1010. 'total_posts' => '2'
  1011. ),
  1012. 'Author' => array(
  1013. 'user' => 'mariano',
  1014. )
  1015. ),
  1016. array(
  1017. 'PaginatorCustomPost' => array(
  1018. 'author_id' => '2',
  1019. 'total_posts' => '1'
  1020. ),
  1021. 'Author' => array(
  1022. 'user' => 'nate'
  1023. )
  1024. )
  1025. );
  1026. $this->assertEquals($expected, $result);
  1027. $result = $Controller->request->params['paging']['PaginatorCustomPost'];
  1028. $this->assertEquals(2, $result['current']);
  1029. $this->assertEquals(3, $result['count']);
  1030. $this->assertEquals(2, $result['pageCount']);
  1031. $this->assertTrue($result['nextPage']);
  1032. $this->assertFalse($result['prevPage']);
  1033. }
  1034. }