Skip to content

Commit

Permalink
⏫ Forwardport of #11067 to 2.3-develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Jan 24, 2018
1 parent 435a6c2 commit a47b10d
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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),
Expand Down Expand Up @@ -454,25 +469,37 @@ 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()
{
$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()
);
}
}

0 comments on commit a47b10d

Please sign in to comment.