|
1
|
|
|
<?php |
|
2
|
|
|
namespace Yii\I18n\Tests; |
|
3
|
|
|
|
|
4
|
|
|
use Yii\I18n\Locale; |
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @group i18n |
|
9
|
|
|
*/ |
|
10
|
|
|
class LocaleTest extends Testcase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testInvalidConstructorShouldThrowException() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
15
|
|
|
new Locale('invalid-locale_zz-123'); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function testLanguageParsedCorrectly() |
|
19
|
|
|
{ |
|
20
|
|
|
$locale = new Locale('en'); |
|
21
|
|
|
$this->assertSame('en', $locale->getLanguage()); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testRegionParsedCorrectly() |
|
25
|
|
|
{ |
|
26
|
|
|
$locale = new Locale('fr-CA'); |
|
27
|
|
|
$this->assertSame('fr', $locale->getLanguage()); |
|
28
|
|
|
$this->assertSame('CA', $locale->getRegion()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testScriptParsedCorrectly() |
|
32
|
|
|
{ |
|
33
|
|
|
$locale = new Locale('zh-Hans'); |
|
34
|
|
|
$this->assertSame('zh', $locale->getLanguage()); |
|
35
|
|
|
$this->assertSame('Hans', $locale->getScript()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testVariantParsedCorrectly() |
|
39
|
|
|
{ |
|
40
|
|
|
$locale = new Locale('de-DE-1901'); |
|
41
|
|
|
$this->assertSame('de', $locale->getLanguage()); |
|
42
|
|
|
$this->assertSame('DE', $locale->getRegion()); |
|
43
|
|
|
$this->assertSame('1901', $locale->getVariant()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testPrivateParsedCorrectly() |
|
47
|
|
|
{ |
|
48
|
|
|
$locale = new Locale('x-fr-CH'); |
|
49
|
|
|
$this->assertSame('fr-CH', $locale->getPrivate()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testAsString() |
|
53
|
|
|
{ |
|
54
|
|
|
$localeString = 'en-GB-boont-r-extended-sequence-x-private'; |
|
55
|
|
|
$locale = new Locale($localeString); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertSame($localeString, $locale->asString()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testWithLanguage() |
|
61
|
|
|
{ |
|
62
|
|
|
$locale = new Locale('ru-RU'); |
|
63
|
|
|
$newLocale = $locale->withLanguage('en'); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertSame('ru', $locale->getLanguage()); |
|
66
|
|
|
$this->assertSame('en', $newLocale->getLanguage()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testWithPrivate() |
|
70
|
|
|
{ |
|
71
|
|
|
$locale = new Locale('en-GB-boont-x-private'); |
|
72
|
|
|
$newLocale = $locale->withPrivate('newprivate'); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertSame('private', $locale->getPrivate()); |
|
75
|
|
|
$this->assertSame('newprivate', $newLocale->getPrivate()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testFallback() |
|
79
|
|
|
{ |
|
80
|
|
|
$locale = new Locale('en-GB-boont-x-private'); |
|
81
|
|
|
$fallbackLocale = $locale->getFallbackLocale(); |
|
82
|
|
|
$this->assertSame('en-GB', $fallbackLocale->asString()); |
|
83
|
|
|
|
|
84
|
|
|
$fallbackLocale = $fallbackLocale->getFallbackLocale(); |
|
85
|
|
|
$this->assertSame('en', $fallbackLocale->asString()); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|