mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Controller::loadModel() now returns true when model is succesfully instantiated as stated in docblock. Added test case.
This commit is contained in:
parent
257665eb5b
commit
f386dca6d8
2 changed files with 24 additions and 2 deletions
|
@ -607,7 +607,7 @@ class Controller extends Object {
|
||||||
*
|
*
|
||||||
* @param string $modelClass Name of model class to load
|
* @param string $modelClass Name of model class to load
|
||||||
* @param mixed $id Initial ID the instanced model class should have
|
* @param mixed $id Initial ID the instanced model class should have
|
||||||
* @return mixed true when single model found and instance created error returned if models not found.
|
* @return mixed true when single model found and instance created, error returned if model not found.
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function loadModel($modelClass = null, $id = null) {
|
function loadModel($modelClass = null, $id = null) {
|
||||||
|
@ -657,6 +657,8 @@ class Controller extends Object {
|
||||||
$this->_persist($modelClass, true, $object);
|
$this->_persist($modelClass, true, $object);
|
||||||
$this->modelNames[] = $modelClass;
|
$this->modelNames[] = $modelClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -442,6 +442,26 @@ class ControllerTest extends CakeTestCase {
|
||||||
App::build();
|
App::build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testLoadModel method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testLoadModel() {
|
||||||
|
$Controller =& new Controller();
|
||||||
|
|
||||||
|
$this->assertFalse(isset($Controller->ControllerPost));
|
||||||
|
|
||||||
|
$result = $Controller->loadModel('ControllerPost');
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
|
||||||
|
$this->assertTrue(in_array('ControllerPost', $Controller->modelNames));
|
||||||
|
|
||||||
|
ClassRegistry::flush();
|
||||||
|
unset($Controller);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testConstructClasses method
|
* testConstructClasses method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue