PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / vendor / vendor-prefixed / stellarwp / validation / tests / unit / Rules / CurrencyTest.php

CurrencyTest.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at vendor/vendor-prefixed/stellarwp/validation/tests/unit/Rules/CurrencyTest.php

245 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Give\Vendors\StellarWP\Validation\Tests\Unit\Rules;
6
7 use Give\Vendors\StellarWP\Validation\Rules\Currency;
8 use Give\Vendors\StellarWP\Validation\Tests\TestCase;
9
10 class CurrencyTest extends TestCase
11 {
12 /**
13 * @since 1.1.0
14 * @dataProvider currencyProvider
15 */
16 public function testCurrencyValidations($currency, $shouldPass)
17 {
18 $rule = new Currency();
19
20 if ($shouldPass) {
21 self::assertValidationRulePassed($rule, $currency);
22 } else {
23 self::assertValidationRuleFailed($rule, $currency);
24 }
25 }
26
27
28
29 /**
30 * Test that obsolete currency codes no longer pass validation.
31 *
32 * @unreleased
33 * @dataProvider obsoleteCurrencyProvider
34 */
35 public function testObsoleteCurrencyCodesFail($currency)
36 {
37 $rule = new Currency();
38 self::assertValidationRuleFailed($rule, $currency);
39 }
40
41 /**
42 * Test newly added currency codes pass validation.
43 *
44 * @unreleased
45 * @dataProvider newCurrencyProvider
46 */
47 public function testNewCurrencyCodesPass($currency)
48 {
49 $rule = new Currency();
50 self::assertValidationRulePassed($rule, $currency);
51 }
52
53 /**
54 * Test case insensitivity with various currency codes.
55 *
56 * @unreleased
57 * @dataProvider caseInsensitiveProvider
58 */
59 public function testCaseInsensitivity($currency, $shouldPass)
60 {
61 $rule = new Currency();
62
63 if ($shouldPass) {
64 self::assertValidationRulePassed($rule, $currency);
65 } else {
66 self::assertValidationRuleFailed($rule, $currency);
67 }
68 }
69
70 /**
71 * @unreleased
72 */
73 public function currencyProvider(): array
74 {
75 return [
76 // Common major currencies
77 ['USD', true],
78 ['EUR', true],
79 ['JPY', true],
80 ['GBP', true],
81 ['CAD', true],
82 ['AUD', true],
83 ['CHF', true],
84
85 // Case insensitive
86 ['usd', true],
87 ['eur', true],
88 ['jpy', true],
89 ['EuR', true],
90 ['CaD', true],
91
92 // Newly added currencies (2024 update)
93 ['AED', true], // UAE Dirham
94 ['BHD', true], // Bahraini Dinar
95 ['KWD', true], // Kuwaiti Dinar
96 ['QAR', true], // Qatari Riyal
97 ['SAR', true], // Saudi Riyal
98 ['VES', true], // Venezuelan Bolívar Soberano (new)
99 ['BYN', true], // Belarusian Ruble (new)
100 ['GHS', true], // Ghanaian Cedi (new)
101
102 // Regional currencies
103 ['XAF', true], // Central African CFA Franc
104 ['XOF', true], // West African CFA Franc
105 ['XCD', true], // East Caribbean Dollar
106 ['XPF', true], // CFP Franc
107
108 // Special codes
109 ['XDR', true], // Special Drawing Rights
110
111 // Non-ISO but commonly used (kept in list)
112 ['GGP', true], // Guernsey Pound
113 ['IMP', true], // Isle of Man Pound
114 ['JEP', true], // Jersey Pound
115 ['TVD', true], // Tuvaluan Dollar
116
117 // Invalid codes
118 ['US', false], // Too short
119 ['USDD', false], // Too long
120 ['US D', false], // Contains space
121 ['US-D', false], // Contains hyphen
122 ['ABC', false], // Not a valid currency
123 ['123', false], // Numeric
124 ['', false], // Empty string
125 ['XXX', false], // Invalid code
126 ['ZZZ', false], // Non-existent
127 ];
128 }
129
130 /**
131 * Currency codes that were removed in the 2024 update.
132 *
133 * @unreleased
134 */
135 public function obsoleteCurrencyProvider(): array
136 {
137 return [
138 ['BYR'], // Old Belarusian Ruble (replaced by BYN)
139 ['EEK'], // Estonian Kroon (replaced by EUR)
140 ['GHC'], // Old Ghanaian Cedi (replaced by GHS)
141 ['LVL'], // Latvian Lats (replaced by EUR)
142 ['LTL'], // Lithuanian Litas (replaced by EUR)
143 ['TRL'], // Old Turkish Lira (now only TRY)
144 ['VEF'], // Old Venezuelan Bolívar (replaced by VES)
145 ['ZWD'], // Old Zimbabwean Dollar (replaced by ZWL)
146 ];
147 }
148
149 /**
150 * New currency codes added in the 2024 update.
151 *
152 * @unreleased
153 */
154 public function newCurrencyProvider(): array
155 {
156 return [
157 ['AED'], // UAE Dirham
158 ['AMD'], // Armenian Dram
159 ['AOA'], // Angolan Kwanza
160 ['BHD'], // Bahraini Dinar
161 ['BIF'], // Burundian Franc
162 ['BND'], // Brunei Dollar
163 ['BTN'], // Bhutanese Ngultrum
164 ['BYN'], // Belarusian Ruble (new)
165 ['CDF'], // Congolese Franc
166 ['CVE'], // Cape Verdean Escudo
167 ['DJF'], // Djiboutian Franc
168 ['DZD'], // Algerian Dinar
169 ['ERN'], // Eritrean Nakfa
170 ['ETB'], // Ethiopian Birr
171 ['GEL'], // Georgian Lari
172 ['GHS'], // Ghanaian Cedi (new)
173 ['GMD'], // Gambian Dalasi
174 ['GNF'], // Guinean Franc
175 ['HTG'], // Haitian Gourde
176 ['IQD'], // Iraqi Dinar
177 ['JOD'], // Jordanian Dinar
178 ['KES'], // Kenyan Shilling
179 ['KMF'], // Comorian Franc
180 ['KWD'], // Kuwaiti Dinar
181 ['LSL'], // Lesotho Loti
182 ['LYD'], // Libyan Dinar
183 ['MAD'], // Moroccan Dirham
184 ['MDL'], // Moldovan Leu
185 ['MGA'], // Malagasy Ariary
186 ['MMK'], // Myanmar Kyat
187 ['MOP'], // Macanese Pataca
188 ['MRU'], // Mauritanian Ouguiya
189 ['MVR'], // Maldivian Rufiyaa
190 ['MWK'], // Malawian Kwacha
191 ['PGK'], // Papua New Guinean Kina
192 ['RWF'], // Rwandan Franc
193 ['SDG'], // Sudanese Pound
194 ['SLE'], // Sierra Leonean Leone (new)
195 ['SSP'], // South Sudanese Pound
196 ['STN'], // São Tomé and Príncipe Dobra
197 ['SZL'], // Swazi Lilangeni
198 ['TJS'], // Tajikistani Somoni
199 ['TMT'], // Turkmenistani Manat
200 ['TND'], // Tunisian Dinar
201 ['TOP'], // Tongan Paʻanga
202 ['TZS'], // Tanzanian Shilling
203 ['UGX'], // Ugandan Shilling
204 ['VED'], // Venezuelan Bolívar Digital
205 ['VES'], // Venezuelan Bolívar Soberano
206 ['VUV'], // Vanuatuan Vatu
207 ['WST'], // Samoan Tala
208 ['XAF'], // Central African CFA Franc
209 ['XDR'], // Special Drawing Rights
210 ['XOF'], // West African CFA Franc
211 ['XPF'], // CFP Franc
212 ['ZMW'], // Zambian Kwacha
213 ['ZWL'], // Zimbabwean Dollar (new)
214 ];
215 }
216
217 /**
218 * Test various case combinations.
219 *
220 * @unreleased
221 */
222 public function caseInsensitiveProvider(): array
223 {
224 return [
225 ['USD', true],
226 ['usd', true],
227 ['Usd', true],
228 ['UsD', true],
229 ['EUR', true],
230 ['eur', true],
231 ['eUr', true],
232 ['EuR', true],
233 ['JPY', true],
234 ['jpy', true],
235 ['JpY', true],
236 ['jPy', true],
237 // Invalid codes in various cases
238 ['abc', false],
239 ['ABC', false],
240 ['AbC', false],
241 ['aBc', false],
242 ];
243 }
244 }
245