Skip to content
Permalink
Browse files

Fix: Incorrect model being used as Controller::$modelClass

We cannot be sure that Controller::$uses have not been iterated, so
reset the array to use the first value.
  • Loading branch information...
rchavik committed May 24, 2013
1 parent ca1f9e8 commit a63b54c34bed2085ae5e297cc8aed255aa315fb4
Showing with 14 additions and 1 deletion.
  1. +1 −1 lib/Cake/Controller/Controller.php
  2. +13 −0 lib/Cake/Test/Case/Controller/ControllerMergeVarsTest.php
@@ -634,7 +634,7 @@ public function constructClasses() {
$this->_mergeControllerVars();
if ($this->uses) {
$this->uses = (array)$this->uses;
list(, $this->modelClass) = pluginSplit(current($this->uses));
list(, $this->modelClass) = pluginSplit(reset($this->uses));
}
$this->Components->init($this);
return true;
@@ -250,4 +250,17 @@ public function testMergeVarsNotGreedy() {
$this->assertFalse(isset($Controller->Session));
}
/**
* Ensure that $modelClass is correct even when Controller::$uses
* has been iterated, eg: by a Component, or event handlers.
*/
public function testMergeVarsModelClass() {
$Controller = new MergeVariablescontroller();
$Controller->uses = array('Test', 'TestAlias');
$lastModel = end($Controller->uses);
$Controller->constructClasses();
$this->assertEquals($Controller->uses[0], $Controller->modelClass);
}
}

0 comments on commit a63b54c

Please sign in to comment.
You can’t perform that action at this time.