diff --git a/cake/tests/cases/libs/controller_test_case.test.php b/cake/tests/cases/libs/controller_test_case.test.php index 9ca9913ff..c457da428 100644 --- a/cake/tests/cases/libs/controller_test_case.test.php +++ b/cake/tests/cases/libs/controller_test_case.test.php @@ -20,7 +20,9 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::import('Controller', 'Controller', false); +App::import('Core', array('AppModel', 'Model')); require_once TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'lib' . DS . 'reporter' . DS . 'cake_html_reporter.php'; +require_once dirname(__FILE__) . DS . 'model' . DS . 'models.php'; /** * AppController class @@ -81,13 +83,6 @@ if (!class_exists('PostsController')) { } } -/** - * Post model - */ -if (!class_exists('Post')) { - class Post extends CakeTestModel { - } -} /** * ControllerTestCaseTest @@ -103,7 +98,7 @@ class ControllerTestCaseTest extends CakeTestCase { * @var array * @access public */ - public $fixtures = array('core.post'); + public $fixtures = array('core.post', 'core.author'); /** * reset environment. @@ -136,6 +131,9 @@ class ControllerTestCaseTest extends CakeTestCase { * Test that ControllerTestCase::generate() creates mock objects correctly */ function testGenerate() { + if (defined('APP_CONTROLLER_EXISTS')) { + $this->markTestSkipped('AppController exists, cannot run.'); + } $Posts = $this->Case->generate('Posts'); $this->assertEquals($Posts->name, 'Posts'); $this->assertEquals($Posts->modelClass, 'Post'); @@ -153,6 +151,7 @@ class ControllerTestCaseTest extends CakeTestCase { 'components' => array('RequestHandler') )); + $this->assertInstanceOf('Post', $Posts->Post); $this->assertNull($Posts->Post->save(array())); $this->assertNull($Posts->Post->find('all')); $this->assertEquals($Posts->Post->useTable, 'posts'); diff --git a/cake/tests/lib/controller_test_case.php b/cake/tests/lib/controller_test_case.php index d65650601..63188b059 100644 --- a/cake/tests/lib/controller_test_case.php +++ b/cake/tests/lib/controller_test_case.php @@ -242,6 +242,7 @@ class ControllerTestCase extends CakeTestCase { * interfere with testing. * * ### Mocks: + * * - `methods` Methods to mock on the controller. `_stop()` is mocked by default * - `models` Models to mock. Models are added to the ClassRegistry so they any * time they are instatiated the mock will be created. Pass as key value pairs @@ -270,6 +271,7 @@ class ControllerTestCase extends CakeTestCase { $_controller->name = $controller; $_controller->__construct(); + $config = ClassRegistry::config('Model'); foreach ($mocks['models'] as $model => $methods) { if (is_string($methods)) { $model = $methods; @@ -278,10 +280,8 @@ class ControllerTestCase extends CakeTestCase { if ($methods === true) { $methods = array(); } - ClassRegistry::init($model); - $_model = $this->getMock($model, $methods, array(), '', false); - $_model->name = $model; - $_model->__construct(); + $config = array_merge((array)$config, array('name' => $model)); + $_model = $this->getMock($model, $methods, array($config)); ClassRegistry::removeObject($model); ClassRegistry::addObject($model, $_model); }