From e99f090ee0fb7ec531c40848bcfe43a6a1b1a1f5 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Thu, 27 Jan 2011 18:32:51 -0800 Subject: [PATCH] Fixed issue where ClassRegistry alias was incorrectly set --- .../cases/libs/controller_test_case.test.php | 32 ++++++++++++++++++- cake/tests/lib/controller_test_case.php | 4 +-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/libs/controller_test_case.test.php b/cake/tests/cases/libs/controller_test_case.test.php index 6d4812937..1ffb518c6 100644 --- a/cake/tests/cases/libs/controller_test_case.test.php +++ b/cake/tests/cases/libs/controller_test_case.test.php @@ -76,6 +76,20 @@ if (!class_exists('PostsController')) { } } +/** + * ControllerTestCaseTest controller + */ +class ControllerTestCaseTestController extends AppController { + +/** + * Uses array + * + * @param array + */ + public $uses = array('TestPlugin.TestPluginComment'); + +} + /** * ControllerTestCaseTest @@ -90,7 +104,7 @@ class ControllerTestCaseTest extends CakeTestCase { * @var array * @access public */ - public $fixtures = array('core.post', 'core.author'); + public $fixtures = array('core.post', 'core.author', 'core.test_plugin_comment'); /** * reset environment. @@ -201,6 +215,22 @@ class ControllerTestCaseTest extends CakeTestCase { $result = ClassRegistry::init('TestPlugin.TestPluginComment'); $this->assertInstanceOf('TestPluginComment', $result); + + $Tests = $this->Case->generate('ControllerTestCaseTest', array( + 'models' => array( + 'TestPlugin.TestPluginComment' => array('save') + ) + )); + $this->assertInstanceOf('TestPluginComment', $Tests->TestPluginComment); + $Tests->TestPluginComment->expects($this->at(0)) + ->method('save') + ->will($this->returnValue(true)); + $Tests->TestPluginComment->expects($this->at(1)) + ->method('save') + ->will($this->returnValue(false)); + $this->assertTrue($Tests->TestPluginComment->save(array())); + $this->assertFalse($Tests->TestPluginComment->save(array())); + } /** diff --git a/cake/tests/lib/controller_test_case.php b/cake/tests/lib/controller_test_case.php index 217463ecf..150bf12a5 100644 --- a/cake/tests/lib/controller_test_case.php +++ b/cake/tests/lib/controller_test_case.php @@ -280,8 +280,8 @@ class ControllerTestCase extends CakeTestCase { list($plugin, $name) = pluginSplit($model); $config = array_merge((array)$config, array('name' => $model)); $_model = $this->getMock($name, $methods, array($config)); - ClassRegistry::removeObject($model); - ClassRegistry::addObject($model, $_model); + ClassRegistry::removeObject($name); + ClassRegistry::addObject($name, $_model); } foreach ($mocks['components'] as $component => $methods) {