mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
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:
parent
1bf81bbee9
commit
e03c12eea3
2 changed files with 17 additions and 0 deletions
|
@ -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)) {
|
if (is_array($options)) {
|
||||||
$options[$key] = $result;
|
$options[$key] = $result;
|
||||||
return $options;
|
return $options;
|
||||||
|
|
|
@ -144,6 +144,16 @@ class FormHelperTest extends UnitTestCase {
|
||||||
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
|
$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() {
|
function testFieldError() {
|
||||||
$this->Form->validationErrors['Model']['field'] = 1;
|
$this->Form->validationErrors['Model']['field'] = 1;
|
||||||
$result = $this->Form->error('Model.field');
|
$result = $this->Form->error('Model.field');
|
||||||
|
|
Loading…
Add table
Reference in a new issue