@@ -59,6 +59,16 @@ class DobTest extends \PHPUnit\Framework\TestCase
59
59
*/
60
60
protected $ filterFactory ;
61
61
62
+ /**
63
+ * @var \Magento\Framework\Escaper
64
+ */
65
+ private $ escaper ;
66
+
67
+ /**
68
+ * @var \Magento\Framework\View\Element\Template\Context
69
+ */
70
+ private $ context ;
71
+
62
72
protected function setUp ()
63
73
{
64
74
$ zendCacheCore = new \Zend_Cache_Core ();
@@ -84,8 +94,14 @@ protected function setUp()
84
94
['localeResolver ' => $ localeResolver ]
85
95
);
86
96
87
- $ context = $ this ->createMock (\Magento \Framework \View \Element \Template \Context::class);
88
- $ context ->expects ($ this ->any ())->method ('getLocaleDate ' )->will ($ this ->returnValue ($ timezone ));
97
+ $ this ->context = $ this ->createMock (\Magento \Framework \View \Element \Template \Context::class);
98
+ $ this ->context ->expects ($ this ->any ())->method ('getLocaleDate ' )->will ($ this ->returnValue ($ timezone ));
99
+
100
+ $ this ->escaper = $ this ->getMockBuilder (\Magento \Framework \Escaper::class)
101
+ ->disableOriginalConstructor ()
102
+ ->setMethods (['escapeHtml ' ])
103
+ ->getMock ();
104
+ $ this ->context ->expects ($ this ->any ())->method ('getEscaper ' )->will ($ this ->returnValue ($ this ->escaper ));
89
105
90
106
$ this ->attribute = $ this ->getMockBuilder (\Magento \Customer \Api \Data \AttributeMetadataInterface::class)
91
107
->getMockForAbstractClass ();
@@ -102,7 +118,7 @@ protected function setUp()
102
118
->getMock ();
103
119
104
120
$ this ->_block = new \Magento \Customer \Block \Widget \Dob (
105
- $ context ,
121
+ $ this -> context ,
106
122
$ this ->createMock (\Magento \Customer \Helper \Address::class),
107
123
$ this ->customerMetadata ,
108
124
$ this ->createMock (\Magento \Framework \View \Element \Html \Date::class),
@@ -465,22 +481,40 @@ public function testGetMaxDateRangeWithException()
465
481
$ this ->assertNull ($ this ->_block ->getMaxDateRange ());
466
482
}
467
483
468
- public function testGetHtmlExtraParamsWithoutRequiredOption () {
484
+ public function testGetHtmlExtraParamsWithoutRequiredOption ()
485
+ {
486
+ $ this ->escaper ->expects ($ this ->any ())
487
+ ->method ('escapeHtml ' )
488
+ ->with ('{"validate-date":{"dateFormat":"M\/d\/yy"}} ' )
489
+ ->will ($ this ->returnValue ('{"validate-date":{"dateFormat":"M\/d\/yy"}} ' ));
490
+
469
491
$ this ->attribute ->expects ($ this ->once ())
470
492
->method ("isRequired " )
471
493
->willReturn (false );
472
494
473
- $ this ->assertEquals ($ this ->_block ->getHtmlExtraParams (), 'data-validate="{ \'validate-date-au \':true}" ' );
495
+ $ this ->assertEquals (
496
+ $ this ->_block ->getHtmlExtraParams (),
497
+ 'data-validate="{"validate-date":{"dateFormat":"M\/d\/yy"}}" '
498
+ );
474
499
}
475
500
476
- public function testGetHtmlExtraParamsWithRequiredOption () {
501
+ public function testGetHtmlExtraParamsWithRequiredOption ()
502
+ {
477
503
$ this ->attribute ->expects ($ this ->once ())
478
504
->method ("isRequired " )
479
505
->willReturn (true );
480
506
507
+ $ this ->escaper ->expects ($ this ->any ())
508
+ ->method ('escapeHtml ' )
509
+ ->with ('{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}} ' )
510
+ ->will ($ this ->returnValue ('{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}} ' ));
511
+
512
+
513
+ $ this ->context ->expects ($ this ->any ())->method ('getEscaper ' )->will ($ this ->returnValue ($ this ->escaper ));
514
+
481
515
$ this ->assertEquals (
482
- $ this -> _block -> getHtmlExtraParams () ,
483
- ' data-validate="{ \' validate-date-au \' :true, required:true}" '
516
+ ' data-validate="{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}}" ' ,
517
+ $ this -> _block -> getHtmlExtraParams ()
484
518
);
485
519
}
486
520
}
0 commit comments