aboutsummaryrefslogtreecommitdiffstats
path: root/library/intl/tests/LocaleResolverTest.php
blob: a52dea353fb53cd5b64be78ed45eafadcabd8bca (plain) (blame)
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
<?php

namespace CommerceGuys\Intl\Tests;

use org\bovigo\vfs\vfsStream;

/**
 * @coversDefaultClass \CommerceGuys\Intl\LocaleResolverTrait
 */
class LocaleResolverTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var DummyRepository
     */
    protected $repository;

    public function setUp()
    {
        // Simulate the presence of various definitions.
        $root = vfsStream::setup('resources');
        vfsStream::newFile('dummy/bs-Cyrl.json')->at($root)->setContent('');
        vfsStream::newFile('dummy/bs.json')->at($root)->setContent('');
        vfsStream::newFile('dummy/en.json')->at($root)->setContent('');

        $this->repository = new DummyRepository();
    }

    /**
     * @covers ::resolveLocale
     * @covers ::getLocaleVariants
     */
    public function testLocaleFallback()
    {
        $locale = $this->repository->runResolveLocale('bs-Cyrl-BA');
        $this->assertEquals('bs-Cyrl', $locale);
        $locale = $this->repository->runResolveLocale('bs-Latn-BA');
        $this->assertEquals('bs', $locale);
        $locale = $this->repository->runResolveLocale('de', 'en');
        $this->assertEquals('en', $locale);
    }

    /**
     * @covers ::resolveLocale
     * @covers ::getLocaleVariants
     * @expectedException \CommerceGuys\Intl\Exception\UnknownLocaleException
     */
    public function testInvalidLocale()
    {
        $locale = $this->repository->runResolveLocale('de');
    }
}