From 570145d5685804c3e06093fab10c7e6da3192043 Mon Sep 17 00:00:00 2001 From: TommyO Date: Fri, 1 Aug 2008 11:27:53 +0000 Subject: [PATCH] Added test to show (deprecated?) support of string status codes in redirect(). Fixed fail on string status codes in redirect(). git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7410 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/controller.php | 2 +- .../cases/libs/controller/controller.test.php | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index a1c0ffb5c..027f89412 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -540,7 +540,7 @@ class Controller extends Object { } if (isset($codes[$status])) { - $code = $status = $codes[$status]; + $code = $msg = $codes[$status]; if (is_numeric($status)) { $code = $status; } diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index fea4a48f6..b92b2726a 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -323,7 +323,7 @@ class ControllerTest extends CakeTestCase { $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); $this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1); $this->assertEqual($results, array(1, 2, 3)); - + $Controller->passedArgs = array('sort' => 'ControllerPost.author_id', 'direction' => 'allYourBase'); $results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id'); $this->assertEqual($Controller->ControllerPost->lastQuery['order'][0], array('ControllerPost.author_id' => 'asc')); @@ -457,21 +457,21 @@ class ControllerTest extends CakeTestCase { $result = $Controller->render('/elements/test_element'); $this->assertPattern('/this is the test element/', $result); - + $Controller = new TestController(); $Controller->constructClasses(); $Controller->ControllerComment->validationErrors = array('title' => 'tooShort'); $expected = $Controller->ControllerComment->validationErrors; - + ClassRegistry::flush(); $Controller->viewPath = 'posts'; $result = $Controller->render('index'); $View = ClassRegistry::getObject('view'); $this->assertTrue(isset($View->validationErrors['ControllerComment'])); $this->assertEqual($expected, $View->validationErrors['ControllerComment']); - + $Controller->ControllerComment->validationErrors = array(); - ClassRegistry::flush(); + ClassRegistry::flush(); } /** * testToBeInheritedGuardmethods method @@ -539,6 +539,7 @@ class ControllerTest extends CakeTestCase { Mock::generatePartial('Controller', 'MockController', array('header')); App::import('Helper', 'Cache'); +// $codes = array_merge($codes, array_flip($codes)); foreach ($codes as $code => $msg) { $MockController =& new MockController(); $MockController->components = array('Test'); @@ -547,6 +548,15 @@ class ControllerTest extends CakeTestCase { $MockController->expectCallCount('header', 2); $MockController->redirect($url, (int) $code, false); } + $codes = array_flip($codes); + foreach ($codes as $code => $msg) { + $MockController =& new MockController(); + $MockController->components = array('Test'); + $MockController->Component =& new Component(); + $MockController->Component->init($MockController); + $MockController->expectCallCount('header', 2); + $MockController->redirect($url, $code, false); + } } /** * testMergeVars method