From 09cf69c452b4cbd6b61086cadbef0bd4b572c113 Mon Sep 17 00:00:00 2001 From: AD7six Date: Mon, 19 Aug 2013 09:46:07 +0000 Subject: [PATCH] Pass Controller:$components config to mocked components Otherwise there can be significant differences in behavior between using an unmodifiedcomponent in testAction and using a mock as the config will not be propogated from the controller --- .../Case/TestSuite/ControllerTestCaseTest.php | 22 +++++++++++++++++++ .../Controller/TestConfigsController.php | 13 +++++++++++ lib/Cake/TestSuite/ControllerTestCase.php | 3 ++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 lib/Cake/Test/test_app/Controller/TestConfigsController.php diff --git a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php index 301949a73..d139e7f18 100644 --- a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php +++ b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php @@ -210,6 +210,28 @@ class ControllerTestCaseTest extends CakeTestCase { $this->assertEquals('written!', $Posts->Auth->Session->write('something')); } +/** + * testGenerateWithComponentConfig + */ + public function testGenerateWithComponentConfig() { + $Tests = $this->Case->generate('TestConfigs', array( + )); + + $expected = array('some' => 'config'); + $settings = array_intersect_key($Tests->RequestHandler->settings, array('some' => 'foo')); + $this->assertSame($expected, $settings, 'A mocked component should have the same config as an unmocked component'); + + $Tests = $this->Case->generate('TestConfigs', array( + 'components' => array( + 'RequestHandler' => array('isPut') + ) + )); + + $expected = array('some' => 'config'); + $settings = array_intersect_key($Tests->RequestHandler->settings, array('some' => 'foo')); + $this->assertSame($expected, $settings, 'A mocked component should have the same config as an unmocked component'); + } + /** * Tests ControllerTestCase::generate() using classes from plugins */ diff --git a/lib/Cake/Test/test_app/Controller/TestConfigsController.php b/lib/Cake/Test/test_app/Controller/TestConfigsController.php new file mode 100644 index 000000000..aa8400ea9 --- /dev/null +++ b/lib/Cake/Test/test_app/Controller/TestConfigsController.php @@ -0,0 +1,13 @@ + array( + 'some' => 'config' + ) + ); + +} diff --git a/lib/Cake/TestSuite/ControllerTestCase.php b/lib/Cake/TestSuite/ControllerTestCase.php index 28227a437..7aaff1b00 100644 --- a/lib/Cake/TestSuite/ControllerTestCase.php +++ b/lib/Cake/TestSuite/ControllerTestCase.php @@ -364,7 +364,8 @@ abstract class ControllerTestCase extends CakeTestCase { 'class' => $componentClass )); } - $componentObj = $this->getMock($componentClass, $methods, array($controllerObj->Components)); + $config = isset($controllerObj->components[$component]) ? $controllerObj->components[$component] : array(); + $componentObj = $this->getMock($componentClass, $methods, array($controllerObj->Components, $config)); $controllerObj->Components->set($name, $componentObj); $controllerObj->Components->enable($name); }