Moving a test case that should be implemented in controller, as that is where the code that needs to be tested is located.

This commit is contained in:
mark_story 2010-08-11 22:47:54 -04:00
parent 45064315d4
commit 238c734f70
2 changed files with 32 additions and 48 deletions

View file

@ -408,54 +408,6 @@ class ComponentTest extends CakeTestCase {
)); ));
} }
/**
* test that components can modify values from beforeRedirect
*
* @return void
*/
function testBeforeRedirectModification() {
$this->markTestIncomplete('This test needs to be implemented');
/*
*$MockController = new MockController();
$MockController->components = array('MockTest');
$MockController->Component = new Component();
$MockController->Component->init($MockController);
$MockController->MockTest->setReturnValue('beforeRedirect', 'http://book.cakephp.org');
$MockController->expectAt(0, 'header', array('HTTP/1.1 301 Moved Permanently'));
$MockController->expectAt(1, 'header', array('Location: http://book.cakephp.org'));
$MockController->expectCallCount('header', 2);
$MockController->redirect('http://cakephp.org', 301, false);
$MockController = new MockController();
$MockController->components = array('MockTest');
$MockController->Component = new Component();
$MockController->Component->init($MockController);
$MockController->MockTest->setReturnValue('beforeRedirect', false);
$MockController->expectNever('header');
$MockController->redirect('http://cakephp.org', 301, false);
$MockController = new MockController();
$MockController->components = array('MockTest', 'MockTestB');
$MockController->Component = new Component();
$MockController->Component->init($MockController);
$MockController->MockTest->setReturnValue('beforeRedirect', 'http://book.cakephp.org');
$MockController->MockTestB->setReturnValue('beforeRedirect', 'http://bakery.cakephp.org');
$MockController->expectAt(0, 'header', array('HTTP/1.1 301 Moved Permanently'));
$MockController->expectAt(1, 'header', array('Location: http://bakery.cakephp.org'));
$MockController->expectCallCount('header', 2);
$MockController->redirect('http://cakephp.org', 301, false);
*/
}
/**
* test that components can pass modifying values from beforeRedirect
*
* @return void
*/
function testBeforeRedirectPass() {
$this->markTestIncomplete('This test needs to be implemented');
}
/** /**
* Test that SessionComponent doesn't get added if its already in the components array. * Test that SessionComponent doesn't get added if its already in the components array.
* *

View file

@ -1109,6 +1109,38 @@ class ControllerTest extends CakeTestCase {
$Controller->redirect('http://cakephp.org', 301, false); $Controller->redirect('http://cakephp.org', 301, false);
} }
/**
* test that beforeRedirect callback returnning null doesn't affect things.
*
* @return void
*/
function testRedirectBeforeRedirectModifyingParamsArrayReturn() {
$Controller = $this->getMock('Controller', array('header', '_stop'));
$Controller->Components = $this->getMock('ComponentCollection');
$return = array(
array(
'url' => 'http://example.com/test/1',
'exit' => false,
'status' => 302
),
array(
'url' => 'http://example.com/test/2',
),
);
$Controller->Components->expects($this->once())->method('trigger')
->will($this->returnValue($return));
$Controller->expects($this->at(0))->method('header')
->with('HTTP/1.1 302 Found');
$Controller->expects($this->at(1))->method('header')
->with('Location: http://example.com/test/2');
$Controller->expects($this->never())->method('_stop');
$Controller->redirect('http://cakephp.org', 301);
}
/** /**
* testMergeVars method * testMergeVars method
* *