diff --git a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php index 8d6370503..bbf9279e7 100644 --- a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php +++ b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php @@ -79,6 +79,12 @@ if (!class_exists('PostsController')) { public $components = array( 'RequestHandler', 'Email', + 'AliasedEmail' => array( + 'className' => 'Email', + ), + 'AliasedPluginEmail' => array( + 'className' => 'TestPlugin.TestPluginEmail', + ), 'Auth' ); } @@ -270,6 +276,46 @@ class ControllerTestCaseTest extends CakeTestCase { $this->assertFalse($Tests->TestPluginComment->save(array())); } +/** + * Tests ControllerTestCase::generate() using aliased component + * + * @return void + */ + public function testGenerateWithMockedAliasedComponent() + { + $Posts = $this->Case->generate('Posts', array( + 'components' => array( + 'AliasedEmail' => array('send') + ) + )); + $Posts->AliasedEmail->expects($this->once()) + ->method('send') + ->will($this->returnValue(true)); + + $this->assertInstanceOf('EmailComponent', $Posts->AliasedEmail); + $this->assertTrue($Posts->AliasedEmail->send()); + } + +/** + * Tests ControllerTestCase::generate() using aliased plugin component + * + * @return void + */ + public function testGenerateWithMockedAliasedPluginComponent() + { + $Posts = $this->Case->generate('Posts', array( + 'components' => array( + 'AliasedPluginEmail' => array('send') + ) + )); + $Posts->AliasedPluginEmail->expects($this->once()) + ->method('send') + ->will($this->returnValue(true)); + + $this->assertInstanceOf('TestPluginEmailComponent', $Posts->AliasedPluginEmail); + $this->assertTrue($Posts->AliasedPluginEmail->send()); + } + /** * Tests testAction * diff --git a/lib/Cake/Test/test_app/Plugin/TestPlugin/Controller/Component/TestPluginEmailComponent.php b/lib/Cake/Test/test_app/Plugin/TestPlugin/Controller/Component/TestPluginEmailComponent.php new file mode 100644 index 000000000..834f57501 --- /dev/null +++ b/lib/Cake/Test/test_app/Plugin/TestPlugin/Controller/Component/TestPluginEmailComponent.php @@ -0,0 +1,10 @@ +components[$component]) ? $controllerObj->components[$component] : array(); + if (isset($config['className'])) { + $alias = $component; + $component = $config['className']; + } list($plugin, $name) = pluginSplit($component, true); + if (!isset($alias)) { + $alias = $name; + } $componentClass = $name . 'Component'; App::uses($componentClass, $plugin . 'Controller/Component'); if (!class_exists($componentClass)) { @@ -396,11 +404,11 @@ abstract class ControllerTestCase extends CakeTestCase { 'class' => $componentClass )); } - $config = isset($controllerObj->components[$component]) ? $controllerObj->components[$component] : array(); /** @var Component|PHPUnit_Framework_MockObject_MockObject $componentObj */ $componentObj = $this->getMock($componentClass, $methods, array($controllerObj->Components, $config)); - $controllerObj->Components->set($name, $componentObj); - $controllerObj->Components->enable($name); + $controllerObj->Components->set($alias, $componentObj); + $controllerObj->Components->enable($alias); + unset($alias); } $controllerObj->constructClasses();