Do type checks when looking for models in Controller::$uses.

This solves issues with models not being added when $uses = true.

Fixes #3774
This commit is contained in:
mark_story 2013-04-19 12:16:18 -04:00
parent 63b392a26b
commit efd86a498a
2 changed files with 18 additions and 5 deletions

View file

@ -723,7 +723,7 @@ class Controller extends Object implements CakeEventListener {
}
$this->uses = ($this->uses) ? (array)$this->uses : array();
if (!in_array($modelClass, $this->uses)) {
if (!in_array($modelClass, $this->uses, true)) {
$this->uses[] = $modelClass;
}

View file

@ -447,11 +447,24 @@ class ControllerTest extends CakeTestCase {
$result = $Controller->loadModel('ControllerPost');
$this->assertTrue($result);
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
$this->assertTrue(in_array('ControllerPost', $Controller->uses));
$this->assertInstanceOf('ControllerPost', $Controller->ControllerPost);
$this->assertContains('ControllerPost', $Controller->uses);
}
ClassRegistry::flush();
unset($Controller);
/**
* Test loadModel() when uses = true.
*
* @return void
*/
public function testLoadModelUsesTrue() {
$request = new CakeRequest('controller_posts/index');
$response = $this->getMock('CakeResponse');
$Controller = new Controller($request, $response);
$Controller->uses = true;
$Controller->loadModel('ControllerPost');
$this->assertInstanceOf('ControllerPost', $Controller->ControllerPost);
$this->assertContains('ControllerPost', $Controller->uses);
}
/**