Changes reverted. Added 2 tests of error-related options

This commit is contained in:
Dario Savella 2019-03-15 17:41:29 +01:00
parent 5ba9e41df8
commit 08d11154a7
2 changed files with 57 additions and 1 deletions

View file

@ -2084,6 +2084,62 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* Test validation errors with error options
*
* @return void
*/
public function testPasswordValidationWithOptions() {
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['password'] = array('Please provide a password');
$result = $this->Form->input('Contact.password',array(
'error' => array(
'attributes' => array('class' => 'special-error-class'),
)
));
$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' => 'special-error-class')),
'Please provide a password',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$Contact->validationErrors['password'] = array('Please provide a password<br>otherwise you will not be able to login');
$result = $this->Form->input('Contact.password',array(
'error' => array(
'attributes' => array(
'class' => 'special-error-class',
'escape' => false,
)
)
));
$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' => 'special-error-class')),
'Please provide a password<br>otherwise you will not be able to login',
'/div',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Test validation errors, when validation message is an empty string.
*

View file

@ -1095,7 +1095,7 @@ class FormHelper extends AppHelper {
$out['error'] = null;
if ($type !== 'hidden' && $error !== false) {
$errMsg = $this->error($fieldName, null, $error);
$errMsg = $this->error($fieldName, $error);
if ($errMsg) {
$divOptions = $this->addClass($divOptions, Hash::get($divOptions, 'errorClass', 'error'));
if ($errorMessage) {