Skip to content

Commit

Permalink
Merge pull request #1282 from dereuromark/master-model-class
Browse files Browse the repository at this point in the history
$this->modelClass needs to be correct prior to the components init()
  • Loading branch information
markstory committed May 14, 2013
2 parents f7d106a + 9fd2af9 commit de7535d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Controller.php
Expand Up @@ -632,11 +632,11 @@ public function implementedEvents() {
*/
public function constructClasses() {
$this->_mergeControllerVars();
$this->Components->init($this);
if ($this->uses) {
$this->uses = (array)$this->uses;
list(, $this->modelClass) = pluginSplit(current($this->uses));
}
$this->Components->init($this);
return true;
}

Expand Down
23 changes: 23 additions & 0 deletions lib/Cake/Test/Case/Controller/ControllerTest.php
Expand Up @@ -360,6 +360,13 @@ public function beforeRender(Controller $controller) {

class Test2Component extends TestComponent {

public $model;

public function __construct(ComponentCollection $collection, $settings) {
$this->controller = $collection->getController();
$this->model = $this->controller->modelClass;
}

public function beforeRender(Controller $controller) {
return false;
}
Expand Down Expand Up @@ -526,6 +533,22 @@ public function testConstructClasses() {
$this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost'));
}

/**
* testConstructClassesWithComponents method
*
* @return void
*/
public function testConstructClassesWithComponents() {
$Controller = new TestPluginController(new CakeRequest(), new CakeResponse());
$Controller->uses = array('NameTest');
$Controller->components[] = 'Test2';

$Controller->constructClasses();
$this->assertEquals('NameTest', $Controller->Test2->model);
$this->assertEquals('Name', $Controller->NameTest->name);
$this->assertEquals('Name', $Controller->NameTest->alias);
}

/**
* testAliasName method
*
Expand Down

0 comments on commit de7535d

Please sign in to comment.