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:
gwoo 2008-06-27 00:43:31 +00:00
parent 5e92674990
commit 1576a83505
2 changed files with 29 additions and 23 deletions

View file

@ -298,6 +298,7 @@ class Controller extends Object {
* @see Component::init()
*/
function _initComponents() {
trigger_error(__('Controller::_initComponents(); deprecated, use $this->Component->init($this);', true), E_USER_WARNING);
$this->Component->init($this);
}
/**
@ -845,15 +846,6 @@ class Controller extends Object {
}
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.
*
@ -909,6 +901,7 @@ class Controller extends Object {
return array();
}
$options = array_merge($this->params, $this->params['url'], $this->passedArgs);
if (isset($this->paginate[$object->alias])) {
$defaults = $this->paginate[$object->alias];
} else {
@ -926,9 +919,13 @@ class Controller extends Object {
}
if (!empty($options['order']) && is_array($options['order'])) {
$key = key($options['order']);
if (strpos($key, '.') === false && $object->hasField($key)) {
$options['order'][$object->alias . '.' . $key] = $options['order'][$key];
$key = $field = key($options['order']);
if (strpos($key, '.') !== false) {
$field = array_pop(explode('.', $key));
}
if ($object->hasField($field)) {
$options['order'][$object->alias . '.' . $field] = $options['order'][$key];
} else {
unset($options['order'][$key]);
}
}

View file

@ -303,6 +303,26 @@ class ControllerTest extends CakeTestCase {
$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' => '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
@ -446,17 +466,6 @@ class ControllerTest extends CakeTestCase {
$this->assertTrue($Controller->_afterScaffoldSaveError(''));
$this->assertFalse($Controller->_scaffoldError(''));
}
/**
* testCleanUpFields method
*
* @access public
* @return void
*/
function testCleanUpFields() {
$Controller =& new Controller();
$Controller->cleanUpFields();
$this->assertError();
}
/**
* testRedirect method
*