]> BookStack Code Mirror - bookstack/blob - tests/LanguageTest.php
Fix Crowdin name in the language_request issue template
[bookstack] / tests / LanguageTest.php
1 <?php
2
3 namespace Tests;
4
5 class LanguageTest extends TestCase
6 {
7     protected $langs;
8
9     /**
10      * LanguageTest constructor.
11      */
12     protected function setUp(): void
13     {
14         parent::setUp();
15         $this->langs = array_diff(scandir(resource_path('lang')), ['..', '.']);
16     }
17
18     public function test_locales_config_key_set_properly()
19     {
20         $configLocales = config('app.locales');
21         sort($configLocales);
22         sort($this->langs);
23         $this->assertEquals(implode(':', $configLocales), implode(':', $this->langs), 'app.locales configuration variable does not match those found in lang files');
24     }
25
26     // Not part of standard phpunit test runs since we sometimes expect non-added langs.
27     public function do_test_locales_all_have_language_dropdown_entry()
28     {
29         $dropdownLocales = array_keys(trans('settings.language_select', [], 'en'));
30         sort($dropdownLocales);
31         sort($this->langs);
32         $diffs = array_diff($this->langs, $dropdownLocales);
33         if (count($diffs) > 0) {
34             $diffText = implode(',', $diffs);
35             $this->addWarning("Languages: {$diffText} found in files but not in language select dropdown.");
36         }
37         $this->assertTrue(true);
38     }
39
40     public function test_correct_language_if_not_logged_in()
41     {
42         $loginReq = $this->get('/login');
43         $loginReq->assertSee('Log In');
44
45         $loginPageFrenchReq = $this->get('/login', ['Accept-Language' => 'fr']);
46         $loginPageFrenchReq->assertSee('Se Connecter');
47     }
48
49     public function test_public_lang_autodetect_can_be_disabled()
50     {
51         config()->set('app.auto_detect_locale', false);
52         $loginReq = $this->get('/login');
53         $loginReq->assertSee('Log In');
54
55         $loginPageFrenchReq = $this->get('/login', ['Accept-Language' => 'fr']);
56         $loginPageFrenchReq->assertDontSee('Se Connecter');
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
66                 try {
67                     $translations = trans(str_replace('.php', '', $file), [], $lang);
68                 } catch (\Exception $e) {
69                     $loadError = true;
70                 }
71                 $this->assertFalse($loadError, "Translation file {$lang}/{$file} failed to load");
72             }
73         }
74     }
75
76     public function test_rtl_config_set_if_lang_is_rtl()
77     {
78         $this->asEditor();
79         $this->assertFalse(config('app.rtl'), 'App RTL config should be false by default');
80         setting()->putUser($this->getEditor(), 'language', 'ar');
81         $this->get('/');
82         $this->assertTrue(config('app.rtl'), 'App RTL config should have been set to true by middleware');
83     }
84 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.