Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding tests for startupProcess and shutDownProcess in controller

Fixing variable reference
  • Loading branch information...
commit d5fa897681667d70e03bc25f2d318c6f85e071fa 1 parent 8dfadaf
José Lorenzo Rodríguez lorenzo authored
2  cake/libs/controller/controller.php
View
@@ -542,7 +542,7 @@ function startupProcess() {
* @access public
*/
function shutdownProcess() {
- $this->Component->triggerCallback('shutdown', $controller);
+ $this->Component->triggerCallback('shutdown', $this);
$this->afterFilter();
}
2  cake/tests/cases/console/libs/tasks/controller.test.php
View
@@ -333,8 +333,6 @@ function testBakeActionsUsingSessions() {
$this->assertTrue(strpos($result, 'if ($this->Article->delete($id))') !== false);
$this->assertTrue(strpos($result, "\$this->Session->setFlash(sprintf(__('%s deleted', true), 'Article'));") !== false);
-debug($result, true);
-
$result = $this->Task->bakeActions('Articles', 'admin_', true);
$this->assertTrue(strpos($result, 'function admin_index() {') !== false);
64 cake/tests/cases/libs/controller/controller.test.php
View
@@ -366,6 +366,31 @@ class TestComponent extends Object {
*/
function beforeRedirect() {
}
+/**
+ * initialize method
+ *
+ * @access public
+ * @return void
+ */
+ function initialize(&$controller) {
+ }
+
+/**
+ * startup method
+ *
+ * @access public
+ * @return void
+ */
+ function startup(&$controller) {
+ }
+/**
+ * shutdown method
+ *
+ * @access public
+ * @return void
+ */
+ function shutdown(&$controller) {
+ }
}
/**
@@ -382,7 +407,6 @@ class AnotherTestController extends AppController {
* @access public
*/
var $name = 'AnotherTest';
-
/**
* uses property
*
@@ -1307,5 +1331,43 @@ function testControllerHttpCodes() {
$expected = array(404 => 'Sorry Bro');
$this->assertEqual($result, $expected);
}
+
+/**
+ * Tests that the startup process calls the correct functions
+ *
+ * @access public
+ * @return void
+ */
+ function testStartupProcess() {
+ Mock::generatePartial('AnotherTestController','MockedController', array('beforeFilter'));
+ Mock::generate('TestComponent', 'MockTestComponent', array('startup', 'initialize'));
+ $MockedController =& new MockedController();
+ $MockedController->components = array('MockTest');
+ $MockedController->Component =& new Component();
+ $MockedController->Component->init($MockedController);
+ $MockedController->startupProcess();
+
+ $MockedController->expectCallCount('beforeFilter', 1);
+ $MockedController->MockTest->expectOnce('initialize', array($MockedController));
+ $MockedController->MockTest->expectOnce('startup', array($MockedController));
+ }
+/**
+ * Tests that the shutdown process calls the correct functions
+ *
+ * @access public
+ * @return void
+ */
+ function testShutdownProcess() {
+ Mock::generatePartial('AnotherTestController','MockedController2', array('afterFilter'));
+ Mock::generate('TestComponent', 'MockTestComponent', array('shutdown'));
+ $MockedController =& new MockedController2();
+ $MockedController->components = array('MockTest');
+ $MockedController->Component =& new Component();
+ $MockedController->Component->init($MockedController);
+ $MockedController->shutdownProcess();
+
+ $MockedController->expectCallCount('afterFilter', 1);
+ $MockedController->MockTest->expectOnce('shutdown', array($MockedController));
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.