Skip to content

Commit

Permalink
Passing empty string in [\'error\'] behaved like false, now will beha…
Browse files Browse the repository at this point in the history
…ve like any other string
  • Loading branch information
ceeram authored and bar committed Sep 28, 2011
1 parent d489d49 commit 9f23f65
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/form.php
Expand Up @@ -512,7 +512,7 @@ function error($field, $text = null, $options = array()) {
unset($options[$error]);
}

if ($text != null) {
if ($text !== null) {
$error = $text;
} elseif (is_numeric($error)) {
$error = sprintf(__('Error in field %s', true), Inflector::humanize($this->field()));
Expand Down
30 changes: 29 additions & 1 deletion cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -1325,6 +1325,34 @@ function testPasswordValidation() {
$this->assertTags($result, $expected);
}

/**
* testEmptyErrorValidation method
*
* test validation error div
*
* @access public
* @return void
*/
function testEmptyErrorValidation() {
$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
$result = $this->Form->input('Contact.password', array('error' => ''));
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
array(),
'/div',
'/div'
);
$this->assertTags($result, $expected);
}

/**
* testFormValidationAssociated method
*
Expand Down Expand Up @@ -5804,7 +5832,7 @@ public function testCreateOnSubmit() {

$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post',
'id' => 'ContactAddForm', 'method' => 'post',
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
'action' => '/contacts/index/param',
'accept-charset' => 'utf-8'
Expand Down

0 comments on commit 9f23f65

Please sign in to comment.