Controller::loadModel() now returns true when model is succesfully instantiated as stated in docblock. Added test case.

This commit is contained in:
ADmad 2010-05-02 05:32:53 +05:30
parent 257665eb5b
commit f386dca6d8
2 changed files with 24 additions and 2 deletions

View file

@ -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;
} }
/** /**

View file

@ -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
* *