Skip to content

Commit 0fb8492

Browse files
committed
magento#11067: MAGETWO-80096-PR-11067
- Fixed Unit Test
1 parent d570e1d commit 0fb8492

File tree

1 file changed

+42
-8
lines changed
  • app/code/Magento/Customer/Test/Unit/Block/Widget

1 file changed

+42
-8
lines changed

app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ class DobTest extends \PHPUnit\Framework\TestCase
5959
*/
6060
protected $filterFactory;
6161

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+
6272
protected function setUp()
6373
{
6474
$zendCacheCore = new \Zend_Cache_Core();
@@ -84,8 +94,14 @@ protected function setUp()
8494
['localeResolver' => $localeResolver]
8595
);
8696

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));
89105

90106
$this->attribute = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
91107
->getMockForAbstractClass();
@@ -102,7 +118,7 @@ protected function setUp()
102118
->getMock();
103119

104120
$this->_block = new \Magento\Customer\Block\Widget\Dob(
105-
$context,
121+
$this->context,
106122
$this->createMock(\Magento\Customer\Helper\Address::class),
107123
$this->customerMetadata,
108124
$this->createMock(\Magento\Framework\View\Element\Html\Date::class),
@@ -465,22 +481,40 @@ public function testGetMaxDateRangeWithException()
465481
$this->assertNull($this->_block->getMaxDateRange());
466482
}
467483

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+
469491
$this->attribute->expects($this->once())
470492
->method("isRequired")
471493
->willReturn(false);
472494

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+
);
474499
}
475500

476-
public function testGetHtmlExtraParamsWithRequiredOption() {
501+
public function testGetHtmlExtraParamsWithRequiredOption()
502+
{
477503
$this->attribute->expects($this->once())
478504
->method("isRequired")
479505
->willReturn(true);
480506

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+
481515
$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()
484518
);
485519
}
486520
}

0 commit comments

Comments
 (0)