mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding tests for startupProcess and shutDownProcess in controller
Fixing variable reference
This commit is contained in:
parent
8dfadafc88
commit
d5fa897681
3 changed files with 64 additions and 4 deletions
|
@ -542,7 +542,7 @@ class Controller extends Object {
|
|||
* @access public
|
||||
*/
|
||||
function shutdownProcess() {
|
||||
$this->Component->triggerCallback('shutdown', $controller);
|
||||
$this->Component->triggerCallback('shutdown', $this);
|
||||
$this->afterFilter();
|
||||
}
|
||||
|
||||
|
|
|
@ -333,8 +333,6 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$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);
|
||||
|
|
|
@ -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 @@ class ControllerTest extends CakeTestCase {
|
|||
$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));
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue