From 06d06c85d90dbade160ca188a0ee34847409141c Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 2 Apr 2008 20:14:06 +0000 Subject: [PATCH] "Fixes #4339, Providing null for variable with underscores leads to camelcased variable in view" git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6626 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/controller.php | 2 +- .../cases/libs/controller/controller.test.php | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index c89957765..9d1b43113 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -577,7 +577,7 @@ class Controller extends Object { if ($name == 'title') { $this->pageTitle = $value; } else { - if ($two === null) { + if ($two === null && is_array($one)) { $this->viewVars[Inflector::variable($name)] = $value; } else { $this->viewVars[$name] = $value; diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 5d7685de5..11c248bef 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -105,9 +105,8 @@ class ControllerTest extends CakeTestCase { function testFlash() { $Controller =& new Controller(); - ob_start(); $Controller->flash('this should work', '/flash'); - $result = ob_get_clean(); + $result = $Controller->output; $expected = ' @@ -128,6 +127,25 @@ class ControllerTest extends CakeTestCase { $expected = str_replace(array("\t", "\r\n", "\n"), "", $expected); $this->assertEqual($result, $expected); } -} + function testControllerSet() { + $Controller =& new Controller(); + $Controller->set('variable_with_underscores', null); + $this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars)); + + $Controller->viewVars = array(); + $viewVars = array('ModelName' => array('id' => 1, 'name' => 'value')); + $Controller->set($viewVars); + $this->assertTrue(array_key_exists('modelName', $Controller->viewVars)); + + $Controller->viewVars = array(); + $Controller->set('variable_with_underscores', 'value'); + $this->assertTrue(array_key_exists('variable_with_underscores', $Controller->viewVars)); + + $Controller->viewVars = array(); + $viewVars = array('ModelName' => 'name'); + $Controller->set($viewVars); + $this->assertTrue(array_key_exists('modelName', $Controller->viewVars)); + } +} ?> \ No newline at end of file