You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/LocaleCodeTest.php

26 lines
688 B
PHTML

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Services\LocaleCode;
$cases = [
'EN_us' => 'en-US',
'pt-br' => 'pt-BR',
'zh-hant' => 'zh-Hant',
'sr-latn-rs' => 'sr-Latn-RS',
'es-419' => 'es-419',
];
foreach ($cases as $input => $expected) {
if (LocaleCode::canonicalize($input) !== $expected) {
throw new RuntimeException('Locale canonicalization failed: ' . $input);
}
}
foreach (['', 'e', 'en-', 'en/US', 'x-private'] as $invalid) {
if (LocaleCode::canonicalize($invalid) !== null) {
throw new RuntimeException('Invalid locale was accepted: ' . $invalid);
}
}
echo "Locale code canonicalization tests passed.\n";