From c7127630f6054d9284c88d698e18c00ccfe85cc1 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Tue, 18 Jan 2011 17:50:34 -0800 Subject: [PATCH] Added support for plugin classes in ControllerTestCase::generate(). Fixes #1453 --- .../cases/libs/controller_test_case.test.php | 19 +++++++++++++++++++ cake/tests/lib/controller_test_case.php | 19 +++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/cake/tests/cases/libs/controller_test_case.test.php b/cake/tests/cases/libs/controller_test_case.test.php index 72bb959cb..f2c1a09a4 100644 --- a/cake/tests/cases/libs/controller_test_case.test.php +++ b/cake/tests/cases/libs/controller_test_case.test.php @@ -188,6 +188,25 @@ class ControllerTestCaseTest extends CakeTestCase { $this->assertEquals($Posts->Auth->Session->write('something'), 'written!'); } +/** + * Tests ControllerTestCase::generate() using classes from plugins + */ + function testGenerateWithPlugin() { + $Tests = $this->Case->generate('TestPlugin.Tests', array( + 'models' => array( + 'TestPlugin.TestPluginComment' + ), + 'components' => array( + 'TestPlugin.PluginsComponent' + ) + )); + $this->assertEquals($Tests->name, 'Tests'); + $this->assertInstanceOf('PluginsComponentComponent', $Tests->PluginsComponent); + + $result = ClassRegistry::init('TestPlugin.TestPluginComment'); + $this->assertInstanceOf('TestPluginComment', $result); + } + /** * Tests testAction */ diff --git a/cake/tests/lib/controller_test_case.php b/cake/tests/lib/controller_test_case.php index 97e71303e..2cd9be5f7 100644 --- a/cake/tests/lib/controller_test_case.php +++ b/cake/tests/lib/controller_test_case.php @@ -262,8 +262,9 @@ class ControllerTestCase extends CakeTestCase { 'components' => array() ), (array)$mocks); - $_controller = $this->getMock($controller.'Controller', $mocks['methods'], array(), '', false); - $_controller->name = $controller; + list($plugin, $name) = pluginSplit($controller); + $_controller = $this->getMock($name.'Controller', $mocks['methods'], array(), '', false); + $_controller->name = $name; $_controller->__construct(); $config = ClassRegistry::config('Model'); @@ -275,8 +276,9 @@ class ControllerTestCase extends CakeTestCase { if ($methods === true) { $methods = array(); } + list($plugin, $name) = pluginSplit($model); $config = array_merge((array)$config, array('name' => $model)); - $_model = $this->getMock($model, $methods, array($config)); + $_model = $this->getMock($name, $methods, array($config)); ClassRegistry::removeObject($model); ClassRegistry::addObject($model, $_model); } @@ -289,14 +291,15 @@ class ControllerTestCase extends CakeTestCase { if ($methods === true) { $methods = array(); } + list($plugin, $name) = pluginSplit($component); if (!App::import('Component', $component)) { throw new MissingComponentFileException(array( - 'file' => Inflector::underscore($component) . '.php', - 'class' => $componentClass + 'file' => Inflector::underscore($name) . '.php', + 'class' => $name.'Component' )); - } - $_component = $this->getMock($component.'Component', $methods, array(), '', false); - $_controller->Components->set($component, $_component); + } + $_component = $this->getMock($name.'Component', $methods, array(), '', false); + $_controller->Components->set($name, $_component); } $_controller->constructClasses();