Skip to content

Commit 81cba12

Browse files
author
Sergii Kovalenko
committed
Merge branch 'MAGETWO-49669' into BUGS
2 parents 910d913 + 74898ae commit 81cba12

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AttributeMerger
4545
'alphanumeric' => 'validate-alphanum',
4646
'url' => 'validate-url',
4747
'email' => 'email2',
48+
'length' => 'validate-length',
4849
];
4950

5051
/**

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ public function getClass()
158158

159159
$textLengthValidateClasses = $this->getTextLengthValidateClasses();
160160
if (!empty($textLengthValidateClasses)) {
161-
$out[] = implode(' ', $textLengthValidateClasses);
161+
$out = array_merge($out, $textLengthValidateClasses);
162162
}
163163

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

@@ -191,6 +191,9 @@ protected function _getInputValidateClass()
191191
case 'url':
192192
$class = 'validate-url';
193193
break;
194+
case 'length':
195+
$class = 'validate-length';
196+
break;
194197
default:
195198
$class = false;
196199
break;

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,36 @@ public function testGetClass()
8686
$this->assertContains('maximum-length-2', $result);
8787
$this->assertContains('validate-length', $result);
8888
}
89+
90+
public function testGetClassLength()
91+
{
92+
$attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\AbstractAttribute')
93+
->disableOriginalConstructor()
94+
->setMethods([
95+
'getIsRequired',
96+
'getFrontendClass',
97+
'getValidateRules',
98+
])
99+
->getMock();
100+
$attributeMock->expects($this->once())
101+
->method('getIsRequired')
102+
->willReturn(true);
103+
$attributeMock->expects($this->once())
104+
->method('getFrontendClass')
105+
->willReturn('');
106+
$attributeMock->expects($this->exactly(3))
107+
->method('getValidateRules')
108+
->willReturn([
109+
'input_validation' => 'length',
110+
'min_text_length' => 1,
111+
'max_text_length' => 2,
112+
]);
113+
114+
$this->model->setAttribute($attributeMock);
115+
$result = $this->model->getClass();
116+
117+
$this->assertContains('minimum-length-1', $result);
118+
$this->assertContains('maximum-length-2', $result);
119+
$this->assertContains('validate-length', $result);
120+
}
89121
}

0 commit comments

Comments
 (0)