Skip to content

Commit

Permalink
Adding tests for startupProcess and shutDownProcess in controller
Browse files Browse the repository at this point in the history
Fixing variable reference
  • Loading branch information
lorenzo committed Feb 28, 2010
1 parent 8dfadaf commit d5fa897
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cake/libs/controller/controller.php
Expand Up @@ -542,7 +542,7 @@ function startupProcess() {
* @access public
*/
function shutdownProcess() {
$this->Component->triggerCallback('shutdown', $controller);
$this->Component->triggerCallback('shutdown', $this);
$this->afterFilter();
}

Expand Down
2 changes: 0 additions & 2 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -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);
Expand Down
64 changes: 63 additions & 1 deletion cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -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) {
}
}

/**
Expand All @@ -382,7 +407,6 @@ class AnotherTestController extends AppController {
* @access public
*/
var $name = 'AnotherTest';

/**
* uses property
*
Expand Down Expand Up @@ -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));
}
}
?>

0 comments on commit d5fa897

Please sign in to comment.