]> BookStack Code Mirror - bookstack/blob - tests/LanguageTest.php
Updated the Swedish language files
[bookstack] / tests / LanguageTest.php
1 <?php namespace Tests;
2
3 class LanguageTest extends TestCase
4 {
5
6     protected $langs;
7
8     /**
9      * LanguageTest constructor.
10      */
11     public function setUp()
12     {
13         parent::setUp();
14         $this->langs = array_diff(scandir(resource_path('lang')), ['..', '.', 'check.php', 'format.php']);
15     }
16
17     public function test_locales_config_key_set_properly()
18     {
19         $configLocales = config('app.locales');
20         sort($configLocales);
21         sort($this->langs);
22         $this->assertTrue(implode(':', $this->langs) === implode(':', $configLocales), 'app.locales configuration variable matches found lang files');
23     }
24
25     public function test_correct_language_if_not_logged_in()
26     {
27         $loginReq = $this->get('/login');
28         $loginReq->assertSee('Log In');
29
30         $loginPageFrenchReq = $this->get('/login', ['Accept-Language' => 'fr']);
31         $loginPageFrenchReq->assertSee('Se Connecter');
32     }
33
34     public function test_public_lang_autodetect_can_be_disabled()
35     {
36         config()->set('app.auto_detect_locale', false);
37         $loginReq = $this->get('/login');
38         $loginReq->assertSee('Log In');
39
40         $loginPageFrenchReq = $this->get('/login', ['Accept-Language' => 'fr']);
41         $loginPageFrenchReq->assertDontSee('Se Connecter');
42     }
43
44     public function test_js_endpoint_for_each_language()
45     {
46
47         $visibleKeys = ['common', 'components', 'entities', 'errors'];
48
49         $this->asEditor();
50         foreach ($this->langs as $lang) {
51             setting()->putUser($this->getEditor(), 'language', $lang);
52             $transResp = $this->get('/translations');
53             foreach ($visibleKeys as $key) {
54                 $transResp->assertSee($key);
55             }
56         }
57     }
58
59     public function test_all_lang_files_loadable()
60     {
61         $files = array_diff(scandir(resource_path('lang/en')), ['..', '.']);
62         foreach ($this->langs as $lang) {
63             foreach ($files as $file) {
64                 $loadError = false;
65                 try {
66                     $translations = trans(str_replace('.php', '', $file), [], $lang);
67                 } catch (\Exception $e) {
68                     $loadError = true;
69                 }
70                 $this->assertFalse($loadError, "Translation file {$lang}/{$file} failed to load");
71             }
72         }
73     }
74
75     public function test_rtl_config_set_if_lang_is_rtl()
76     {
77         $this->asEditor();
78         $this->assertFalse(config('app.rtl'), "App RTL config should be false by default");
79         setting()->putUser($this->getEditor(), 'language', 'ar');
80         $this->get('/');
81         $this->assertTrue(config('app.rtl'), "App RTL config should have been set to true by middleware");
82     }
83
84     public function test_de_informal_falls_base_to_de()
85     {
86         // Base de back value
87         $deBack = trans()->get('common.cancel', [], 'de', false);
88         $this->assertEquals('Abbrechen', $deBack);
89         // Ensure de_informal has no value set
90         $this->assertEquals('common.cancel', trans()->get('common.cancel', [], 'de_informal', false));
91         // Ensure standard trans falls back to de
92         $this->assertEquals($deBack, trans('common.cancel', [], 'de_informal'));
93         // Ensure de_informal gets its own values where set
94         $deEmailActionHelp = trans()->get('common.email_action_help', [], 'de', false);
95         $enEmailActionHelp = trans()->get('common.email_action_help', [], 'en', false);
96         $deInformalEmailActionHelp = trans()->get('common.email_action_help', [], 'de_informal', false);
97         $this->assertNotEquals($deEmailActionHelp, $deInformalEmailActionHelp);
98         $this->assertNotEquals($enEmailActionHelp, $deInformalEmailActionHelp);
99     }
100
101     public function test_de_informal_falls_base_to_de_in_js_endpoint()
102     {
103         $this->asEditor();
104         setting()->putUser($this->getEditor(), 'language', 'de_informal');
105
106         $transResp = $this->get('/translations');
107         $transResp->assertSee('"cancel":"Abbrechen"');
108     }
109
110 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.