From 5ba9e41df8c2ec2b6bfded55d27a8dcfba480007 Mon Sep 17 00:00:00 2001 From: Dario Savella Date: Fri, 15 Mar 2019 10:39:52 +0100 Subject: [PATCH 1/3] Form helper did not respect passed FormHelper::inputDefaults() --- lib/Cake/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 83eb67eaf..db1aa4164 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1095,7 +1095,7 @@ class FormHelper extends AppHelper { $out['error'] = null; if ($type !== 'hidden' && $error !== false) { - $errMsg = $this->error($fieldName, $error); + $errMsg = $this->error($fieldName, null, $error); if ($errMsg) { $divOptions = $this->addClass($divOptions, Hash::get($divOptions, 'errorClass', 'error')); if ($errorMessage) { From 08d11154a7b2f2d0014488be9b5287a910658c15 Mon Sep 17 00:00:00 2001 From: Dario Savella Date: Fri, 15 Mar 2019 17:41:29 +0100 Subject: [PATCH 2/3] Changes reverted. Added 2 tests of error-related options --- .../Test/Case/View/Helper/FormHelperTest.php | 56 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 40a147782..43c1e68d1 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -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
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
otherwise you will not be able to login', + '/div', + '/div' + ); + $this->assertTags($result, $expected); + } + /** * Test validation errors, when validation message is an empty string. * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index db1aa4164..83eb67eaf 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -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) { From cf5577234f625afdb2ee3ae51b8a4a96d5af4f81 Mon Sep 17 00:00:00 2001 From: Dario Savella Date: Fri, 15 Mar 2019 18:50:26 +0100 Subject: [PATCH 3/3] PHPCS typos fixed --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 43c1e68d1..4aa6c66fb 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2093,10 +2093,10 @@ class FormHelperTest extends CakeTestCase { $Contact = ClassRegistry::getObject('Contact'); $Contact->validationErrors['password'] = array('Please provide a password'); - $result = $this->Form->input('Contact.password',array( + $result = $this->Form->input('Contact.password', array( 'error' => array( - 'attributes' => array('class' => 'special-error-class'), - ) + 'attributes' => array('class' => 'special-error-class'), + ) )); $expected = array( 'div' => array('class' => 'input password error'), @@ -2115,7 +2115,7 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $Contact->validationErrors['password'] = array('Please provide a password
otherwise you will not be able to login'); - $result = $this->Form->input('Contact.password',array( + $result = $this->Form->input('Contact.password', array( 'error' => array( 'attributes' => array( 'class' => 'special-error-class',