mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Added support for plugin classes in ControllerTestCase::generate(). Fixes #1453
This commit is contained in:
parent
be563e1220
commit
c7127630f6
2 changed files with 30 additions and 8 deletions
|
@ -188,6 +188,25 @@ class ControllerTestCaseTest extends CakeTestCase {
|
||||||
$this->assertEquals($Posts->Auth->Session->write('something'), 'written!');
|
$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
|
* Tests testAction
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -262,8 +262,9 @@ class ControllerTestCase extends CakeTestCase {
|
||||||
'components' => array()
|
'components' => array()
|
||||||
), (array)$mocks);
|
), (array)$mocks);
|
||||||
|
|
||||||
$_controller = $this->getMock($controller.'Controller', $mocks['methods'], array(), '', false);
|
list($plugin, $name) = pluginSplit($controller);
|
||||||
$_controller->name = $controller;
|
$_controller = $this->getMock($name.'Controller', $mocks['methods'], array(), '', false);
|
||||||
|
$_controller->name = $name;
|
||||||
$_controller->__construct();
|
$_controller->__construct();
|
||||||
|
|
||||||
$config = ClassRegistry::config('Model');
|
$config = ClassRegistry::config('Model');
|
||||||
|
@ -275,8 +276,9 @@ class ControllerTestCase extends CakeTestCase {
|
||||||
if ($methods === true) {
|
if ($methods === true) {
|
||||||
$methods = array();
|
$methods = array();
|
||||||
}
|
}
|
||||||
|
list($plugin, $name) = pluginSplit($model);
|
||||||
$config = array_merge((array)$config, array('name' => $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::removeObject($model);
|
||||||
ClassRegistry::addObject($model, $_model);
|
ClassRegistry::addObject($model, $_model);
|
||||||
}
|
}
|
||||||
|
@ -289,14 +291,15 @@ class ControllerTestCase extends CakeTestCase {
|
||||||
if ($methods === true) {
|
if ($methods === true) {
|
||||||
$methods = array();
|
$methods = array();
|
||||||
}
|
}
|
||||||
|
list($plugin, $name) = pluginSplit($component);
|
||||||
if (!App::import('Component', $component)) {
|
if (!App::import('Component', $component)) {
|
||||||
throw new MissingComponentFileException(array(
|
throw new MissingComponentFileException(array(
|
||||||
'file' => Inflector::underscore($component) . '.php',
|
'file' => Inflector::underscore($name) . '.php',
|
||||||
'class' => $componentClass
|
'class' => $name.'Component'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
$_component = $this->getMock($component.'Component', $methods, array(), '', false);
|
$_component = $this->getMock($name.'Component', $methods, array(), '', false);
|
||||||
$_controller->Components->set($component, $_component);
|
$_controller->Components->set($name, $_component);
|
||||||
}
|
}
|
||||||
|
|
||||||
$_controller->constructClasses();
|
$_controller->constructClasses();
|
||||||
|
|
Loading…
Add table
Reference in a new issue