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