Skip to content

Commit a47b10d

Browse files
committed
⏫ Forwardport of #11067 to 2.3-develop branch
1 parent 435a6c2 commit a47b10d

File tree

1 file changed

+34
-7
lines changed
  • app/code/Magento/Customer/Test/Unit/Block/Widget

1 file changed

+34
-7
lines changed

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ class DobTest extends \PHPUnit\Framework\TestCase
5757
*/
5858
protected $filterFactory;
5959

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+
6070
protected function setUp()
6171
{
6272
$zendCacheCore = new \Zend_Cache_Core();
@@ -82,8 +92,13 @@ protected function setUp()
8292
['localeResolver' => $localeResolver]
8393
);
8494

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

88103
$this->attribute = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
89104
->getMockForAbstractClass();
@@ -100,7 +115,7 @@ protected function setUp()
100115
->getMock();
101116

102117
$this->_block = new \Magento\Customer\Block\Widget\Dob(
103-
$context,
118+
$this->context,
104119
$this->createMock(\Magento\Customer\Helper\Address::class),
105120
$this->customerMetadata,
106121
$this->createMock(\Magento\Framework\View\Element\Html\Date::class),
@@ -454,25 +469,37 @@ public function testGetMaxDateRangeWithException()
454469
);
455470
$this->assertNull($this->_block->getMaxDateRange());
456471
}
457-
472+
458473
public function testGetHtmlExtraParamsWithoutRequiredOption()
459474
{
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"}}'));
460479
$this->attribute->expects($this->once())
461480
->method("isRequired")
462481
->willReturn(false);
463482

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+
);
465487
}
466488

467489
public function testGetHtmlExtraParamsWithRequiredOption()
468490
{
469491
$this->attribute->expects($this->once())
470492
->method("isRequired")
471493
->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));
472499

473500
$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()
476503
);
477504
}
478505
}

0 commit comments

Comments
 (0)