Skip to content

Commit 29411fe

Browse files
committed
Fix #12256 #13263 - add unit tests
1 parent 1e6a299 commit 29411fe

File tree

2 files changed

+87
-62
lines changed

2 files changed

+87
-62
lines changed

lib/internal/Magento/Framework/Locale/Test/Unit/TranslatedListsTest.php

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Locale\Test\Unit;
89

@@ -17,23 +18,62 @@ class TranslatedListsTest extends TestCase
1718
/**
1819
* @var TranslatedLists
1920
*/
20-
protected $listsModel;
21+
private $listsModel;
2122

2223
/**
23-
* @var MockObject | ConfigInterface
24+
* @var MockObject | ConfigInterface
2425
*/
25-
protected $mockConfig;
26+
private $mockConfig;
2627

2728
/**
28-
* @var MockObject | ResolverInterface
29+
* @var MockObject | ResolverInterface
2930
*/
30-
protected $mockLocaleResolver;
31+
private $mockLocaleResolver;
32+
33+
/**
34+
* @var array
35+
*/
36+
private $expectedCurrencies = [
37+
'USD',
38+
'EUR',
39+
'UAH',
40+
'GBP',
41+
];
42+
43+
/**
44+
* @var array
45+
*/
46+
private $expectedLocales = [
47+
'en_US' => 'English (United States)',
48+
'en_GB' => 'English (United Kingdom)',
49+
'uk_UA' => 'Ukrainian (Ukraine)',
50+
'de_DE' => 'German (Germany)',
51+
'sr_Cyrl_RS' => 'Serbian (Cyrillic, Serbia)',
52+
'sr_Latn_RS' => 'Serbian (Latin, Serbia)'
53+
];
54+
55+
/**
56+
* @var array
57+
*/
58+
private $expectedTranslatedLocales = [
59+
'en_US' => 'English (United States) / English (United States)',
60+
'en_GB' => 'English (United Kingdom) / English (United Kingdom)',
61+
'uk_UA' => 'українська (Україна) / Ukrainian (Ukraine)',
62+
'de_DE' => 'Deutsch (Deutschland) / German (Germany)',
63+
'sr_Cyrl_RS' => 'српски (ћирилица, Србија) / Serbian (Cyrillic, Serbia)',
64+
'sr_Latn_RS' => 'Srpski (latinica, Srbija) / Serbian (Latin, Serbia)'
65+
];
3166

3267
protected function setUp()
3368
{
3469
$this->mockConfig = $this->getMockBuilder(ConfigInterface::class)
3570
->disableOriginalConstructor()
3671
->getMock();
72+
$this->mockConfig->method('getAllowedLocales')
73+
->willReturn(array_keys($this->expectedLocales));
74+
$this->mockConfig->method('getAllowedCurrencies')
75+
->willReturn($this->expectedCurrencies);
76+
3777
$this->mockLocaleResolver = $this->getMockBuilder(ResolverInterface::class)
3878
->disableOriginalConstructor()
3979
->getMock();
@@ -69,12 +109,6 @@ public function testGetOptionAllCurrencies()
69109

70110
public function testGetOptionCurrencies()
71111
{
72-
$allowedCurrencies = ['USD', 'EUR', 'GBP', 'UAH'];
73-
74-
$this->mockConfig->expects($this->once())
75-
->method('getAllowedCurrencies')
76-
->willReturn($allowedCurrencies);
77-
78112
$expectedResults = ['USD', 'EUR', 'GBP', 'UAH'];
79113

80114
$currencyList = $this->listsModel->getOptionCurrencies();
@@ -134,44 +168,34 @@ public function testGetOptionTimezones()
134168

135169
public function testGetOptionLocales()
136170
{
137-
$this->setupForOptionLocales();
138-
139-
$expectedResults = ['en_US', 'uk_UA', 'de_DE'];
140-
141-
$list = $this->listsModel->getOptionLocales();
142-
foreach ($expectedResults as $value) {
143-
$found = false;
144-
foreach ($list as $item) {
145-
$found = $found || ($value == $item['value']);
146-
}
147-
$this->assertTrue($found);
148-
}
171+
$locales = array_intersect(
172+
$this->expectedLocales,
173+
$this->convertOptionLocales($this->listsModel->getOptionLocales())
174+
);
175+
$this->assertEquals($this->expectedLocales, $locales);
149176
}
150177

151178
public function testGetTranslatedOptionLocales()
152179
{
153-
$this->setupForOptionLocales();
154-
155-
$expectedResults = ['en_US', 'uk_UA', 'de_DE'];
156-
157-
$list = $this->listsModel->getOptionLocales();
158-
foreach ($expectedResults as $value) {
159-
$found = false;
160-
foreach ($list as $item) {
161-
$found = $found || ($value == $item['value']);
162-
}
163-
$this->assertTrue($found);
164-
}
180+
$locales = array_intersect(
181+
$this->expectedTranslatedLocales,
182+
$this->convertOptionLocales($this->listsModel->getTranslatedOptionLocales())
183+
);
184+
$this->assertEquals($this->expectedTranslatedLocales, $locales);
165185
}
166186

167187
/**
168-
* Setup for option locales
188+
* @param array $optionLocales
189+
* @return array
169190
*/
170-
protected function setupForOptionLocales()
191+
private function convertOptionLocales($optionLocales): array
171192
{
172-
$allowedLocales = ['en_US', 'uk_UA', 'de_DE'];
173-
$this->mockConfig->expects($this->once())
174-
->method('getAllowedLocales')
175-
->willReturn($allowedLocales);
193+
$result = [];
194+
195+
foreach ($optionLocales as $optionLocale) {
196+
$result[$optionLocale['value']] = $optionLocale['label'];
197+
}
198+
199+
return $result;
176200
}
177201
}

lib/internal/Magento/Framework/Setup/Test/Unit/ListsTest.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Setup\Test\Unit;
89

10+
use Magento\Framework\Locale\ConfigInterface;
911
use Magento\Framework\Setup\Lists;
12+
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\MockObject\MockObject;
1014

11-
class ListsTest extends \PHPUnit\Framework\TestCase
15+
class ListsTest extends TestCase
1216
{
1317
/**
1418
* @var Lists
1519
*/
16-
protected $lists;
20+
private $lists;
1721

1822
/**
19-
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Locale\ConfigInterface
23+
* @var MockObject|ConfigInterface
2024
*/
21-
protected $mockConfig;
25+
private $mockConfig;
2226

2327
/**
2428
* @var array
2529
*/
26-
protected $expectedTimezones = [
30+
private $expectedTimezones = [
2731
'Australia/Darwin',
2832
'America/Los_Angeles',
2933
'Europe/Kiev',
@@ -33,7 +37,7 @@ class ListsTest extends \PHPUnit\Framework\TestCase
3337
/**
3438
* @var array
3539
*/
36-
protected $expectedCurrencies = [
40+
private $expectedCurrencies = [
3741
'USD',
3842
'EUR',
3943
'UAH',
@@ -43,23 +47,23 @@ class ListsTest extends \PHPUnit\Framework\TestCase
4347
/**
4448
* @var array
4549
*/
46-
protected $expectedLocales = [
47-
'en_US',
48-
'en_GB',
49-
'uk_UA',
50-
'de_DE',
50+
private $expectedLocales = [
51+
'en_US' => 'English (United States)',
52+
'en_GB' => 'English (United Kingdom)',
53+
'uk_UA' => 'Ukrainian (Ukraine)',
54+
'de_DE' => 'German (Germany)',
55+
'sr_Cyrl_RS' => 'Serbian (Cyrillic, Serbia)',
56+
'sr_Latn_RS' => 'Serbian (Latin, Serbia)'
5157
];
5258

5359
protected function setUp()
5460
{
55-
$this->mockConfig = $this->getMockBuilder(\Magento\Framework\Locale\ConfigInterface::class)
61+
$this->mockConfig = $this->getMockBuilder(ConfigInterface::class)
5662
->disableOriginalConstructor()
5763
->getMock();
58-
$this->mockConfig->expects($this->any())
59-
->method('getAllowedLocales')
60-
->willReturn($this->expectedLocales);
61-
$this->mockConfig->expects($this->any())
62-
->method('getAllowedCurrencies')
64+
$this->mockConfig->method('getAllowedLocales')
65+
->willReturn(array_keys($this->expectedLocales));
66+
$this->mockConfig->method('getAllowedCurrencies')
6367
->willReturn($this->expectedCurrencies);
6468

6569
$this->lists = new Lists($this->mockConfig);
@@ -73,13 +77,10 @@ public function testGetTimezoneList()
7377

7478
public function testGetLocaleList()
7579
{
76-
$locales = array_intersect($this->expectedLocales, array_keys($this->lists->getLocaleList()));
80+
$locales = array_intersect($this->expectedLocales, $this->lists->getLocaleList());
7781
$this->assertEquals($this->expectedLocales, $locales);
7882
}
7983

80-
/**
81-
* Test Lists:getCurrencyList() considering allowed currencies config values.
82-
*/
8384
public function testGetCurrencyList()
8485
{
8586
$currencies = array_intersect($this->expectedCurrencies, array_keys($this->lists->getCurrencyList()));

0 commit comments

Comments
 (0)