Skip to content

Commit

Permalink
Updating Controller test case to use new ComponentCollection.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 11, 2010
1 parent ca65fae commit 55d71dc
Showing 1 changed file with 16 additions and 38 deletions.
54 changes: 16 additions & 38 deletions cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -1032,8 +1032,7 @@ public static function statusCodeProvider() {
function testRedirectByCode($code, $msg) {
$Controller = $this->getMock('Controller', array('header'));

$Controller->Component = new Component();
$Controller->Component->init($Controller);
$Controller->Components = $this->getMock('ComponentCollection');
$Controller->expects($this->at(0))->method('header')
->with("HTTP/1.1 {$code} {$msg}");

Expand All @@ -1055,8 +1054,7 @@ function testRedirectByCode($code, $msg) {
function testRedirectByMessage($code, $msg) {
$Controller = $this->getMock('Controller', array('header'));

$Controller->Component = new Component();
$Controller->Component->init($Controller);
$Controller->Components = $this->getMock('ComponentCollection');

$Controller->expects($this->at(0))->method('header')
->with("HTTP/1.1 {$code} {$msg}");
Expand All @@ -1076,9 +1074,10 @@ function testRedirectByMessage($code, $msg) {
*/
function testRedirectTriggeringComponentsReturnNull() {
$Controller = $this->getMock('Controller', array('header'));
$Controller->Component = $this->getMock('Component');
$Controller->Components = $this->getMock('ComponentCollection');

$Controller->Component->expects($this->once())->method('beforeRedirect')->will($this->returnValue(null));
$Controller->Components->expects($this->once())->method('trigger')
->will($this->returnValue(null));

$Controller->expects($this->at(0))->method('header')
->with('HTTP/1.1 301 Moved Permanently');
Expand All @@ -1096,9 +1095,9 @@ function testRedirectTriggeringComponentsReturnNull() {
*/
function testRedirectBeforeRedirectModifyingParams() {
$Controller = $this->getMock('Controller', array('header'));
$Controller->Component = $this->getMock('Component');
$Controller->Components = $this->getMock('ComponentCollection');

$Controller->Component->expects($this->once())->method('beforeRedirect')
$Controller->Components->expects($this->once())->method('trigger')
->will($this->returnValue(array('http://book.cakephp.org')));

$Controller->expects($this->at(0))->method('header')
Expand Down Expand Up @@ -1389,27 +1388,6 @@ function testPostConditions() {
$this->assertIdentical($result, $expected);
}

/**
* testRequestHandlerPrefers method
*
* @access public
* @return void
*/
function testRequestHandlerPrefers(){
Configure::write('debug', 2);
$Controller = new Controller();
$Controller->components = array("RequestHandler");
$Controller->modelClass='ControllerPost';
$Controller->params['url']['ext'] = 'rss';
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$Controller->beforeFilter();
$Controller->Component->startup($Controller);

$this->assertEqual($Controller->RequestHandler->prefers(), 'rss');
unset($Controller);
}

/**
* testControllerHttpCodes method
*
Expand Down Expand Up @@ -1455,16 +1433,17 @@ function testControllerHttpCodes() {
* @return void
*/
function testStartupProcess() {
$this->getMock('TestComponent', array('startup', 'initialize'), array(), 'MockStartupComponent');
$Controller = $this->getMock('Controller', array('beforeFilter', 'afterFilter'));

$Controller->components = array('MockStartup');
$Controller->Component = new Component();
$Controller->Component->init($Controller);
$Controller->Components = $this->getMock('ComponentCollection');

$Controller->expects($this->once())->method('beforeFilter');
$Controller->MockStartup->expects($this->at(0))->method('initialize');
$Controller->MockStartup->expects($this->at(1))->method('startup');
$Controller->Components->expects($this->at(0))->method('trigger')
->with('initialize', array(&$Controller));

$Controller->Components->expects($this->at(1))->method('trigger')
->with('startup', array(&$Controller));

$Controller->startupProcess();
}
Expand All @@ -1475,15 +1454,14 @@ function testStartupProcess() {
* @return void
*/
function testShutdownProcess() {
$this->getMock('TestComponent', array('shutdown'), array(), 'MockShutdownComponent');
$Controller = $this->getMock('Controller', array('beforeFilter', 'afterFilter'));

$Controller->components = array('MockShutdown');
$Controller->Component = new Component();
$Controller->Component->init($Controller);
$Controller->Components = $this->getMock('ComponentCollection');

$Controller->expects($this->once())->method('afterFilter');
$Controller->MockShutdown->expects($this->once())->method('shutdown');
$Controller->Components->expects($this->once())->method('trigger')
->with('shutdown', array(&$Controller));

$Controller->shutdownProcess();
}
Expand Down

0 comments on commit 55d71dc

Please sign in to comment.