mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-20 08:29:55 +00:00
fixing issue with sort in pagination and adding tests, removes previously deprecated controller methods and adds trigger_error to recent ones
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7276 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
5e92674990
commit
1576a83505
2 changed files with 29 additions and 23 deletions
|
@ -298,6 +298,7 @@ class Controller extends Object {
|
||||||
* @see Component::init()
|
* @see Component::init()
|
||||||
*/
|
*/
|
||||||
function _initComponents() {
|
function _initComponents() {
|
||||||
|
trigger_error(__('Controller::_initComponents(); deprecated, use $this->Component->init($this);', true), E_USER_WARNING);
|
||||||
$this->Component->init($this);
|
$this->Component->init($this);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -845,15 +846,6 @@ class Controller extends Object {
|
||||||
}
|
}
|
||||||
return $cond;
|
return $cond;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Deprecated, see Model::deconstruct();
|
|
||||||
*
|
|
||||||
* @see Model::deconstruct()
|
|
||||||
* @deprecated as of 1.2.0.5970
|
|
||||||
*/
|
|
||||||
function cleanUpFields($modelClass = null) {
|
|
||||||
trigger_error(__('Controller::cleanUpFields() - Deprecated: this functionality has been moved to Model and is handled automatically', true), E_USER_WARNING);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Handles automatic pagination of model records.
|
* Handles automatic pagination of model records.
|
||||||
*
|
*
|
||||||
|
@ -909,6 +901,7 @@ class Controller extends Object {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
$options = array_merge($this->params, $this->params['url'], $this->passedArgs);
|
$options = array_merge($this->params, $this->params['url'], $this->passedArgs);
|
||||||
|
|
||||||
if (isset($this->paginate[$object->alias])) {
|
if (isset($this->paginate[$object->alias])) {
|
||||||
$defaults = $this->paginate[$object->alias];
|
$defaults = $this->paginate[$object->alias];
|
||||||
} else {
|
} else {
|
||||||
|
@ -926,9 +919,13 @@ class Controller extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($options['order']) && is_array($options['order'])) {
|
if (!empty($options['order']) && is_array($options['order'])) {
|
||||||
$key = key($options['order']);
|
$key = $field = key($options['order']);
|
||||||
if (strpos($key, '.') === false && $object->hasField($key)) {
|
if (strpos($key, '.') !== false) {
|
||||||
$options['order'][$object->alias . '.' . $key] = $options['order'][$key];
|
$field = array_pop(explode('.', $key));
|
||||||
|
}
|
||||||
|
if ($object->hasField($field)) {
|
||||||
|
$options['order'][$object->alias . '.' . $field] = $options['order'][$key];
|
||||||
|
} else {
|
||||||
unset($options['order'][$key]);
|
unset($options['order'][$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,6 +303,26 @@ class ControllerTest extends CakeTestCase {
|
||||||
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
|
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
|
||||||
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
|
||||||
$this->assertEqual($results, array(1, 2, 3));
|
$this->assertEqual($results, array(1, 2, 3));
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('sort' => 'ControllerPost.id', 'direction' => 'asc');
|
||||||
|
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
|
||||||
|
$this->assertEqual($results, array(1, 2, 3));
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('sort' => 'ControllerPost.id', 'direction' => 'desc');
|
||||||
|
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
|
||||||
|
$this->assertEqual($results, array(3, 2, 1));
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('sort' => 'id', 'direction' => 'desc');
|
||||||
|
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
|
||||||
|
$this->assertEqual($results, array(3, 2, 1));
|
||||||
|
|
||||||
|
$Controller->passedArgs = array('sort' => 'NotExisting.field', 'direction' => 'desc');
|
||||||
|
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
|
||||||
|
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
|
||||||
|
$this->assertEqual($results, array(1, 2, 3));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testPaginateExtraParams method
|
* testPaginateExtraParams method
|
||||||
|
@ -446,17 +466,6 @@ class ControllerTest extends CakeTestCase {
|
||||||
$this->assertTrue($Controller->_afterScaffoldSaveError(''));
|
$this->assertTrue($Controller->_afterScaffoldSaveError(''));
|
||||||
$this->assertFalse($Controller->_scaffoldError(''));
|
$this->assertFalse($Controller->_scaffoldError(''));
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* testCleanUpFields method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function testCleanUpFields() {
|
|
||||||
$Controller =& new Controller();
|
|
||||||
$Controller->cleanUpFields();
|
|
||||||
$this->assertError();
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* testRedirect method
|
* testRedirect method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue