From 8e69df9013c1b08ddfdaf7362bba32f20a663de5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 22 Oct 2011 22:44:21 -0400 Subject: [PATCH] Revert "Fix RedirectRoute by stopping execution." This reverts commit 841e7aa560d27f14c6f381a3548c8d8c74e4a463. Having _stop() on CakeResponse seemed like the wrong place to stop execution. It can make testing with redirects harder. Instead RedirectRoute should be stopping execution. --- lib/Cake/Network/CakeResponse.php | 15 --------------- lib/Cake/Test/Case/Network/CakeResponseTest.php | 2 +- .../Case/Routing/Route/RedirectRouteTest.php | 16 ++++++++-------- lib/Cake/Test/Case/Routing/RouterTest.php | 2 +- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index fe75a1254..d917bc817 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -351,10 +351,6 @@ class CakeResponse { foreach ($this->_headers as $header => $value) { $this->_sendHeader($header, $value); } - - if (isset($this->_headers['Location'])) { - $this->_stop(); - } $this->_sendContent($this->_body); } @@ -666,15 +662,4 @@ class CakeResponse { public function __toString() { return (string)$this->_body; } - -/** - * Stop execution of the current script. Wraps exit() making - * testing easier. - * - * @param integer|string $status see http://php.net/exit for values - * @return void - */ - protected function _stop($status = 0) { - exit($status); - } } diff --git a/lib/Cake/Test/Case/Network/CakeResponseTest.php b/lib/Cake/Test/Case/Network/CakeResponseTest.php index ac6d29db9..2293e2bc5 100644 --- a/lib/Cake/Test/Case/Network/CakeResponseTest.php +++ b/lib/Cake/Test/Case/Network/CakeResponseTest.php @@ -209,7 +209,7 @@ class CakeResponseTest extends CakeTestCase { * */ public function testSendWithLocation() { - $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent', '_stop')); + $response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent')); $response->header('Location', 'http://www.example.com'); $response->expects($this->at(0)) ->method('_sendHeader')->with('HTTP/1.1 302 Found'); diff --git a/lib/Cake/Test/Case/Routing/Route/RedirectRouteTest.php b/lib/Cake/Test/Case/Routing/Route/RedirectRouteTest.php index 3942ef90b..94efe04e1 100644 --- a/lib/Cake/Test/Case/Routing/Route/RedirectRouteTest.php +++ b/lib/Cake/Test/Case/Routing/Route/RedirectRouteTest.php @@ -45,44 +45,44 @@ class RedirectRouteTestCase extends CakeTestCase { */ public function testParsing() { $route = new RedirectRoute('/home', array('controller' => 'posts')); - $route->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + $route->response = $this->getMock('CakeResponse', array('_sendHeader')); $result = $route->parse('/home'); $this->assertEqual($route->response->header(), array('Location' => Router::url('/posts', true))); $route = new RedirectRoute('/home', array('controller' => 'posts', 'action' => 'index')); - $route->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + $route->response = $this->getMock('CakeResponse', array('_sendHeader')); $result = $route->parse('/home'); $this->assertEqual($route->response->header(), array('Location' => Router::url('/posts', true))); $this->assertEqual($route->response->statusCode(), 301); $route = new RedirectRoute('/google', 'http://google.com'); - $route->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + $route->response = $this->getMock('CakeResponse', array('_sendHeader')); $result = $route->parse('/google'); $this->assertEqual($route->response->header(), array('Location' => 'http://google.com')); $route = new RedirectRoute('/posts/*', array('controller' => 'posts', 'action' => 'view'), array('status' => 302)); - $route->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + $route->response = $this->getMock('CakeResponse', array('_sendHeader')); $result = $route->parse('/posts/2'); $this->assertEqual($route->response->header(), array('Location' => Router::url('/posts/view', true))); $this->assertEqual($route->response->statusCode(), 302); $route = new RedirectRoute('/posts/*', array('controller' => 'posts', 'action' => 'view'), array('persist' => true)); - $route->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + $route->response = $this->getMock('CakeResponse', array('_sendHeader')); $result = $route->parse('/posts/2'); $this->assertEqual($route->response->header(), array('Location' => Router::url('/posts/view/2', true))); $route = new RedirectRoute('/posts/*', '/test', array('persist' => true)); - $route->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + $route->response = $this->getMock('CakeResponse', array('_sendHeader')); $result = $route->parse('/posts/2'); $this->assertEqual($route->response->header(), array('Location' => Router::url('/test', true))); $route = new RedirectRoute('/my_controllers/:action/*', array('controller' => 'tags', 'action' => 'add'), array('persist' => true)); - $route->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + $route->response = $this->getMock('CakeResponse', array('_sendHeader')); $result = $route->parse('/my_controllers/do_something/passme/named:param'); $this->assertEqual($route->response->header(), array('Location' => Router::url('/tags/add/passme/named:param', true))); $route = new RedirectRoute('/my_controllers/:action/*', array('controller' => 'tags', 'action' => 'add')); - $route->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + $route->response = $this->getMock('CakeResponse', array('_sendHeader')); $result = $route->parse('/my_controllers/do_something/passme/named:param'); $this->assertEqual($route->response->header(), array('Location' => Router::url('/tags/add', true))); } diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 58e5c3b49..6a0cbc291 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -2458,7 +2458,7 @@ class RouterTest extends CakeTestCase { public function testRouteRedirection() { Router::redirect('/blog', array('controller' => 'posts'), array('status' => 302)); $this->assertEqual(count(Router::$routes), 1); - Router::$routes[0]->response = $this->getMock('CakeResponse', array('_sendHeader', '_stop')); + Router::$routes[0]->response = $this->getMock('CakeResponse', array('_sendHeader')); $this->assertEqual(Router::$routes[0]->options['status'], 302); Router::parse('/blog');