Added support for plugin classes in ControllerTestCase::generate(). Fixes #1453

This commit is contained in:
Jeremy Harris 2011-01-18 17:50:34 -08:00
parent be563e1220
commit c7127630f6
2 changed files with 30 additions and 8 deletions

View file

@ -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
*/

View file

@ -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();