@@ -57,6 +57,16 @@ class DobTest extends \PHPUnit\Framework\TestCase
57
57
*/
58
58
protected $ filterFactory ;
59
59
60
+ /**
61
+ * @var \Magento\Framework\Escaper
62
+ */
63
+ private $ escaper ;
64
+
65
+ /**
66
+ * @var \Magento\Framework\View\Element\Template\Context
67
+ */
68
+ private $ context ;
69
+
60
70
protected function setUp ()
61
71
{
62
72
$ zendCacheCore = new \Zend_Cache_Core ();
@@ -82,8 +92,13 @@ protected function setUp()
82
92
['localeResolver ' => $ localeResolver ]
83
93
);
84
94
85
- $ context = $ this ->createMock (\Magento \Framework \View \Element \Template \Context::class);
86
- $ context ->expects ($ this ->any ())->method ('getLocaleDate ' )->will ($ this ->returnValue ($ timezone ));
95
+ $ this ->context = $ this ->createMock (\Magento \Framework \View \Element \Template \Context::class);
96
+ $ this ->context ->expects ($ this ->any ())->method ('getLocaleDate ' )->will ($ this ->returnValue ($ timezone ));
97
+ $ this ->escaper = $ this ->getMockBuilder (\Magento \Framework \Escaper::class)
98
+ ->disableOriginalConstructor ()
99
+ ->setMethods (['escapeHtml ' ])
100
+ ->getMock ();
101
+ $ this ->context ->expects ($ this ->any ())->method ('getEscaper ' )->will ($ this ->returnValue ($ this ->escaper ));
87
102
88
103
$ this ->attribute = $ this ->getMockBuilder (\Magento \Customer \Api \Data \AttributeMetadataInterface::class)
89
104
->getMockForAbstractClass ();
@@ -100,7 +115,7 @@ protected function setUp()
100
115
->getMock ();
101
116
102
117
$ this ->_block = new \Magento \Customer \Block \Widget \Dob (
103
- $ context ,
118
+ $ this -> context ,
104
119
$ this ->createMock (\Magento \Customer \Helper \Address::class),
105
120
$ this ->customerMetadata ,
106
121
$ this ->createMock (\Magento \Framework \View \Element \Html \Date::class),
@@ -454,25 +469,37 @@ public function testGetMaxDateRangeWithException()
454
469
);
455
470
$ this ->assertNull ($ this ->_block ->getMaxDateRange ());
456
471
}
457
-
472
+
458
473
public function testGetHtmlExtraParamsWithoutRequiredOption ()
459
474
{
475
+ $ this ->escaper ->expects ($ this ->any ())
476
+ ->method ('escapeHtml ' )
477
+ ->with ('{"validate-date":{"dateFormat":"M\/d\/yy"}} ' )
478
+ ->will ($ this ->returnValue ('{"validate-date":{"dateFormat":"M\/d\/yy"}} ' ));
460
479
$ this ->attribute ->expects ($ this ->once ())
461
480
->method ("isRequired " )
462
481
->willReturn (false );
463
482
464
- $ this ->assertEquals ($ this ->_block ->getHtmlExtraParams (), 'data-validate="{ \'validate-date-au \':true}" ' );
483
+ $ this ->assertEquals (
484
+ $ this ->_block ->getHtmlExtraParams (),
485
+ 'data-validate="{"validate-date":{"dateFormat":"M\/d\/yy"}}" '
486
+ );
465
487
}
466
488
467
489
public function testGetHtmlExtraParamsWithRequiredOption ()
468
490
{
469
491
$ this ->attribute ->expects ($ this ->once ())
470
492
->method ("isRequired " )
471
493
->willReturn (true );
494
+ $ this ->escaper ->expects ($ this ->any ())
495
+ ->method ('escapeHtml ' )
496
+ ->with ('{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}} ' )
497
+ ->will ($ this ->returnValue ('{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}} ' ));
498
+ $ this ->context ->expects ($ this ->any ())->method ('getEscaper ' )->will ($ this ->returnValue ($ this ->escaper ));
472
499
473
500
$ this ->assertEquals (
474
- $ this -> _block -> getHtmlExtraParams () ,
475
- ' data-validate="{ \' validate-date-au \' :true, required:true}" '
501
+ ' data-validate="{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}}" ' ,
502
+ $ this -> _block -> getHtmlExtraParams ()
476
503
);
477
504
}
478
505
}
0 commit comments