Skip to content

Commit 7ac8e72

Browse files
committed
Merge remote-tracking branch 'act4/ACP2E-4025' into PR_25_June_odubovyk
2 parents 03340a1 + 81210e7 commit 7ac8e72

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

app/code/Magento/Directory/Test/Unit/Model/CurrencyTest.php

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,15 @@ function (array $args) {
138138
*/
139139
public static function getOutputFormatDataProvider(): array
140140
{
141-
$ar_DZ = "\u{062C}.\u{0645}.\u{200F}\u{00A0}%s";
142-
if (version_compare(PHP_VERSION, '8.3', '>=')) {
143-
$ar_DZ = "%s\u{00A0}\u{062C}.\u{0645}.\u{200F}";
144-
}
141+
// Use dynamic detection for problematic locale/currency combinations!
142+
$ar_DZ_EGP = self::getExpectedFormatForLocale('ar_DZ', 'EGP');
143+
145144
return [
146145
'en_US:USD' => ['en_US', 'USD', '$%s'],
147146
'en_US:PLN' => ['en_US', 'PLN', "PLN\u{00A0}%s"],
148147
'en_US:PKR' => ['en_US', 'PKR', "PKR\u{00A0}%s"],
149148
'af_ZA:VND' => ['af_ZA', 'VND', "\u{20AB}%s"],
150-
'ar_DZ:EGP' => ['ar_DZ', 'EGP', $ar_DZ],
149+
'ar_DZ:EGP' => ['ar_DZ', 'EGP', $ar_DZ_EGP],
151150
'ar_SA:USD' => ['ar_SA', 'USD', "%s\u{00A0}US$"],
152151
'ar_SA:LBP' => ['ar_SA', 'LBP', "%s\u{00A0}\u{0644}.\u{0644}.\u{200F}"],
153152
'fa_IR:USD' => ['fa_IR', 'USD', "\u{200E}$%s"],
@@ -162,6 +161,62 @@ public static function getOutputFormatDataProvider(): array
162161
];
163162
}
164163

164+
/**
165+
* Get expected format for a specific locale/currency combination
166+
* This handles cases where intl extension version affects formatting
167+
*
168+
* @param string $locale
169+
* @param string $currency
170+
* @return string
171+
*/
172+
private static function getExpectedFormatForLocale(string $locale, string $currency): string
173+
{
174+
// Define known problematic combinations and their expected formats
175+
$problematicFormats = [
176+
'ar_DZ:EGP' => [
177+
'old' => "\u{062C}.\u{0645}.\u{200F}\u{00A0}%s",
178+
'new' => "%s\u{00A0}\u{062C}.\u{0645}.\u{200F}"
179+
]
180+
];
181+
182+
$key = $locale . ':' . $currency;
183+
184+
if (isset($problematicFormats[$key])) {
185+
// Check if we're using a newer intl version that changes formatting
186+
if (self::isNewerIntlVersion()) {
187+
return $problematicFormats[$key]['new'];
188+
}
189+
return $problematicFormats[$key]['old'];
190+
}
191+
192+
// For non-problematic combinations, return a default format
193+
// This could be enhanced with more specific formats as needed
194+
return "%s";
195+
}
196+
197+
/**
198+
* Check if the current intl extension version uses newer formatting rules
199+
*
200+
* @return bool
201+
*/
202+
private static function isNewerIntlVersion(): bool
203+
{
204+
// Check intl extension version
205+
if (extension_loaded('intl')) {
206+
$intlVersion = INTL_ICU_VERSION ?? '0.0.0';
207+
208+
// ICU 72+ (released around 2022) introduced changes to RTL formatting
209+
// This is a more reliable indicator than PHP version
210+
if (version_compare($intlVersion, '72.0', '>=')) {
211+
return true;
212+
}
213+
}
214+
215+
// Fallback: Check PHP version as a rough indicator
216+
// This is less reliable but provides some backward compatibility
217+
return version_compare(PHP_VERSION, '8.3', '>=');
218+
}
219+
165220
/**
166221
* @dataProvider getFormatTxtNumberFormatterDataProvider
167222
* @param string $locale

0 commit comments

Comments
 (0)