mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-03 14:43:49 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -4,19 +4,18 @@
|
|||
*
|
||||
* Series of tests for paginator component.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Controller.Component
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Controller', 'Controller');
|
||||
|
@ -31,13 +30,6 @@ App::uses('CakeResponse', 'Network');
|
|||
*/
|
||||
class PaginatorTestController extends Controller {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'PaginatorTest'
|
||||
*/
|
||||
public $name = 'PaginatorTest';
|
||||
|
||||
/**
|
||||
* components property
|
||||
*
|
||||
|
@ -53,17 +45,10 @@ class PaginatorTestController extends Controller {
|
|||
*/
|
||||
class PaginatorControllerPost extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'PaginatorControllerPost'
|
||||
*/
|
||||
public $name = 'PaginatorControllerPost';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'posts'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'posts';
|
||||
|
||||
|
@ -106,7 +91,7 @@ class PaginatorControllerPost extends CakeTestModel {
|
|||
* @return void
|
||||
*/
|
||||
public function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
|
||||
if ($conditions == 'popular') {
|
||||
if ($conditions === 'popular') {
|
||||
$conditions = array($this->name . '.' . $this->primaryKey . ' > ' => '1');
|
||||
$options = Hash::merge($fields, compact('conditions'));
|
||||
return parent::find('all', $options);
|
||||
|
@ -123,27 +108,21 @@ class PaginatorControllerPost extends CakeTestModel {
|
|||
*/
|
||||
class ControllerPaginateModel extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'ControllerPaginateModel'
|
||||
*/
|
||||
public $name = 'ControllerPaginateModel';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'comments'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'comments';
|
||||
|
||||
/**
|
||||
* paginate method
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra) {
|
||||
$this->extra = $extra;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,21 +146,21 @@ class PaginatorControllerComment extends CakeTestModel {
|
|||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'Comment'
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'Comment';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'comments'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'comments';
|
||||
|
||||
/**
|
||||
* alias property
|
||||
*
|
||||
* @var string 'PaginatorControllerComment'
|
||||
* @var string
|
||||
*/
|
||||
public $alias = 'PaginatorControllerComment';
|
||||
}
|
||||
|
@ -193,35 +172,21 @@ class PaginatorControllerComment extends CakeTestModel {
|
|||
*/
|
||||
class PaginatorAuthor extends CakeTestModel {
|
||||
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'PaginatorAuthor'
|
||||
*/
|
||||
public $name = 'PaginatorAuthor';
|
||||
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var string 'authors'
|
||||
* @var string
|
||||
*/
|
||||
public $useTable = 'authors';
|
||||
|
||||
/**
|
||||
* alias property
|
||||
*
|
||||
* @var string 'PaginatorAuthor'
|
||||
*/
|
||||
public $alias = 'PaginatorAuthor';
|
||||
|
||||
/**
|
||||
* alias property
|
||||
*
|
||||
* @var string 'PaginatorAuthor'
|
||||
* @var string
|
||||
*/
|
||||
public $virtualFields = array(
|
||||
'joined_offset' => 'PaginatorAuthor.id + 1'
|
||||
);
|
||||
'joined_offset' => 'PaginatorAuthor.id + 1'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
@ -276,7 +241,7 @@ class PaginatorCustomPost extends CakeTestModel {
|
|||
* @return array
|
||||
*/
|
||||
protected function _findTotals($state, $query, $results = array()) {
|
||||
if ($state == 'before') {
|
||||
if ($state === 'before') {
|
||||
$query['fields'] = array('author_id');
|
||||
$this->virtualFields['total_posts'] = "COUNT({$this->alias}.id)";
|
||||
$query['fields'][] = 'total_posts';
|
||||
|
@ -294,7 +259,7 @@ class PaginatorCustomPost extends CakeTestModel {
|
|||
* @return array
|
||||
*/
|
||||
protected function _findTotalsOperation($state, $query, $results = array()) {
|
||||
if ($state == 'before') {
|
||||
if ($state === 'before') {
|
||||
if (!empty($query['operation']) && $query['operation'] === 'count') {
|
||||
unset($query['limit']);
|
||||
$query['recursive'] = -1;
|
||||
|
@ -353,12 +318,20 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$Controller->request->query = array();
|
||||
$Controller->constructClasses();
|
||||
|
||||
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
|
||||
$this->assertEquals(array(1, 2, 3), $results);
|
||||
$Controller->PaginatorControllerPost->order = null;
|
||||
|
||||
$Controller->Paginator->settings = array(
|
||||
'order' => array('PaginatorControllerComment.id' => 'ASC')
|
||||
);
|
||||
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id');
|
||||
$this->assertEquals(array(1, 2, 3, 4, 5, 6), $results);
|
||||
|
||||
$Controller->Paginator->settings = array(
|
||||
'order' => array('PaginatorControllerPost.id' => 'ASC')
|
||||
);
|
||||
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
|
||||
$this->assertEquals(array(1, 2, 3), $results);
|
||||
|
||||
$Controller->modelClass = null;
|
||||
|
||||
$Controller->uses[0] = 'Plugin.PaginatorControllerPost';
|
||||
|
@ -385,16 +358,16 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
|
||||
$this->assertEquals(array(3, 2, 1), $results);
|
||||
|
||||
$Controller->request->params['named'] = array('sort' => 'NotExisting.field', 'direction' => 'desc');
|
||||
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
|
||||
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page'], 'Invalid field in query %s');
|
||||
$this->assertEquals(array(1, 2, 3), $results);
|
||||
$Controller->request->params['named'] = array('sort' => 'NotExisting.field', 'direction' => 'desc', 'limit' => 2);
|
||||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
|
||||
$this->assertEquals(array(), $Controller->PaginatorControllerPost->lastQueries[1]['order'], 'no order should be set.');
|
||||
|
||||
$Controller->request->params['named'] = array(
|
||||
'sort' => 'PaginatorControllerPost.author_id', 'direction' => 'allYourBase'
|
||||
);
|
||||
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
|
||||
$this->assertEquals(array('PaginatorControllerPost.author_id' => 'asc'), $Controller->PaginatorControllerPost->lastQueries[1]['order'][0]);
|
||||
$this->assertEquals(array('PaginatorControllerPost.author_id' => 'asc'), $Controller->PaginatorControllerPost->lastQueries[0]['order']);
|
||||
$this->assertEquals(array(1, 3, 2), $results);
|
||||
|
||||
$Controller->request->params['named'] = array();
|
||||
|
@ -402,16 +375,16 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertSame(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true);
|
||||
$this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']);
|
||||
$this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']);
|
||||
|
||||
$Controller->request->params['named'] = array();
|
||||
$Controller->Paginator->settings = array('limit' => 'garbage!', 'maxLimit' => 10, 'paramType' => 'named');
|
||||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertSame(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true);
|
||||
$this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']);
|
||||
$this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']);
|
||||
|
||||
$Controller->request->params['named'] = array();
|
||||
$Controller->Paginator->settings = array('limit' => '-1', 'maxLimit' => 10, 'paramType' => 'named');
|
||||
|
@ -420,8 +393,8 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['limit'], 1);
|
||||
$this->assertSame(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false);
|
||||
$this->assertSame($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true);
|
||||
$this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']);
|
||||
$this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']);
|
||||
|
||||
$Controller->Paginator->settings = array('conditions' => array('PaginatorAuthor.user' => 'mariano'));
|
||||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
|
@ -473,23 +446,34 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$Controller->constructClasses();
|
||||
|
||||
$Controller->request->params['named'] = array('page' => '-1', 'contain' => array('PaginatorControllerComment'));
|
||||
$Controller->Paginator->settings = array(
|
||||
'order' => array('PaginatorControllerPost.id' => 'ASC')
|
||||
);
|
||||
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
|
||||
$this->assertEquals(array(1, 2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
|
||||
$this->assertTrue(!isset($Controller->PaginatorControllerPost->lastQueries[1]['contain']));
|
||||
|
||||
$Controller->Paginator->settings = array(
|
||||
'order' => array('PaginatorControllerPost.author_id')
|
||||
);
|
||||
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
|
||||
$this->assertEquals(array(1, 3, 2), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
|
||||
|
||||
$Controller->request->params['named'] = array('page' => '-1');
|
||||
$Controller->Paginator->settings = array(
|
||||
'PaginatorControllerPost' => array(
|
||||
'contain' => array('PaginatorControllerComment'),
|
||||
'maxLimit' => 10,
|
||||
'paramType' => 'named'
|
||||
'paramType' => 'named',
|
||||
'order' => array('PaginatorControllerPost.id' => 'ASC')
|
||||
),
|
||||
);
|
||||
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
|
||||
$this->assertEquals(array(1, 2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
|
||||
$this->assertTrue(isset($Controller->PaginatorControllerPost->lastQueries[1]['contain']));
|
||||
$this->assertTrue(isset($Controller->PaginatorControllerPost->lastQueries[0]['contain']));
|
||||
|
||||
$Controller->Paginator->settings = array(
|
||||
'PaginatorControllerPost' => array(
|
||||
|
@ -498,14 +482,14 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
);
|
||||
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(array(2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
|
||||
$this->assertEquals(array('PaginatorControllerPost.id > ' => '1'), $Controller->PaginatorControllerPost->lastQueries[1]['conditions']);
|
||||
$this->assertEquals(array('PaginatorControllerPost.id > ' => '1'), $Controller->PaginatorControllerPost->lastQueries[0]['conditions']);
|
||||
|
||||
$Controller->request->params['named'] = array('limit' => 12);
|
||||
$Controller->Paginator->settings = array('limit' => 30, 'maxLimit' => 100, 'paramType' => 'named');
|
||||
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$paging = $Controller->params['paging']['PaginatorControllerPost'];
|
||||
|
||||
$this->assertEquals(12, $Controller->PaginatorControllerPost->lastQueries[1]['limit']);
|
||||
$this->assertEquals(12, $Controller->PaginatorControllerPost->lastQueries[0]['limit']);
|
||||
$this->assertEquals(12, $paging['options']['limit']);
|
||||
|
||||
$Controller = new PaginatorTestController($this->request);
|
||||
|
@ -520,7 +504,7 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
'paramType' => 'named'
|
||||
)
|
||||
);
|
||||
$result = $Controller->Paginator->paginate('ControllerPaginateModel');
|
||||
$Controller->Paginator->paginate('ControllerPaginateModel');
|
||||
$expected = array(
|
||||
'contain' => array('ControllerPaginateModel'),
|
||||
'group' => 'Comment.author_id',
|
||||
|
@ -558,7 +542,7 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
public function testPaginateSpecialType() {
|
||||
$Controller = new PaginatorTestController($this->request);
|
||||
$Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
|
||||
$Controller->passedArgs[] = '1';
|
||||
$Controller->request->params['pass'][] = '1';
|
||||
$Controller->params['url'] = array();
|
||||
$Controller->constructClasses();
|
||||
|
||||
|
@ -574,7 +558,7 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
|
||||
$this->assertEquals(array(2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
|
||||
$this->assertEquals(
|
||||
$Controller->PaginatorControllerPost->lastQueries[1]['conditions'],
|
||||
$Controller->PaginatorControllerPost->lastQueries[0]['conditions'],
|
||||
array('PaginatorControllerPost.id > ' => '1')
|
||||
);
|
||||
$this->assertFalse(isset($Controller->params['paging']['PaginatorControllerPost']['options'][0]));
|
||||
|
@ -600,6 +584,53 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertEquals(array(3, 2, 1), $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* test paginate() and model default order
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPaginateOrderModelDefault() {
|
||||
$Controller = new PaginatorTestController($this->request);
|
||||
$Controller->uses = array('PaginatorControllerPost');
|
||||
$Controller->params['url'] = array();
|
||||
$Controller->constructClasses();
|
||||
$Controller->PaginatorControllerPost->order = array(
|
||||
$Controller->PaginatorControllerPost->alias . '.created' => 'desc'
|
||||
);
|
||||
|
||||
$Controller->Paginator->settings = array(
|
||||
'fields' => array('id', 'title', 'created'),
|
||||
'maxLimit' => 10,
|
||||
'paramType' => 'named'
|
||||
);
|
||||
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$expected = array('2007-03-18 10:43:23', '2007-03-18 10:41:23', '2007-03-18 10:39:23');
|
||||
$this->assertEquals($expected, Hash::extract($result, '{n}.PaginatorControllerPost.created'));
|
||||
$this->assertEquals(
|
||||
$Controller->PaginatorControllerPost->order,
|
||||
$Controller->request->paging['PaginatorControllerPost']['options']['order']
|
||||
);
|
||||
|
||||
$Controller->PaginatorControllerPost->order = array('PaginatorControllerPost.id');
|
||||
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
|
||||
$this->assertEquals(array('PaginatorControllerPost.id' => 'asc'), $result['order']);
|
||||
|
||||
$Controller->PaginatorControllerPost->order = 'PaginatorControllerPost.id';
|
||||
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
|
||||
$this->assertArrayNotHasKey('order', $result);
|
||||
|
||||
$Controller->PaginatorControllerPost->order = array(
|
||||
'PaginatorControllerPost.id',
|
||||
'PaginatorControllerPost.created' => 'asc'
|
||||
);
|
||||
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
|
||||
$expected = array(
|
||||
'PaginatorControllerPost.id' => 'asc',
|
||||
'PaginatorControllerPost.created' => 'asc'
|
||||
);
|
||||
$this->assertEquals($expected, $result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test paginate() and virtualField interactions
|
||||
*
|
||||
|
@ -656,6 +687,7 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
* Tests for missing models
|
||||
*
|
||||
* @expectedException MissingModelException
|
||||
* @return void
|
||||
*/
|
||||
public function testPaginateMissingModel() {
|
||||
$Controller = new PaginatorTestController($this->request);
|
||||
|
@ -710,6 +742,28 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test mergeOptions with customFind key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeOptionsCustomFindKey() {
|
||||
$this->request->params['named'] = array(
|
||||
'page' => 10,
|
||||
'limit' => 10
|
||||
);
|
||||
$this->Paginator->settings = array(
|
||||
'page' => 1,
|
||||
'limit' => 20,
|
||||
'maxLimit' => 100,
|
||||
'paramType' => 'named',
|
||||
'findType' => 'myCustomFind'
|
||||
);
|
||||
$result = $this->Paginator->mergeOptions('Post');
|
||||
$expected = array('page' => 10, 'limit' => 10, 'maxLimit' => 100, 'paramType' => 'named', 'findType' => 'myCustomFind');
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test merging options from the querystring.
|
||||
*
|
||||
|
@ -788,6 +842,40 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test mergeOptions with limit > maxLimit in code.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMergeOptionsMaxLimit() {
|
||||
$this->Paginator->settings = array(
|
||||
'limit' => 200,
|
||||
'paramType' => 'named',
|
||||
);
|
||||
$result = $this->Paginator->mergeOptions('Post');
|
||||
$expected = array('page' => 1, 'limit' => 200, 'maxLimit' => 100, 'paramType' => 'named');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$this->Paginator->settings = array(
|
||||
'maxLimit' => 10,
|
||||
'paramType' => 'named',
|
||||
);
|
||||
$result = $this->Paginator->mergeOptions('Post');
|
||||
$expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 10, 'paramType' => 'named');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$this->request->params['named'] = array(
|
||||
'limit' => 500
|
||||
);
|
||||
$this->Paginator->settings = array(
|
||||
'limit' => 150,
|
||||
'paramType' => 'named',
|
||||
);
|
||||
$result = $this->Paginator->mergeOptions('Post');
|
||||
$expected = array('page' => 1, 'limit' => 500, 'maxLimit' => 100, 'paramType' => 'named');
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that invalid directions are ignored.
|
||||
*
|
||||
|
@ -806,6 +894,9 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
|
||||
/**
|
||||
* Test that a really large page number gets clamped to the max page size.
|
||||
*
|
||||
* @expectedException NotFoundException
|
||||
* @return void
|
||||
*/
|
||||
public function testOutOfRangePageNumberGetsClamped() {
|
||||
$Controller = new PaginatorTestController($this->request);
|
||||
|
@ -816,21 +907,52 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$Controller->constructClasses();
|
||||
$Controller->PaginatorControllerPost->recursive = 0;
|
||||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$Controller->request->params['paging']['PaginatorControllerPost']['page'],
|
||||
'Super big page number should be capped to max number of pages'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a really REALLY large page number gets clamped to the max page size.
|
||||
*
|
||||
* @expectedException NotFoundException
|
||||
* @return void
|
||||
*/
|
||||
public function testOutOfVeryBigPageNumberGetsClamped() {
|
||||
$Controller = new PaginatorTestController($this->request);
|
||||
$Controller->uses = array('PaginatorControllerPost');
|
||||
$Controller->params['named'] = array(
|
||||
'page' => '3000000000000000000000000',
|
||||
);
|
||||
$Controller->constructClasses();
|
||||
$Controller->PaginatorControllerPost->recursive = 0;
|
||||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
}
|
||||
|
||||
/**
|
||||
* testOutOfRangePageNumberAndPageCountZero
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testOutOfRangePageNumberAndPageCountZero() {
|
||||
$Controller = new PaginatorTestController($this->request);
|
||||
$Controller->uses = array('PaginatorControllerPost');
|
||||
$Controller->params['named'] = array(
|
||||
'page' => '3000',
|
||||
);
|
||||
$Controller->constructClasses();
|
||||
$Controller->PaginatorControllerPost->recursive = 0;
|
||||
$Controller->paginate = array(
|
||||
'conditions' => array('PaginatorControllerPost.id >' => 100)
|
||||
);
|
||||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$Controller->request->params['paging']['PaginatorControllerPost']['page'],
|
||||
'Page number should not be 0'
|
||||
);
|
||||
|
||||
try {
|
||||
$Controller->Paginator->paginate('PaginatorControllerPost');
|
||||
$this->fail();
|
||||
} catch (NotFoundException $e) {
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$Controller->request->params['paging']['PaginatorControllerPost']['page'],
|
||||
'Page number should not be 0'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -849,6 +971,23 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertNull($result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that fields in the whitelist are not validated
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateSortWhitelistTrusted() {
|
||||
$model = $this->getMock('Model');
|
||||
$model->alias = 'model';
|
||||
$model->expects($this->never())->method('hasField');
|
||||
|
||||
$options = array('sort' => 'body', 'direction' => 'asc');
|
||||
$result = $this->Paginator->validateSort($model, $options, array('body'));
|
||||
|
||||
$expected = array('body' => 'asc');
|
||||
$this->assertEquals($expected, $result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that virtual fields work.
|
||||
*
|
||||
|
@ -874,6 +1013,30 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertEquals('desc', $result['order']['something']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that sorting fields is alias specific
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateSortSharedFields() {
|
||||
$model = $this->getMock('Model');
|
||||
$model->alias = 'Parent';
|
||||
$model->Child = $this->getMock('Model');
|
||||
$model->Child->alias = 'Child';
|
||||
|
||||
$model->expects($this->never())
|
||||
->method('hasField');
|
||||
|
||||
$model->Child->expects($this->at(0))
|
||||
->method('hasField')
|
||||
->with('something')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$options = array('sort' => 'Child.something', 'direction' => 'desc');
|
||||
$result = $this->Paginator->validateSort($model, $options);
|
||||
|
||||
$this->assertEquals('desc', $result['order']['Child.something']);
|
||||
}
|
||||
/**
|
||||
* test that multiple sort works.
|
||||
*
|
||||
|
@ -884,10 +1047,12 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$model->alias = 'model';
|
||||
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));
|
||||
|
||||
$options = array('order' => array(
|
||||
'author_id' => 'asc',
|
||||
'title' => 'asc'
|
||||
));
|
||||
$options = array(
|
||||
'order' => array(
|
||||
'author_id' => 'asc',
|
||||
'title' => 'asc'
|
||||
)
|
||||
);
|
||||
$result = $this->Paginator->validateSort($model, $options);
|
||||
$expected = array(
|
||||
'model.author_id' => 'asc',
|
||||
|
@ -917,6 +1082,21 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertEquals($options['order'], $result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test sorting with incorrect aliases on valid fields.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateSortInvalidAlias() {
|
||||
$model = $this->getMock('Model');
|
||||
$model->alias = 'Model';
|
||||
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));
|
||||
|
||||
$options = array('sort' => 'Derp.id');
|
||||
$result = $this->Paginator->validateSort($model, $options);
|
||||
$this->assertEquals(array(), $result['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that maxLimit is respected
|
||||
*
|
||||
|
@ -948,32 +1128,32 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$Controller = new Controller($this->request);
|
||||
|
||||
$Controller->uses = array('PaginatorControllerPost', 'ControllerComment');
|
||||
$Controller->passedArgs[] = '1';
|
||||
$Controller->request->params['pass'][] = '1';
|
||||
$Controller->constructClasses();
|
||||
|
||||
$Controller->request->params['named'] = array(
|
||||
'contain' => array('ControllerComment'), 'limit' => '1000'
|
||||
);
|
||||
$result = $Controller->paginate('PaginatorControllerPost');
|
||||
$Controller->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(100, $Controller->params['paging']['PaginatorControllerPost']['options']['limit']);
|
||||
|
||||
$Controller->request->params['named'] = array(
|
||||
'contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000
|
||||
);
|
||||
$result = $Controller->paginate('PaginatorControllerPost');
|
||||
$Controller->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(100, $Controller->params['paging']['PaginatorControllerPost']['options']['limit']);
|
||||
|
||||
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '10');
|
||||
$result = $Controller->paginate('PaginatorControllerPost');
|
||||
$Controller->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(10, $Controller->params['paging']['PaginatorControllerPost']['options']['limit']);
|
||||
|
||||
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000');
|
||||
$Controller->paginate = array('maxLimit' => 2000, 'paramType' => 'named');
|
||||
$result = $Controller->paginate('PaginatorControllerPost');
|
||||
$Controller->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(1000, $Controller->params['paging']['PaginatorControllerPost']['options']['limit']);
|
||||
|
||||
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '5000');
|
||||
$result = $Controller->paginate('PaginatorControllerPost');
|
||||
$Controller->paginate('PaginatorControllerPost');
|
||||
$this->assertEquals(2000, $Controller->params['paging']['PaginatorControllerPost']['options']['limit']);
|
||||
}
|
||||
|
||||
|
@ -999,11 +1179,26 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
), false);
|
||||
|
||||
$Controller->paginate = array(
|
||||
'fields' => array('PaginatorControllerComment.id', 'title', 'PaginatorControllerPost.title'),
|
||||
'fields' => array(
|
||||
'PaginatorControllerComment.id',
|
||||
'title',
|
||||
'PaginatorControllerPost.title'
|
||||
),
|
||||
);
|
||||
$Controller->passedArgs = array('sort' => 'PaginatorControllerPost.title', 'dir' => 'asc');
|
||||
$result = $Controller->paginate('PaginatorControllerComment');
|
||||
$this->assertEquals(array(1, 2, 3, 4, 5, 6), Hash::extract($result, '{n}.PaginatorControllerComment.id'));
|
||||
$Controller->request->params['named'] = array(
|
||||
'sort' => 'PaginatorControllerPost.title',
|
||||
'direction' => 'desc'
|
||||
);
|
||||
$result = Hash::extract(
|
||||
$Controller->paginate('PaginatorControllerComment'),
|
||||
'{n}.PaginatorControllerComment.id'
|
||||
);
|
||||
$result1 = array_splice($result, 0, 2);
|
||||
sort($result1);
|
||||
$this->assertEquals(array(5, 6), $result1);
|
||||
|
||||
sort($result);
|
||||
$this->assertEquals(array(1, 2, 3, 4), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1012,7 +1207,7 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testPaginateCustomFind() {
|
||||
$Controller =& new Controller($this->request);
|
||||
$Controller = new Controller($this->request);
|
||||
$Controller->uses = array('PaginatorCustomPost');
|
||||
$Controller->constructClasses();
|
||||
$data = array('author_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
|
||||
|
@ -1052,7 +1247,7 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testPaginateCustomFindFieldsArray() {
|
||||
$Controller =& new Controller($this->request);
|
||||
$Controller = new Controller($this->request);
|
||||
$Controller->uses = array('PaginatorCustomPost');
|
||||
$Controller->constructClasses();
|
||||
$data = array('author_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
|
||||
|
@ -1078,6 +1273,38 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
$this->assertTrue($result['nextPage']);
|
||||
$this->assertFalse($result['prevPage']);
|
||||
}
|
||||
/**
|
||||
* test paginate() and custom find with customFind key, to make sure the correct count is returned.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPaginateCustomFindWithCustomFindKey() {
|
||||
$Controller = new Controller($this->request);
|
||||
$Controller->uses = array('PaginatorCustomPost');
|
||||
$Controller->constructClasses();
|
||||
$data = array('author_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
|
||||
$Controller->PaginatorCustomPost->create($data);
|
||||
$result = $Controller->PaginatorCustomPost->save();
|
||||
$this->assertTrue(!empty($result));
|
||||
|
||||
$Controller->paginate = array(
|
||||
'conditions' => array('PaginatorCustomPost.published' => 'Y'),
|
||||
'findType' => 'list',
|
||||
'limit' => 2
|
||||
);
|
||||
$result = $Controller->paginate();
|
||||
$expected = array(
|
||||
1 => 'First Post',
|
||||
2 => 'Second Post',
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
$result = $Controller->params['paging']['PaginatorCustomPost'];
|
||||
$this->assertEquals(2, $result['current']);
|
||||
$this->assertEquals(3, $result['count']);
|
||||
$this->assertEquals(2, $result['pageCount']);
|
||||
$this->assertTrue($result['nextPage']);
|
||||
$this->assertFalse($result['prevPage']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test paginate() and custom find with fields array, to make sure the correct count is returned.
|
||||
|
@ -1085,7 +1312,7 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testPaginateCustomFindGroupBy() {
|
||||
$Controller =& new Controller($this->request);
|
||||
$Controller = new Controller($this->request);
|
||||
$Controller->uses = array('PaginatorCustomPost');
|
||||
$Controller->constructClasses();
|
||||
$data = array('author_id' => 2, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
|
||||
|
@ -1150,7 +1377,7 @@ class PaginatorComponentTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testPaginateCustomFindCount() {
|
||||
$Controller =& new Controller($this->request);
|
||||
$Controller = new Controller($this->request);
|
||||
$Controller->uses = array('PaginatorCustomPost');
|
||||
$Controller->constructClasses();
|
||||
$data = array('author_id' => 2, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue