forked from php/web-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLangChooserTest.php
More file actions
130 lines (100 loc) · 4.41 KB
/
Copy pathLangChooserTest.php
File metadata and controls
130 lines (100 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
declare(strict_types=1);
namespace phpweb\Test\Unit;
use phpweb\LangChooser;
use PHPUnit\Framework;
#[Framework\Attributes\CoversClass(LangChooser::class)]
class LangChooserTest extends Framework\TestCase
{
private const DEFAULT_LANGUAGE_LIST = [
'en' => 'English',
'de' => 'German',
'ja' => 'Japanese',
'pt_BR' => 'Brazilian Portuguese',
'zh' => 'Chinese (Simplified)',
];
public function testChooseCodeWithLangParameter(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'en');
$result = $langChooser->chooseCode('de', '/', null);
self::assertSame(['de', 'de'], $result);
}
public function testChooseCodeWithShortcutPath(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'en');
$result = $langChooser->chooseCode('', '/de/echo', null);
self::assertSame(['de', 'de'], $result);
}
#[Framework\Attributes\TestWith(['de', 'de'])]
#[Framework\Attributes\TestWith(['pt_BR', 'pt_BR'])]
public function testChooseCodeWithManualPath(string $pathLang, string $expected): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'en');
$result = $langChooser->chooseCode('', "/manual/$pathLang", null);
self::assertSame([$expected, $expected], $result);
}
public function testChooseCodeWithUserPreference(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], 'de', 'en');
$result = $langChooser->chooseCode('', '/', null);
self::assertSame(['de', ''], $result);
}
public function testChooseCodeWithAcceptLanguage(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'en');
$result = $langChooser->chooseCode('', '/', 'de,ja,en');
self::assertSame(['de', ''], $result);
}
public function testChooseCodeWithAcceptLanguageQuality(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'en');
$result = $langChooser->chooseCode('', '/', 'de;q=0.8,ja,en');
self::assertSame(['ja', ''], $result);
}
#[Framework\Attributes\TestWith(['de-at', 'de'])]
#[Framework\Attributes\TestWith(['pt-br', 'pt_BR'])]
#[Framework\Attributes\TestWith(['zh-cn', 'zh'])]
#[Framework\Attributes\TestWith(['zh-tw', 'en'])]
public function testChooseCodeWithAcceptLanguageFollowedByCountryCode(string $acceptLanguage, string $expected): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'en');
$result = $langChooser->chooseCode('', '/', $acceptLanguage);
self::assertSame([$expected, ''], $result);
}
public function testChooseCodeWithMirrorDefaultLanguage(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'de');
$result = $langChooser->chooseCode('', '/', null);
self::assertSame(['de', ''], $result);
}
public function testChooseCodeWithDefaultLanguage(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'fr');
$result = $langChooser->chooseCode('', '/', null);
self::assertSame(['en', ''], $result);
}
public function testChooseCodeWithLangParameterAndManualPath(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'en');
$result = $langChooser->chooseCode('de', '/manual/en', null);
self::assertSame(['de', 'de'], $result);
}
public function testChooseCodeWithManualPathAndUserPreference(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], 'en', 'en');
$result = $langChooser->chooseCode('', '/manual/de', null);
self::assertSame(['de', 'de'], $result);
}
public function testChooseCodeWithManualPathAndAcceptLanguage(): void
{
$langChooser = new LangChooser(self::DEFAULT_LANGUAGE_LIST, [], '', 'en');
$result = $langChooser->chooseCode('', '/manual/de', 'en');
self::assertSame(['de', 'de'], $result);
}
public function testChooseCodeInactiveLanguageIsNotChosen(): void
{
$langChooser = new LangChooser(['en' => 'English', 'de' => 'German', 'pl' => 'Polish'], ['pl' => 'Polish'], '', '');
$result = $langChooser->chooseCode('pl', '/manual/pl', 'pl');
self::assertSame(['en', 'pl'], $result);
}
}