Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigTest.php
Go to the documentation of this file.
1 <?php
8 
9 class ConfigTest extends \PHPUnit\Framework\TestCase
10 {
11  private static $allAllowedLocales = [
12  'af_ZA', 'ar_DZ', 'ar_EG', 'ar_KW', 'ar_MA', 'ar_SA', 'az_Latn_AZ', 'be_BY', 'bg_BG', 'bn_BD',
13  'bs_Latn_BA', 'ca_ES', 'cs_CZ', 'cy_GB', 'da_DK', 'de_AT', 'de_CH', 'de_DE', 'el_GR', 'en_AU',
14  'en_CA', 'en_GB', 'en_NZ', 'en_US', 'es_AR', 'es_CO', 'es_PA', 'gl_ES', 'es_CR', 'es_ES',
15  'es_MX', 'eu_ES', 'es_PE', 'et_EE', 'fa_IR', 'fi_FI', 'fil_PH', 'fr_CA', 'fr_FR', 'gu_IN',
16  'he_IL', 'hi_IN', 'hr_HR', 'hu_HU', 'id_ID', 'is_IS', 'it_CH', 'it_IT', 'ja_JP', 'ka_GE',
17  'km_KH', 'ko_KR', 'lo_LA', 'lt_LT', 'lv_LV', 'mk_MK', 'mn_Cyrl_MN', 'ms_Latn_MY', 'nl_NL', 'nb_NO',
18  'nn_NO', 'pl_PL', 'pt_BR', 'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sq_AL', 'sr_Cyrl_RS',
19  'sv_SE', 'sw_KE', 'th_TH', 'tr_TR', 'uk_UA', 'vi_VN', 'zh_Hans_CN', 'zh_Hant_HK', 'zh_Hant_TW', 'es_CL',
20  'lo_LA', 'es_VE', 'en_IE',
21  ];
22 
23  private static $allAllowedCurrencies = [
24  'AFN', 'ALL', 'AZN', 'DZD', 'AOA', 'ARS', 'AMD', 'AWG', 'AUD', 'BSD',
25  'BHD', 'BDT', 'BBD', 'BYR', 'BZD', 'BMD', 'BTN', 'BOB', 'BAM', 'BWP',
26  'BRL', 'GBP', 'BND', 'BGN', 'BUK', 'BIF', 'KHR', 'CAD', 'CVE', 'CZK',
27  'KYD', 'GQE', 'CLP', 'CNY', 'COP', 'KMF', 'CDF', 'CRC', 'HRK', 'CUP',
28  'DKK', 'DJF', 'DOP', 'XCD', 'EGP', 'SVC', 'ERN', 'EEK', 'ETB', 'EUR',
29  'FKP', 'FJD', 'GMD', 'GEK', 'GEL', 'GHS', 'GIP', 'GTQ', 'GNF', 'GYD',
30  'HTG', 'HNL', 'HKD', 'HUF', 'ISK', 'INR', 'IDR', 'IRR', 'IQD', 'ILS',
31  'JMD', 'JPY', 'JOD', 'KZT', 'KES', 'KWD', 'KGS', 'LAK', 'LVL', 'LBP',
32  'LSL', 'LRD', 'LYD', 'LTL', 'MOP', 'MKD', 'MGA', 'MWK', 'MYR', 'MVR',
33  'LSM', 'MRO', 'MUR', 'MXN', 'MDL', 'MNT', 'MAD', 'MZN', 'MMK', 'NAD',
34  'NPR', 'ANG', 'YTL', 'NZD', 'NIC', 'NGN', 'KPW', 'NOK', 'OMR', 'PKR',
35  'PAB', 'PGK', 'PYG', 'PEN', 'PHP', 'PLN', 'QAR', 'RHD', 'RON', 'RUB',
36  'RWF', 'SHP', 'STD', 'SAR', 'RSD', 'SCR', 'SLL', 'SGD', 'SKK', 'SBD',
37  'SOS', 'ZAR', 'KRW', 'LKR', 'SDG', 'SRD', 'SZL', 'SEK', 'CHF', 'SYP',
38  'TWD', 'TJS', 'TZS', 'THB', 'TOP', 'TTD', 'TND', 'TMM', 'USD', 'UGX',
39  'UAH', 'AED', 'UYU', 'UZS', 'VUV', 'VEB', 'VEF', 'VND', 'CHE', 'CHW',
40  'XOF', 'WST', 'YER', 'ZMK', 'ZWD', 'TRY', 'AZM', 'ROL', 'TRL', 'XPF',
41  ];
42 
43  private static $samplePresentLocales = [
44  'en_US', 'lv_LV', 'pt_BR', 'it_IT', 'ar_EG', 'bg_BG', 'en_IE', 'es_ES',
45  'en_AU', 'pt_PT', 'ru_RU', 'en_CA', 'vi_VN', 'ja_JP', 'en_GB', 'zh_CN',
46  'zh_TW', 'fr_FR', 'ar_KW', 'pl_PL', 'ko_KR', 'sk_SK', 'el_GR', 'hi_IN',
47  ];
48 
49  private static $sampleAbsentLocales = [
50  'aa_BB', 'foo_BAR', 'cc_DD',
51  ];
52 
53  private static $sampleAdditionalLocales = [
54  'en_AA', 'es_ZZ',
55  ];
56 
57  private static $samplePresentCurrencies = [
58  'AUD', 'BBD', 'GBP', 'CAD', 'CZK', 'GQE', 'CNY', 'DJF', 'HKD', 'JPY', 'MYR',
59  'MXN', 'NZD', 'PHP', 'SGD', 'CHF', 'TWD', 'USD', 'AED', 'ZWD', 'ROL', 'CHE',
60  ];
61 
62  private static $sampleAbsentCurrencies = [
63  'ABC', 'DEF', 'GHI', 'ZZZ',
64  ];
65 
66  private static $sampleAdditionalCurrencies = [
67  'QED', 'PNP', 'EJN', 'MTO', 'EBY',
68  ];
69 
71  private $configObject;
72 
74  {
75  $this->configObject = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
76  ->getObject(\Magento\Framework\Locale\Config::class);
77 
78  $retrievedLocales = $this->configObject->getAllowedLocales();
79 
80  $differences = array_diff($this::$allAllowedLocales, $retrievedLocales);
81 
82  $this->assertEmpty($differences);
83 
84  foreach ($this::$sampleAbsentLocales as $absentLocale) {
85  $this->assertNotContains($absentLocale, $retrievedLocales);
86  }
87  }
88 
90  {
91  $this->configObject = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
92  ->getObject(
93  \Magento\Framework\Locale\Config::class,
94  [
95  'data' => [
96  'allowedLocales' => $this::$sampleAdditionalLocales,
97  ],
98  ]
99  );
100 
101  $retrievedLocalesWithAdditions = $this->configObject->getAllowedLocales();
102 
103  $differences = array_diff(
104  array_unique(array_merge($this::$allAllowedLocales, $this::$sampleAdditionalLocales)),
105  $retrievedLocalesWithAdditions
106  );
107 
108  $this->assertEmpty($differences);
109 
110  foreach ($this::$sampleAbsentLocales as $absentLocale) {
111  $this->assertNotContains($absentLocale, $retrievedLocalesWithAdditions);
112  }
113  }
114 
116  {
117  $this->configObject = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
118  ->getObject(
119  \Magento\Framework\Locale\Config::class,
120  [
121  'data' => [
122  'allowedLocales' => $this::$samplePresentLocales,
123  ],
124  ]
125  );
126 
127  $retrievedLocalesWithRedundencies = $this->configObject->getAllowedLocales();
128 
129  $differences = array_diff(
130  $this::$allAllowedLocales,
131  $retrievedLocalesWithRedundencies
132  );
133 
134  $this->assertEmpty($differences);
135 
136  foreach ($this::$sampleAbsentLocales as $absentLocale) {
137  $this->assertNotContains($absentLocale, $retrievedLocalesWithRedundencies);
138  }
139  }
140 
142  {
143  $this->configObject = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
144  ->getObject(\Magento\Framework\Locale\Config::class);
145 
146  $retrievedCurrencies = $this->configObject->getAllowedCurrencies();
147 
148  $differences = array_diff($this::$allAllowedCurrencies, $retrievedCurrencies);
149 
150  $this->assertEmpty($differences);
151 
152  foreach ($this::$sampleAbsentCurrencies as $absentCurrency) {
153  $this->assertNotContains($absentCurrency, $retrievedCurrencies);
154  }
155  }
156 
158  {
159  $this->configObject = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
160  ->getObject(
161  \Magento\Framework\Locale\Config::class,
162  [
163  'data' => [
164  'allowedCurrencies' => $this::$sampleAdditionalCurrencies,
165  ],
166  ]
167  );
168 
169  $retrievedCurrenciesWithAdditions = $this->configObject->getAllowedCurrencies();
170 
171  $differences = array_diff(
172  array_unique(array_merge($this::$allAllowedCurrencies, $this::$samplePresentCurrencies)),
173  $retrievedCurrenciesWithAdditions
174  );
175 
176  $this->assertEmpty($differences);
177 
178  foreach ($this::$sampleAbsentCurrencies as $absentCurrency) {
179  $this->assertNotContains($absentCurrency, $retrievedCurrenciesWithAdditions);
180  }
181  }
182 
184  {
185  $this->configObject = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
186  ->getObject(
187  \Magento\Framework\Locale\Config::class,
188  [
189  'data' => [
190  'allowedCurrencies' => $this::$samplePresentCurrencies,
191  ],
192  ]
193  );
194 
195  $retrievedCurrenciesWithRedundencies = $this->configObject->getAllowedCurrencies();
196 
197  $differences = array_diff(
198  $this::$allAllowedCurrencies,
199  $retrievedCurrenciesWithRedundencies
200  );
201 
202  $this->assertEmpty($differences);
203 
204  foreach ($this::$sampleAbsentCurrencies as $absentCurrency) {
205  $this->assertNotContains($absentCurrency, $retrievedCurrenciesWithRedundencies);
206  }
207  }
208 }