--- zfv1/tests/Zend/Test/PHPUnit/_files/application/controllers/ZendTestRedirectController.php (revision 0) +++ zfv1/tests/Zend/Test/PHPUnit/_files/application/controllers/ZendTestRedirectController.php (revision 0) @@ -0,0 +1,42 @@ +_redirect('/login'); + } + + public function bazAction() + { + $this->_helper->viewRenderer->setNoRender(true); + echo 'this should never be executed'; + } +} Index: zfv1/tests/Zend/Test/PHPUnit/ControllerTestCaseTest.php =================================================================== --- zfv1/tests/Zend/Test/PHPUnit/ControllerTestCaseTest.php (revision 24148) +++ zfv1/tests/Zend/Test/PHPUnit/ControllerTestCaseTest.php (working copy) @@ -781,6 +781,17 @@ : gettype($boot); $this->assertTrue($boot === $this->testCase->bootstrap->getBootstrap(), $type); } + + /** + * @group ZF-7496 + */ + public function testRedirectWorksAsExpectedInPreDispatchMethods() + { + $this->testCase->getFrontController()->setControllerDirectory(dirname(__FILE__) . '/_files/application/controllers'); + $this->testCase->dispatch('/zend-test-redirect/baz'); + $this->testCase->assertRedirectTo('/login'); + $this->assertNotEquals('this should never be executed', $this->testCase->getResponse()->getBody()); + } } // Concrete test case class for testing purposes Index: zfv1/library/Zend/Controller/Action.php =================================================================== --- zfv1/library/Zend/Controller/Action.php (revision 24148) +++ zfv1/library/Zend/Controller/Action.php (working copy) @@ -504,6 +504,12 @@ if (null === $this->_classMethods) { $this->_classMethods = get_class_methods($this); } + + // ZF-7496 - if the preDispatch state modified the response into a + // redirect, don't continue processing + if ($this->getResponse()->isRedirect()) { + return; + } // preDispatch() didn't change the action, so we can continue if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {