ConfigTest.php 8.1 KB

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