mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
63b392a26b
commit
efd86a498a
2 changed files with 18 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue