From 09fae6203d84d5a8ccfbe28bd8e063cfbceade3a Mon Sep 17 00:00:00 2001 From: gwoo Date: Mon, 2 Jun 2008 04:57:06 +0000 Subject: [PATCH] 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 --- cake/libs/controller/component.php | 16 ++++++------- .../cases/libs/controller/component.test.php | 24 +++++++++++++++---- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cake/libs/controller/component.php b/cake/libs/controller/component.php index 3a95746b3..05e5567cb 100644 --- a/cake/libs/controller/component.php +++ b/cake/libs/controller/component.php @@ -183,15 +183,15 @@ class Component extends Object { } } - if ($componentCn == 'SessionComponent') { - $object->{$component} =& new $componentCn($base); + if (isset($this->__loaded[$component])) { + $object->{$component} =& $this->__loaded[$component]; } else { - $object->{$component} =& new $componentCn(); - } - - $object->{$component}->enabled = true; - - if (!isset($this->__loaded[$component])) { + if ($componentCn == 'SessionComponent') { + $object->{$component} =& new $componentCn($base); + } else { + $object->{$component} =& new $componentCn(); + } + $object->{$component}->enabled = true; $this->__loaded[$component] =& $object->{$component}; } diff --git a/cake/tests/cases/libs/controller/component.test.php b/cake/tests/cases/libs/controller/component.test.php index a6bd055bb..91592206a 100644 --- a/cake/tests/cases/libs/controller/component.test.php +++ b/cake/tests/cases/libs/controller/component.test.php @@ -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'); } } ?> \ No newline at end of file