Skip to content

Commit 6ddd1d1

Browse files
committed
MC-20118: Arabic Date Selector shows date in incorrect format
1 parent 56003dd commit 6ddd1d1

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ public function getHtmlExtraParams()
277277
*/
278278
public function getDateFormat()
279279
{
280-
return $this->_localeDate->getDateFormatWithLongYear();
280+
$dateFormat = $this->_localeDate->getDateFormatWithLongYear();
281+
/** Escape RTL characters which are present in some locales and corrupt formatting */
282+
$escapedDateFormat = preg_replace('/[^MmDdYy\/\.\-]/', '', $dateFormat);
283+
284+
return $escapedDateFormat;
281285
}
282286

283287
/**

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Magento\Framework\View\Element\Html\Date;
2424
use Magento\Framework\View\Element\Template\Context;
2525
use PHPUnit\Framework\TestCase;
26-
use PHPUnit_Framework_MockObject_MockObject;
26+
use PHPUnit\Framework\MockObject\MockObject;
2727
use Zend_Cache_Backend_BlackHole;
2828
use Zend_Cache_Core;
2929

@@ -60,17 +60,17 @@ class DobTest extends TestCase
6060
const YEAR_HTML =
6161
'<div><label for="year"><span>yy</span></label><input type="text" id="year" name="Year" value="14"></div>';
6262

63-
/** @var PHPUnit_Framework_MockObject_MockObject|AttributeMetadataInterface */
63+
/** @var MockObject|AttributeMetadataInterface */
6464
protected $attribute;
6565

6666
/** @var Dob */
6767
protected $_block;
6868

69-
/** @var PHPUnit_Framework_MockObject_MockObject|CustomerMetadataInterface */
69+
/** @var MockObject|CustomerMetadataInterface */
7070
protected $customerMetadata;
7171

7272
/**
73-
* @var FilterFactory|PHPUnit_Framework_MockObject_MockObject
73+
* @var FilterFactory|MockObject
7474
*/
7575
protected $filterFactory;
7676

@@ -336,12 +336,27 @@ public function getYearDataProvider()
336336
}
337337

338338
/**
339-
* is used to derive the Locale that is used to determine the
340-
* value of Dob::getDateFormat() for that Locale.
339+
* Is used to derive the Locale that is used to determine the value of Dob::getDateFormat() for that Locale
340+
*
341+
* @param string $locale
342+
* @param string $expectedFormat
343+
* @dataProvider getDateFormatDataProvider
341344
*/
342-
public function testGetDateFormat()
345+
public function testGetDateFormat(string $locale, string $expectedFormat)
343346
{
344-
$this->assertEquals(self::DATE_FORMAT, $this->_block->getDateFormat());
347+
$this->_locale = $locale;
348+
$this->assertEquals($expectedFormat, $this->_block->getDateFormat());
349+
}
350+
351+
/**
352+
* @return array
353+
*/
354+
public function getDateFormatDataProvider(): array
355+
{
356+
return [
357+
['ar_SA', 'd/M/y'],
358+
[Resolver::DEFAULT_LOCALE, self::DATE_FORMAT],
359+
];
345360
}
346361

347362
/**

0 commit comments

Comments
 (0)