Skip to content

Commit cce27f1

Browse files
author
Sergey Semenov
committed
MAGETWO-42994: Customer custom attribute is not validated on frontend
1 parent e5fb2be commit cce27f1

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

app/code/Magento/Eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function getClass()
161161
$out[] = implode(' ', $textLengthValidateClasses);
162162
}
163163

164-
$out = !empty($out) ? implode(' ', $out) : '';
164+
$out = !empty($out) ? trim(implode(' ', $out)) : '';
165165
return $out;
166166
}
167167

@@ -208,15 +208,17 @@ private function getTextLengthValidateClasses()
208208
{
209209
$classes = [];
210210

211-
$validateRules = $this->getAttribute()->getValidateRules();
212-
if (!empty($validateRules['min_text_length'])) {
213-
$classes[] = 'minimum-length-' . $validateRules['min_text_length'];
214-
}
215-
if (!empty($validateRules['max_text_length'])) {
216-
$classes[] = 'maximum-length-' . $validateRules['max_text_length'];
217-
}
218-
if (!empty($classes)) {
219-
$classes[] = 'validate-length';
211+
if ($this->_getInputValidateClass()) {
212+
$validateRules = $this->getAttribute()->getValidateRules();
213+
if (!empty($validateRules['min_text_length'])) {
214+
$classes[] = 'minimum-length-' . $validateRules['min_text_length'];
215+
}
216+
if (!empty($validateRules['max_text_length'])) {
217+
$classes[] = 'maximum-length-' . $validateRules['max_text_length'];
218+
}
219+
if (!empty($classes)) {
220+
$classes[] = 'validate-length';
221+
}
220222
}
221223

222224
return $classes;

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Frontend/DefaultFrontendTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ protected function setUp()
3232

3333
public function testGetClassEmpty()
3434
{
35-
/** @var \PHPUnit_Framework_MockObject_MockObject $attributeMock */
3635
$attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\AbstractAttribute')
3736
->disableOriginalConstructor()
3837
->setMethods([
@@ -57,7 +56,6 @@ public function testGetClassEmpty()
5756

5857
public function testGetClass()
5958
{
60-
/** @var \PHPUnit_Framework_MockObject_MockObject $attributeMock */
6159
$attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\AbstractAttribute')
6260
->disableOriginalConstructor()
6361
->setMethods([
@@ -72,7 +70,7 @@ public function testGetClass()
7270
$attributeMock->expects($this->once())
7371
->method('getFrontendClass')
7472
->willReturn('');
75-
$attributeMock->expects($this->exactly(2))
73+
$attributeMock->expects($this->exactly(3))
7674
->method('getValidateRules')
7775
->willReturn([
7876
'input_validation' => 'alphanumeric',

dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getAttributeMetadataDataProvider()
7474
AttributeMetadata::REQUIRED => true,
7575
AttributeMetadata::DATA_MODEL => '',
7676
AttributeMetadata::OPTIONS => [],
77-
AttributeMetadata::FRONTEND_CLASS => ' required-entry',
77+
AttributeMetadata::FRONTEND_CLASS => 'required-entry',
7878
AttributeMetadata::USER_DEFINED => false,
7979
AttributeMetadata::SORT_ORDER => 40,
8080
AttributeMetadata::FRONTEND_LABEL => 'First Name',
@@ -134,7 +134,7 @@ public function getAttributeMetadataDataProvider()
134134
AttributeMetadata::OPTIONS => [
135135
['label' => 'Main Website', 'value' => '1'],
136136
],
137-
AttributeMetadata::FRONTEND_CLASS => ' required-entry',
137+
AttributeMetadata::FRONTEND_CLASS => 'required-entry',
138138
AttributeMetadata::USER_DEFINED => false,
139139
AttributeMetadata::SORT_ORDER => 10,
140140
AttributeMetadata::FRONTEND_LABEL => 'Associate to Website',

dev/tests/integration/testsuite/Magento/Customer/Helper/AddressTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public function getAttributeValidationClass()
3030
{
3131
return [
3232
['bad-code', ''],
33-
['city', ' required-entry'],
33+
['city', 'required-entry'],
3434
['company', ''],
35-
['country_id', ' required-entry'],
35+
['country_id', 'required-entry'],
3636
['fax', ''],
3737
['firstname', 'required-entry'],
3838
['lastname', 'required-entry'],

0 commit comments

Comments
 (0)