LocaleTest::testWithPrivate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 2
b 0
f 0
1
<?php
2
namespace Yii\I18n\Tests;
3
4
use Yiisoft\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->language());
22
    }
23
24
    public function testRegionParsedCorrectly()
25
    {
26
        $locale = new Locale('fr-CA');
27
        $this->assertSame('fr', $locale->language());
28
        $this->assertSame('CA', $locale->region());
29
    }
30
31
    public function testScriptParsedCorrectly()
32
    {
33
        $locale = new Locale('zh-Hans');
34
        $this->assertSame('zh', $locale->language());
35
        $this->assertSame('Hans', $locale->script());
36
    }
37
38
    public function testVariantParsedCorrectly()
39
    {
40
        $locale = new Locale('de-DE-1901');
41
        $this->assertSame('de', $locale->language());
42
        $this->assertSame('DE', $locale->region());
43
        $this->assertSame('1901', $locale->variant());
44
    }
45
46
    public function testPrivateParsedCorrectly()
47
    {
48
        $locale = new Locale('x-fr-CH');
49
        $this->assertSame('fr-CH', $locale->private());
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->language());
66
        $this->assertSame('en', $newLocale->language());
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->private());
75
        $this->assertSame('newprivate', $newLocale->private());
76
    }
77
78
    public function testFallback()
79
    {
80
        $locale = new Locale('en-GB-boont-x-private');
81
82
        $fallbackLocale = $locale->fallbackLocale();
83
        $this->assertSame('en-GB', $fallbackLocale->asString());
84
85
        $fallbackLocale = $fallbackLocale->fallbackLocale();
86
        $this->assertSame('en', $fallbackLocale->asString());
87
    }
88
}
89