From a47b10dce854a2d21ead6b362b86ca3ddf595386 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Wed, 24 Jan 2018 15:25:13 +0200 Subject: [PATCH] :arrow_double_up: Forwardport of magento/magento2#11067 to 2.3-develop branch --- .../Test/Unit/Block/Widget/DobTest.php | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php b/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php index 81d9a144bec5e..5ea3067409935 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php @@ -57,6 +57,16 @@ class DobTest extends \PHPUnit\Framework\TestCase */ protected $filterFactory; + /** + * @var \Magento\Framework\Escaper + */ + private $escaper; + + /** + * @var \Magento\Framework\View\Element\Template\Context + */ + private $context; + protected function setUp() { $zendCacheCore = new \Zend_Cache_Core(); @@ -82,8 +92,13 @@ protected function setUp() ['localeResolver' => $localeResolver] ); - $context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); - $context->expects($this->any())->method('getLocaleDate')->will($this->returnValue($timezone)); + $this->context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); + $this->context->expects($this->any())->method('getLocaleDate')->will($this->returnValue($timezone)); + $this->escaper = $this->getMockBuilder(\Magento\Framework\Escaper::class) + ->disableOriginalConstructor() + ->setMethods(['escapeHtml']) + ->getMock(); + $this->context->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaper)); $this->attribute = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class) ->getMockForAbstractClass(); @@ -100,7 +115,7 @@ protected function setUp() ->getMock(); $this->_block = new \Magento\Customer\Block\Widget\Dob( - $context, + $this->context, $this->createMock(\Magento\Customer\Helper\Address::class), $this->customerMetadata, $this->createMock(\Magento\Framework\View\Element\Html\Date::class), @@ -454,14 +469,21 @@ public function testGetMaxDateRangeWithException() ); $this->assertNull($this->_block->getMaxDateRange()); } - + public function testGetHtmlExtraParamsWithoutRequiredOption() { + $this->escaper->expects($this->any()) + ->method('escapeHtml') + ->with('{"validate-date":{"dateFormat":"M\/d\/yy"}}') + ->will($this->returnValue('{"validate-date":{"dateFormat":"M\/d\/yy"}}')); $this->attribute->expects($this->once()) ->method("isRequired") ->willReturn(false); - $this->assertEquals($this->_block->getHtmlExtraParams(), 'data-validate="{\'validate-date-au\':true}"'); + $this->assertEquals( + $this->_block->getHtmlExtraParams(), + 'data-validate="{"validate-date":{"dateFormat":"M\/d\/yy"}}"' + ); } public function testGetHtmlExtraParamsWithRequiredOption() @@ -469,10 +491,15 @@ public function testGetHtmlExtraParamsWithRequiredOption() $this->attribute->expects($this->once()) ->method("isRequired") ->willReturn(true); + $this->escaper->expects($this->any()) + ->method('escapeHtml') + ->with('{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}}') + ->will($this->returnValue('{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}}')); + $this->context->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaper)); $this->assertEquals( - $this->_block->getHtmlExtraParams(), - 'data-validate="{\'validate-date-au\':true, required:true}"' + 'data-validate="{"required":true,"validate-date":{"dateFormat":"M\/d\/yy"}}"', + $this->_block->getHtmlExtraParams() ); } }