3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magento \Framework \Locale \Test \Unit ;
8
9
@@ -17,23 +18,62 @@ class TranslatedListsTest extends TestCase
17
18
/**
18
19
* @var TranslatedLists
19
20
*/
20
- protected $ listsModel ;
21
+ private $ listsModel ;
21
22
22
23
/**
23
- * @var MockObject | ConfigInterface
24
+ * @var MockObject | ConfigInterface
24
25
*/
25
- protected $ mockConfig ;
26
+ private $ mockConfig ;
26
27
27
28
/**
28
- * @var MockObject | ResolverInterface
29
+ * @var MockObject | ResolverInterface
29
30
*/
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
+ ];
31
66
32
67
protected function setUp ()
33
68
{
34
69
$ this ->mockConfig = $ this ->getMockBuilder (ConfigInterface::class)
35
70
->disableOriginalConstructor ()
36
71
->getMock ();
72
+ $ this ->mockConfig ->method ('getAllowedLocales ' )
73
+ ->willReturn (array_keys ($ this ->expectedLocales ));
74
+ $ this ->mockConfig ->method ('getAllowedCurrencies ' )
75
+ ->willReturn ($ this ->expectedCurrencies );
76
+
37
77
$ this ->mockLocaleResolver = $ this ->getMockBuilder (ResolverInterface::class)
38
78
->disableOriginalConstructor ()
39
79
->getMock ();
@@ -69,12 +109,6 @@ public function testGetOptionAllCurrencies()
69
109
70
110
public function testGetOptionCurrencies ()
71
111
{
72
- $ allowedCurrencies = ['USD ' , 'EUR ' , 'GBP ' , 'UAH ' ];
73
-
74
- $ this ->mockConfig ->expects ($ this ->once ())
75
- ->method ('getAllowedCurrencies ' )
76
- ->willReturn ($ allowedCurrencies );
77
-
78
112
$ expectedResults = ['USD ' , 'EUR ' , 'GBP ' , 'UAH ' ];
79
113
80
114
$ currencyList = $ this ->listsModel ->getOptionCurrencies ();
@@ -134,44 +168,34 @@ public function testGetOptionTimezones()
134
168
135
169
public function testGetOptionLocales ()
136
170
{
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 );
149
176
}
150
177
151
178
public function testGetTranslatedOptionLocales ()
152
179
{
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 );
165
185
}
166
186
167
187
/**
168
- * Setup for option locales
188
+ * @param array $optionLocales
189
+ * @return array
169
190
*/
170
- protected function setupForOptionLocales ()
191
+ private function convertOptionLocales ( $ optionLocales ): array
171
192
{
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 ;
176
200
}
177
201
}
0 commit comments