Skip to content

Commit

Permalink
Added support for plugin classes in ControllerTestCase::generate(). F…
Browse files Browse the repository at this point in the history
…ixes #1453
  • Loading branch information
jeremyharris committed Jan 19, 2011
1 parent be563e1 commit c712763
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
19 changes: 19 additions & 0 deletions cake/tests/cases/libs/controller_test_case.test.php
Expand Up @@ -188,6 +188,25 @@ function testGenerate() {
$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
*/
Expand Down
19 changes: 11 additions & 8 deletions cake/tests/lib/controller_test_case.php
Expand Up @@ -262,8 +262,9 @@ public function generate($controller, $mocks = array()) {
'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');
Expand All @@ -275,8 +276,9 @@ public function generate($controller, $mocks = array()) {
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);
}
Expand All @@ -289,14 +291,15 @@ public function generate($controller, $mocks = array()) {
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();
Expand Down

0 comments on commit c712763

Please sign in to comment.