]> BookStack Code Mirror - bookstack/blob - tests/LanguageTest.php
Updated Spanish translation
[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']);
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_js_endpoint_for_each_language()
35     {
36
37         $visibleKeys = ['common', 'components', 'entities', 'errors'];
38
39         $this->asEditor();
40         foreach ($this->langs as $lang) {
41             setting()->putUser($this->getEditor(), 'language', $lang);
42             $transResp = $this->get('/translations');
43             foreach ($visibleKeys as $key) {
44                 $transResp->assertSee($key);
45             }
46         }
47     }
48
49     public function test_all_lang_files_loadable()
50     {
51         $files = array_diff(scandir(resource_path('lang/en')), ['..', '.']);
52         foreach ($this->langs as $lang) {
53             foreach ($files as $file) {
54                 $loadError = false;
55                 try {
56                     $translations = trans(str_replace('.php', '', $file), [], $lang);
57                 } catch (\Exception $e) {
58                     $loadError = true;
59                 }
60                 $this->assertFalse($loadError, "Translation file {$lang}/{$file} failed to load");
61             }
62         }
63     }
64
65 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.