File tree 2 files changed +75
-2
lines changed
lib/internal/Magento/Framework
Test/Unit/Data/Form/Element
2 files changed +75
-2
lines changed Original file line number Diff line number Diff line change @@ -353,8 +353,13 @@ public function getElementHtml()
353
353
$ html .= '<label class="addbefore" for=" ' . $ htmlId . '"> ' . $ beforeElementHtml . '</label> ' ;
354
354
}
355
355
356
- $ html .= '<input id=" ' . $ htmlId . '" name=" ' . $ this ->getName () . '" ' . $ this ->_getUiId () . ' value=" ' .
357
- $ this ->getEscapedValue () . '" ' . $ this ->serialize ($ this ->getHtmlAttributes ()) . '/> ' ;
356
+ if (is_array ($ this ->getValue ())) {
357
+ foreach ($ this ->getValue () as $ value ) {
358
+ $ html .= $ this ->getHtmlForInputByValue ($ this ->_escape ($ value ));
359
+ }
360
+ } else {
361
+ $ html .= $ this ->getHtmlForInputByValue ($ this ->getEscapedValue ());
362
+ }
358
363
359
364
$ afterElementJs = $ this ->getAfterElementJs ();
360
365
if ($ afterElementJs ) {
@@ -574,4 +579,17 @@ public function isLocked()
574
579
{
575
580
return $ this ->getData ($ this ->lockHtmlAttribute ) == 1 ;
576
581
}
582
+
583
+ /**
584
+ * Get input html by sting value.
585
+ *
586
+ * @param string $value
587
+ *
588
+ * @return string
589
+ */
590
+ private function getHtmlForInputByValue (string $ value )
591
+ {
592
+ return '<input id=" ' . $ this ->getHtmlId () . '" name=" ' . $ this ->getName () . '" ' . $ this ->_getUiId ()
593
+ . ' value=" ' . $ value . '" ' . $ this ->serialize ($ this ->getHtmlAttributes ()) . '/> ' ;
594
+ }
577
595
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ namespace Magento \Framework \Test \Unit \Data ;
8
+
9
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
+
11
+ /**
12
+ * Test for \Magento\Framework\Data\Form\Element\Hidden.
13
+ */
14
+ class HiddenTest extends \PHPUnit \Framework \TestCase
15
+ {
16
+ /**
17
+ * @var \Magento\Framework\Data\Form\Element\Hidden
18
+ */
19
+ private $ element ;
20
+
21
+ protected function setUp ()
22
+ {
23
+ $ objectManager = new ObjectManager ($ this );
24
+ $ this ->element = $ objectManager ->getObject (\Magento \Framework \Data \Form \Element \Hidden::class);
25
+ }
26
+
27
+ /**
28
+ * @param mixed $value
29
+ *
30
+ * @dataProvider getElementHtmlDataProvider
31
+ */
32
+ public function testGetElementHtml ($ value )
33
+ {
34
+ $ form = $ this ->createMock (\Magento \Framework \Data \Form::class);
35
+ $ this ->element ->setForm ($ form );
36
+ $ this ->element ->setValue ($ value );
37
+ $ html = $ this ->element ->getElementHtml ();
38
+
39
+ if (is_array ($ value )) {
40
+ foreach ($ value as $ item ) {
41
+ $ this ->assertContains ($ item , $ html );
42
+ }
43
+ } else {
44
+ $ this ->assertContains ($ value , $ html );
45
+ }
46
+ }
47
+
48
+ public function getElementHtmlDataProvider ()
49
+ {
50
+ return [
51
+ ['some_value ' ],
52
+ ['store_ids[] ' => ['1 ' , '2 ' ]],
53
+ ];
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments