xref: /web-php/tests/Unit/I18n/LanguagesTest.php (revision cdf59074)
1<?php
2
3declare(strict_types=1);
4
5namespace phpweb\Test\Unit\I18n;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\DataProvider;
9use PHPUnit\Framework\TestCase;
10use phpweb\I18n\Languages;
11
12use function array_diff;
13
14#[CoversClass(Languages::class)]
15final class LanguagesTest extends TestCase
16{
17    #[DataProvider('languageCodeProvider')]
18    public function testConvert(string $languageCode, string $expected): void
19    {
20        self::assertSame($expected, (new Languages())->convert($languageCode));
21    }
22
23    public static function languageCodeProvider(): iterable
24    {
25        yield ['en', 'en'];
26        yield ['de', 'de'];
27        yield ['es', 'es'];
28        yield ['fr', 'fr'];
29        yield ['it', 'it'];
30        yield ['ja', 'ja'];
31        yield ['pl', 'pl'];
32        yield ['pt_br', 'pt_BR'];
33        yield ['pt_BR', 'pt_BR'];
34        yield ['ro', 'ro'];
35        yield ['ru', 'ru'];
36        yield ['tr', 'tr'];
37        yield ['uk', 'uk'];
38        yield ['zh', 'zh'];
39        yield ['zh_cn', 'zh'];
40        yield ['zh_CN', 'zh'];
41        yield ['unknown', 'en'];
42        yield ['', 'en'];
43    }
44
45    public function testConstantsDifference(): void
46    {
47        self::assertSame(
48            array_diff(Languages::LANGUAGES, Languages::INACTIVE_ONLINE_LANGUAGES),
49            Languages::ACTIVE_ONLINE_LANGUAGES,
50        );
51    }
52
53    public function testLanguagesIncGlobalVariables(): void
54    {
55        global $LANGUAGES, $INACTIVE_ONLINE_LANGUAGES, $ACTIVE_ONLINE_LANGUAGES;
56
57        include __DIR__ . '/../../../include/languages.inc';
58
59        self::assertSame(Languages::LANGUAGES, $LANGUAGES);
60        self::assertSame(Languages::INACTIVE_ONLINE_LANGUAGES, $INACTIVE_ONLINE_LANGUAGES);
61        self::assertSame(Languages::ACTIVE_ONLINE_LANGUAGES, $ACTIVE_ONLINE_LANGUAGES);
62    }
63}
64