summaryrefslogtreecommitdiff
path: root/tests/units/Model/LanguageTest.php
blob: 4330c3c8a5989d83f9865958691bb6035ea3b811 (plain)
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
<?php

use Kanboard\Model\LanguageModel;

require_once __DIR__.'/../Base.php';

class LanguageTest extends Base
{
    public function testGetCodes()
    {
        $codes = LanguageModel::getCodes();
        $this->assertContains('fr_FR', $codes);
        $this->assertContains('en_US', $codes);
    }

    public function testFindCode()
    {
        $this->assertSame('', LanguageModel::findCode('xx-XX'));
        $this->assertSame('fr_FR', LanguageModel::findCode('fr-FR'));
        $this->assertSame('en_US', LanguageModel::findCode('en-US'));
    }

    public function testGetJsLanguage()
    {
        $languageModel = new LanguageModel($this->container);
        $this->assertEquals('en', $languageModel->getJsLanguageCode());

        $this->container['sessionStorage']->user = array('language' => 'fr_FR');
        $this->assertEquals('fr', $languageModel->getJsLanguageCode());

        $this->container['sessionStorage']->user = array('language' => 'xx_XX');
        $this->assertEquals('en', $languageModel->getJsLanguageCode());
    }

    public function testGetCurrentLanguage()
    {
        $languageModel = new LanguageModel($this->container);
        $this->assertEquals('en_US', $languageModel->getCurrentLanguage());

        $this->container['sessionStorage']->user = array('language' => 'fr_FR');
        $this->assertEquals('fr_FR', $languageModel->getCurrentLanguage());

        $this->container['sessionStorage']->user = array('language' => 'xx_XX');
        $this->assertEquals('xx_XX', $languageModel->getCurrentLanguage());
    }

    public function testGetLanguages()
    {
        $languageModel = new LanguageModel($this->container);
        $this->assertNotEmpty($languageModel->getLanguages());
        $this->assertArrayHasKey('fr_FR', $languageModel->getLanguages());
        $this->assertContains('Français', $languageModel->getLanguages());
        $this->assertArrayNotHasKey('', $languageModel->getLanguages());

        $this->assertArrayHasKey('', $languageModel->getLanguages(true));
        $this->assertContains('Application default', $languageModel->getLanguages(true));
    }
}