File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed
Model/Entity/Attribute/Frontend
Test/Unit/Model/Entity/Attribute/Frontend Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ class AttributeMerger
45
45
'alphanumeric ' => 'validate-alphanum ' ,
46
46
'url ' => 'validate-url ' ,
47
47
'email ' => 'email2 ' ,
48
+ 'length ' => 'validate-length ' ,
48
49
];
49
50
50
51
/**
Original file line number Diff line number Diff line change @@ -158,10 +158,10 @@ public function getClass()
158
158
159
159
$ textLengthValidateClasses = $ this ->getTextLengthValidateClasses ();
160
160
if (!empty ($ textLengthValidateClasses )) {
161
- $ out[] = implode ( ' ' , $ textLengthValidateClasses );
161
+ $ out = array_merge ( $ out , $ textLengthValidateClasses );
162
162
}
163
163
164
- $ out = !empty ($ out ) ? trim ( implode (' ' , $ out )) : '' ;
164
+ $ out = !empty ($ out ) ? implode (' ' , array_unique ( array_filter ( $ out) )) : '' ;
165
165
return $ out ;
166
166
}
167
167
@@ -191,6 +191,9 @@ protected function _getInputValidateClass()
191
191
case 'url ' :
192
192
$ class = 'validate-url ' ;
193
193
break ;
194
+ case 'length ' :
195
+ $ class = 'validate-length ' ;
196
+ break ;
194
197
default :
195
198
$ class = false ;
196
199
break ;
Original file line number Diff line number Diff line change @@ -86,4 +86,36 @@ public function testGetClass()
86
86
$ this ->assertContains ('maximum-length-2 ' , $ result );
87
87
$ this ->assertContains ('validate-length ' , $ result );
88
88
}
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
+ }
89
121
}
You can’t perform that action at this time.
0 commit comments