From 76f7754014c031bd6b01be6cf67bbc3aed39f9b2 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 26 Jan 2015 10:29:52 +0100 Subject: [PATCH 1/4] Adding a status code test. --- lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php index 4eb1d3011..bb2df1d31 100644 --- a/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php +++ b/lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php @@ -297,6 +297,7 @@ class ControllerTestCaseTest extends CakeTestCase { 'Location' => 'http://cakephp.org' ); $this->assertEquals($expected, $results); + $this->assertSame(302, $Controller->response->statusCode()); } /** From e753fbadca7a31ce26f2800c73d6e5660067d85a Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 26 Jan 2015 10:31:04 +0100 Subject: [PATCH 2/4] Fix ControllerTestCase redirect --- lib/Cake/Controller/Controller.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 74b65e7b6..f8252914a 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -751,7 +751,7 @@ class Controller extends Object implements CakeEventListener { * * @param string|array $url A string or array-based URL pointing to another location within the app, * or an absolute URL - * @param int $status Optional HTTP status code (eg: 404) + * @param int $status HTTP status code (eg: 301) * @param bool $exit If true, exit() will be called after the redirect * @return void * @triggers Controller.beforeRedirect $this, array($url, $status, $exit) @@ -785,6 +785,9 @@ class Controller extends Object implements CakeEventListener { } } + if ($status === null) { + $status = 302; + } if ($status) { $this->response->statusCode($status); } From 70276b7a7ad6b203d3e25ae320d441c1cd8dd925 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 26 Jan 2015 10:35:02 +0100 Subject: [PATCH 3/4] Doc block adjustment. --- lib/Cake/Controller/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index f8252914a..3688386c6 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -751,7 +751,7 @@ class Controller extends Object implements CakeEventListener { * * @param string|array $url A string or array-based URL pointing to another location within the app, * or an absolute URL - * @param int $status HTTP status code (eg: 301) + * @param int|array|null $status HTTP status code (eg: 301). Defaults to 302 when null is passed. * @param bool $exit If true, exit() will be called after the redirect * @return void * @triggers Controller.beforeRedirect $this, array($url, $status, $exit) From 4fa5dd62c57f3e51ac59d7b78722e45a14c938d6 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 26 Jan 2015 23:47:20 +0100 Subject: [PATCH 4/4] Remove conditional status setting. --- lib/Cake/Controller/Controller.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 3688386c6..8cd10fdf1 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -788,9 +788,7 @@ class Controller extends Object implements CakeEventListener { if ($status === null) { $status = 302; } - if ($status) { - $this->response->statusCode($status); - } + $this->response->statusCode($status); if ($exit) { $this->response->send();