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
This commit is contained in:
nate 2007-03-23 17:32:02 +00:00
parent 1bf81bbee9
commit e03c12eea3
2 changed files with 17 additions and 0 deletions

View file

@ -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;

View file

@ -144,6 +144,16 @@ class FormHelperTest extends UnitTestCase {
$this->assertNoPattern('/<input[^<>]+[^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('/^<input[^<>]+value="test"[^<>]+\/>$/', $result);
unset($this->Form->data['Model']['field']);
$result = $this->Form->text('Model/field', array('default' => 'default value'));
$this->assertPattern('/^<input[^<>]+value="default value"[^<>]+\/>$/', $result);
}
function testFieldError() {
$this->Form->validationErrors['Model']['field'] = 1;
$result = $this->Form->error('Model.field');