Skip to content

Commit 2a29bec

Browse files
committed
MC-20622: Email sent from admin order edit includes incorrect static file paths
- Fix unable to set local though \Magento\Backend\Model\Locale\Resolver::setLocale()
1 parent 6f1a6f7 commit 2a29bec

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

app/code/Magento/Backend/Model/Locale/Resolver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
/**
99
* Backend locale model
10+
*
1011
* @api
1112
* @since 100.0.2
13+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1214
*/
1315
class Resolver extends \Magento\Framework\Locale\Resolver
1416
{
@@ -40,7 +42,7 @@ class Resolver extends \Magento\Framework\Locale\Resolver
4042
* @param Manager $localeManager
4143
* @param \Magento\Framework\App\RequestInterface $request
4244
* @param \Magento\Framework\Validator\Locale $localeValidator
43-
* @param null $locale
45+
* @param string|null $locale
4446
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4547
*/
4648
public function __construct(
@@ -76,7 +78,7 @@ public function setLocale($locale = null)
7678
$sessionLocale = $this->_session->getSessionLocale();
7779
$userLocale = $this->_localeManager->getUserInterfaceLocale();
7880

79-
$localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]);
81+
$localeCodes = array_filter([$forceLocale, $locale, $sessionLocale, $userLocale]);
8082

8183
if (count($localeCodes)) {
8284
$locale = reset($localeCodes);

dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class ResolverTest extends \PHPUnit\Framework\TestCase
2020
*/
2121
protected $_model;
2222

23+
/**
24+
* {@inheritDoc}
25+
*/
2326
protected function setUp()
2427
{
2528
parent::setUp();
@@ -29,15 +32,15 @@ protected function setUp()
2932
}
3033

3134
/**
32-
* @covers \Magento\Backend\Model\Locale\Resolver::setLocale
35+
* Tests setLocale() with default locale
3336
*/
3437
public function testSetLocaleWithDefaultLocale()
3538
{
3639
$this->_checkSetLocale(Resolver::DEFAULT_LOCALE);
3740
}
3841

3942
/**
40-
* @covers \Magento\Backend\Model\Locale\Resolver::setLocale
43+
* Tests setLocale() with interface locale
4144
*/
4245
public function testSetLocaleWithBaseInterfaceLocale()
4346
{
@@ -55,7 +58,7 @@ public function testSetLocaleWithBaseInterfaceLocale()
5558
}
5659

5760
/**
58-
* @covers \Magento\Backend\Model\Locale\Resolver::setLocale
61+
* Tests setLocale() with session locale
5962
*/
6063
public function testSetLocaleWithSessionLocale()
6164
{
@@ -68,7 +71,7 @@ public function testSetLocaleWithSessionLocale()
6871
}
6972

7073
/**
71-
* @covers \Magento\Backend\Model\Locale\Resolver::setLocale
74+
* Tests setLocale() with post parameter
7275
*/
7376
public function testSetLocaleWithRequestLocale()
7477
{
@@ -78,13 +81,45 @@ public function testSetLocaleWithRequestLocale()
7881
$this->_checkSetLocale('de_DE');
7982
}
8083

84+
/**
85+
* Tests setLocale() with parameter
86+
*
87+
* @param string|null $localeParam
88+
* @param string|null $localeRequestParam
89+
* @param string $localeExpected
90+
* @dataProvider setLocaleWithParameterDataProvider
91+
*/
92+
public function testSetLocaleWithParameter(
93+
?string $localeParam,
94+
?string $localeRequestParam,
95+
string $localeExpected
96+
) {
97+
$request = Bootstrap::getObjectManager()
98+
->get(\Magento\Framework\App\RequestInterface::class);
99+
$request->setPostValue(['locale' => $localeRequestParam]);
100+
$this->_model->setLocale($localeParam);
101+
$this->assertEquals($localeExpected, $this->_model->getLocale());
102+
}
103+
104+
/**
105+
* @return array
106+
*/
107+
public function setLocaleWithParameterDataProvider(): array
108+
{
109+
return [
110+
['ko_KR', 'ja_JP', 'ja_JP'],
111+
['ko_KR', null, 'ko_KR'],
112+
[null, 'ja_JP', 'ja_JP'],
113+
];
114+
}
115+
81116
/**
82117
* Check set locale
83118
*
84119
* @param string $localeCodeToCheck
85120
* @return void
86121
*/
87-
protected function _checkSetLocale($localeCodeToCheck)
122+
private function _checkSetLocale($localeCodeToCheck)
88123
{
89124
$this->_model->setLocale();
90125
$localeCode = $this->_model->getLocale();

0 commit comments

Comments
 (0)