fixing issue with references from latest component refactor. test case added

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7088 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-02 04:57:06 +00:00
parent 6c48154725
commit 09fae6203d
2 changed files with 28 additions and 12 deletions

View file

@ -183,15 +183,15 @@ class Component extends Object {
}
}
if (isset($this->__loaded[$component])) {
$object->{$component} =& $this->__loaded[$component];
} else {
if ($componentCn == 'SessionComponent') {
$object->{$component} =& new $componentCn($base);
} else {
$object->{$component} =& new $componentCn();
}
$object->{$component}->enabled = true;
if (!isset($this->__loaded[$component])) {
$this->__loaded[$component] =& $object->{$component};
}

View file

@ -41,10 +41,10 @@ class AppleComponent extends Object {
var $components = array('Orange');
var $name = null;
var $testName = null;
function startup(&$controller) {
$this->name = $controller->name;
$this->testName = $controller->name;
}
}
@ -52,9 +52,14 @@ class OrangeComponent extends Object {
var $components = array('Banana');
function initialize(&$controller) {
$this->Banana->testField = 'OrangeField';
}
}
class BananaComponent extends Object {
var $testField = 'BananaField';
}
class ComponentTest extends CakeTestCase {
@ -121,11 +126,22 @@ class ComponentTest extends CakeTestCase {
$Controller->constructClasses();
$this->assertTrue(is_a($Controller->Apple, 'AppleComponent'));
$this->assertEqual($Controller->Apple->name, null);
$this->assertEqual($Controller->Apple->testName, null);
$Controller->Component->startup($Controller);
$this->assertEqual($Controller->Apple->name, 'ComponentTest');
$this->assertEqual($Controller->Apple->testName, 'ComponentTest');
}
function testMultipleComponentInitialize() {
$Controller =& new ComponentTestController();
$Controller->components = array('Orange', 'Banana');
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$this->assertEqual($Controller->Banana->testField, 'OrangeField');
$this->assertEqual($Controller->Orange->Banana->testField, 'OrangeField');
}
}
?>