From 02c3294cb2ae832fff068ed981c0dfa8f7c9674c Mon Sep 17 00:00:00 2001 From: Fanis Strezos Date: Tue, 11 Feb 2020 11:47:20 +0000 Subject: [PATCH 1/2] preg_replace modified in order DOB to be validated in moment js --- lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php index 2568a5ccf21c1..bd307fda7b995 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php @@ -130,8 +130,8 @@ public function getDateFormat($type = \IntlDateFormatter::SHORT) public function getDateFormatWithLongYear() { return preg_replace( - '/(?getDateFormat() ); } From 315f060d1f6d4f9927060e96bbe420839570b2a6 Mon Sep 17 00:00:00 2001 From: Fanis Strezos Date: Wed, 12 Feb 2020 10:55:57 +0000 Subject: [PATCH 2/2] Ammend unit tests --- .../Test/Unit/Block/Widget/DobTest.php | 18 +++++++++--------- .../Framework/Stdlib/DateTime/Timezone.php | 2 +- 2 files changed, 10 insertions(+), 10 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 1fd7fc340e542..d793b864e0e79 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php @@ -48,7 +48,7 @@ class DobTest extends TestCase const YEAR = '2014'; // Value of date('Y', strtotime(self::DATE)) - const DATE_FORMAT = 'M/d/Y'; + const DATE_FORMAT = 'M/dd/Y'; /** Constants used by Dob::setDateInput($code, $html) */ const DAY_HTML = @@ -357,8 +357,8 @@ public function getDateFormatDataProvider(): array [ 'ar_SA', preg_replace( - '/[^MmDdYy\/\.\-]/', - '', + ['/[^MmDdYy\/\.\-]/','/d+/'], + ['','dd'], (new \IntlDateFormatter('ar_SA', \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE)) ->getPattern() ) @@ -544,8 +544,8 @@ public function testGetHtmlExtraParamsWithoutRequiredOption() { $this->escaper->expects($this->any()) ->method('escapeHtml') - ->with('{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}') - ->will($this->returnValue('{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}')); + ->with('{"validate-date":{"dateFormat":"M\/dd\/Y"},"validate-dob":true}') + ->will($this->returnValue('{"validate-date":{"dateFormat":"M\/dd\/Y"},"validate-dob":true}')); $this->attribute->expects($this->once()) ->method("isRequired") @@ -553,7 +553,7 @@ public function testGetHtmlExtraParamsWithoutRequiredOption() $this->assertEquals( $this->_block->getHtmlExtraParams(), - 'data-validate="{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}"' + 'data-validate="{"validate-date":{"dateFormat":"M\/dd\/Y"},"validate-dob":true}"' ); } @@ -567,17 +567,17 @@ public function testGetHtmlExtraParamsWithRequiredOption() ->willReturn(true); $this->escaper->expects($this->any()) ->method('escapeHtml') - ->with('{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}') + ->with('{"required":true,"validate-date":{"dateFormat":"M\/dd\/Y"},"validate-dob":true}') ->will( $this->returnValue( - '{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}' + '{"required":true,"validate-date":{"dateFormat":"M\/dd\/Y"},"validate-dob":true}' ) ); $this->context->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaper)); $this->assertEquals( - 'data-validate="{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}"', + 'data-validate="{"required":true,"validate-date":{"dateFormat":"M\/dd\/Y"},"validate-dob":true}"', $this->_block->getHtmlExtraParams() ); } diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php index bd307fda7b995..fb4b5d44a28f7 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php @@ -130,7 +130,7 @@ public function getDateFormat($type = \IntlDateFormatter::SHORT) public function getDateFormatWithLongYear() { return preg_replace( - ['/(?getDateFormat() );