From c9079c804847203f196d59eae16bd7f27af56e5f Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 13 Jul 2010 20:19:31 -0400 Subject: [PATCH] Removing magical un-removable plugin concatenation in Controller::loadModel(). Adding test case from 'real34'. Fixes #858 --- cake/libs/controller/controller.php | 8 +---- .../cases/libs/controller/controller.test.php | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index bea4fa1ba81..9e10d8c593c 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -572,13 +572,7 @@ public function loadModel($modelClass = null, $id = null) { } $cached = false; $object = null; - $plugin = null; - if ($this->uses === false) { - if ($this->plugin) { - $plugin = $this->plugin . '.'; - } - } - list($plugin, $modelClass) = pluginSplit($modelClass, true, $plugin); + list($plugin, $modelClass) = pluginSplit($modelClass, true); if ($this->persistModel === true) { $cached = $this->_persist($modelClass, null, $object); diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 41ac69b4009..fa6f92eed9c 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -461,6 +461,35 @@ function testLoadModel() { unset($Controller); } +/** + * testLoadModel method from a plugin controller + * + * @access public + * @return void + */ + function testLoadModelInPlugins() { + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), + 'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS), + 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS) + )); + App::import('Controller', 'TestPlugin.TestPlugin'); + + $Controller = new TestPluginController(); + $Controller->plugin = 'TestPlugin'; + $Controller->uses = false; + + $this->assertFalse(isset($Controller->Comment)); + + $result = $Controller->loadModel('Comment'); + $this->assertTrue($result); + $this->assertType('Comment', $Controller->Comment); + $this->assertTrue(in_array('Comment', $Controller->modelNames)); + + ClassRegistry::flush(); + unset($Controller); + } + /** * testConstructClasses method *