diff --git a/cake/libs/controller/component_collection.php b/cake/libs/controller/component_collection.php index 4520efa3f..5efb7c888 100644 --- a/cake/libs/controller/component_collection.php +++ b/cake/libs/controller/component_collection.php @@ -74,10 +74,13 @@ class ComponentCollection extends ObjectCollection { * @throws MissingComponentFileException, MissingComponentClassException when the component could not be found */ public function load($component, $settings = array()) { - list($plugin, $name) = pluginSplit($component); - $alias = $name; if (isset($settings['className'])) { - $name = $settings['className']; + $alias = $component; + $component = $settings['className']; + } + list($plugin, $name) = pluginSplit($component); + if (!isset($alias)) { + $alias = $name; } if (isset($this->_loaded[$alias])) { return $this->_loaded[$alias]; @@ -86,13 +89,13 @@ class ComponentCollection extends ObjectCollection { if (!class_exists($componentClass)) { if (!App::import('Component', $component)) { throw new MissingComponentFileException(array( - 'file' => Inflector::underscore($component) . '.php', + 'file' => Inflector::underscore($componentClass) . '.php', 'class' => $componentClass )); } if (!class_exists($componentClass)) { throw new MissingComponentClassException(array( - 'file' => Inflector::underscore($component) . '.php', + 'file' => Inflector::underscore($componentClass) . '.php', 'class' => $componentClass )); } diff --git a/cake/libs/model/behavior_collection.php b/cake/libs/model/behavior_collection.php index c623faa78..2035a77a0 100644 --- a/cake/libs/model/behavior_collection.php +++ b/cake/libs/model/behavior_collection.php @@ -99,12 +99,15 @@ class BehaviorCollection extends ObjectCollection { * @throws MissingBehaviorFileException or MissingBehaviorClassException when a behavior could not be found. */ public function load($behavior, $config = array()) { - list($plugin, $name) = pluginSplit($behavior); - - $alias = $name; if (isset($config['className'])) { - $name = $config['className']; + $alias = $behavior; + $behavior = $config['className']; } + list($plugin, $name) = pluginSplit($behavior); + if (!isset($alias)) { + $alias = $name; + } + $class = $name . 'Behavior'; if (!App::import('Behavior', $behavior)) { diff --git a/cake/libs/view/helper_collection.php b/cake/libs/view/helper_collection.php index f7f628b82..35e6e0dd4 100644 --- a/cake/libs/view/helper_collection.php +++ b/cake/libs/view/helper_collection.php @@ -57,11 +57,13 @@ class HelperCollection extends ObjectCollection { * @throws MissingHelperFileException, MissingHelperClassException when the helper could not be found */ public function load($helper, $settings = array()) { - list($plugin, $name) = pluginSplit($helper, true); - - $alias = $name; if (isset($settings['className'])) { - $name = $settings['className']; + $alias = $helper; + $helper = $settings['className']; + } + list($plugin, $name) = pluginSplit($helper); + if (!isset($alias)) { + $alias = $name; } if (isset($this->_loaded[$alias])) { diff --git a/cake/tests/cases/libs/controller/component_collection.test.php b/cake/tests/cases/libs/controller/component_collection.test.php index c226a5f8a..549e246a3 100644 --- a/cake/tests/cases/libs/controller/component_collection.test.php +++ b/cake/tests/cases/libs/controller/component_collection.test.php @@ -82,6 +82,15 @@ class ComponentCollectionTest extends CakeTestCase { $result = $this->Components->load('Cookie'); $this->assertInstanceOf('CookieAliasComponent', $result); + + App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS))); + $result = $this->Components->load('SomeOther', array('className' => 'TestPlugin.OtherComponent')); + $this->assertInstanceOf('OtherComponentComponent', $result); + $this->assertInstanceOf('OtherComponentComponent', $this->Components->SomeOther); + + $result = $this->Components->attached(); + $this->assertEquals(array('Cookie', 'SomeOther'), $result, 'attached() results are wrong.'); + App::build(); } /** diff --git a/cake/tests/cases/libs/model/behavior_collection.test.php b/cake/tests/cases/libs/model/behavior_collection.test.php index 2c143b3d2..8d653ced9 100644 --- a/cake/tests/cases/libs/model/behavior_collection.test.php +++ b/cake/tests/cases/libs/model/behavior_collection.test.php @@ -451,6 +451,14 @@ class BehaviorCollectionTest extends CakeTestCase { $this->assertEquals($Apple->Behaviors->Test->testMethod($Apple, true), 'working'); $this->assertEquals($Apple->testMethod(true), 'working'); $this->assertEquals($Apple->Behaviors->dispatchMethod($Apple, 'testMethod'), 'working'); + + App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS))); + $this->assertTrue($Apple->Behaviors->load('SomeOther', array('className' => 'TestPlugin.TestPluginPersisterOne'))); + $this->assertInstanceOf('TestPluginPersisterOneBehavior', $Apple->Behaviors->SomeOther); + + $result = $Apple->Behaviors->attached(); + $this->assertEquals(array('Test', 'SomeOther'), $result, 'attached() results are wrong.'); + App::build(); } /** diff --git a/cake/tests/cases/libs/view/helper_collection.test.php b/cake/tests/cases/libs/view/helper_collection.test.php index b6669b94d..894f9d24a 100644 --- a/cake/tests/cases/libs/view/helper_collection.test.php +++ b/cake/tests/cases/libs/view/helper_collection.test.php @@ -80,6 +80,15 @@ class HelperCollectionTest extends CakeTestCase { $result = $this->Helpers->load('Html'); $this->assertInstanceOf('HtmlAliasHelper', $result); + + App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS))); + $result = $this->Helpers->load('SomeOther', array('className' => 'TestPlugin.OtherHelper')); + $this->assertInstanceOf('OtherHelperHelper', $result); + $this->assertInstanceOf('OtherHelperHelper', $this->Helpers->SomeOther); + + $result = $this->Helpers->attached(); + $this->assertEquals(array('Html', 'SomeOther'), $result, 'attached() results are wrong.'); + App::build(); } /**