From e03c12eea3f1f408b2e2db8967af559bc82f2ec4 Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 23 Mar 2007 17:32:02 +0000 Subject: [PATCH] Fixing default input values for form inputs, and adding test case git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4664 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helper.php | 7 +++++++ cake/tests/cases/libs/view/helpers/form.test.php | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 00d112c3f..ca5d8248a 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -465,6 +465,13 @@ class Helper extends Overloadable { } } + if (is_array($options)) { + if (empty($result) && isset($options['default'])) { + $result = $options['default']; + } + unset($options['default']); + } + if (is_array($options)) { $options[$key] = $result; return $options; diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 6a83a1568..4c65e75e2 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -144,6 +144,16 @@ class FormHelperTest extends UnitTestCase { $this->assertNoPattern('/]+[^type|name|id|value|class]=[^<>]*>/', $result); } + function testDefaultValue() { + $this->Form->data['Model']['field'] = 'test'; + $result = $this->Form->text('Model/field', array('default' => 'default value')); + $this->assertPattern('/^]+value="test"[^<>]+\/>$/', $result); + + unset($this->Form->data['Model']['field']); + $result = $this->Form->text('Model/field', array('default' => 'default value')); + $this->assertPattern('/^]+value="default value"[^<>]+\/>$/', $result); + } + function testFieldError() { $this->Form->validationErrors['Model']['field'] = 1; $result = $this->Form->error('Model.field');