|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests; |
| 4 | + |
| 5 | +use Illuminate\Support\Facades\Config; |
| 6 | + |
| 7 | +final class TranslationsTest extends TestCase |
| 8 | +{ |
| 9 | + public function testDefaultTranslation() |
| 10 | + { |
| 11 | + $this->setConfigLocale('en'); |
| 12 | + |
| 13 | + $response = $this->get('/routes'); |
| 14 | + |
| 15 | + $response->assertStatus(200); |
| 16 | + $response->assertSee('Routes'); |
| 17 | + $response->assertSee('Middlewares'); |
| 18 | + $response->assertSee('Loading... Please wait...'); |
| 19 | + $response->assertSee('Routes per page'); |
| 20 | + |
| 21 | + $response->assertDontSee('Foo Bar'); |
| 22 | + $response->assertDontSee('Записей на странице'); |
| 23 | + } |
| 24 | + |
| 25 | + public function testChangedAppLocaleTranslation() |
| 26 | + { |
| 27 | + $this->setConfigLocale('ru'); |
| 28 | + |
| 29 | + $response = $this->get('/routes'); |
| 30 | + |
| 31 | + $response->assertStatus(200); |
| 32 | + $response->assertSee('Маршруты'); |
| 33 | + $response->assertSee('Мидлвари'); |
| 34 | + $response->assertSee('Загрузка... Пожалуйста, подождите...'); |
| 35 | + $response->assertSee('Записей на странице'); |
| 36 | + |
| 37 | + $response->assertDontSee('Foo Bar'); |
| 38 | + $response->assertDontSee('Routes per page'); |
| 39 | + } |
| 40 | + |
| 41 | + public function testChangedPackageLocaleTranslation() |
| 42 | + { |
| 43 | + $this->setConfigLocale('en', 'ru'); |
| 44 | + |
| 45 | + $response = $this->get('/routes'); |
| 46 | + |
| 47 | + $response->assertStatus(200); |
| 48 | + $response->assertSee('Маршруты'); |
| 49 | + $response->assertSee('Мидлвари'); |
| 50 | + $response->assertSee('Загрузка... Пожалуйста, подождите...'); |
| 51 | + $response->assertSee('Записей на странице'); |
| 52 | + |
| 53 | + $response->assertDontSee('Foo Bar'); |
| 54 | + $response->assertDontSee('Routes per page'); |
| 55 | + } |
| 56 | + |
| 57 | + public function testIncorrectLocaleTranslation() |
| 58 | + { |
| 59 | + $this->setConfigLocale('en', 'foo'); |
| 60 | + |
| 61 | + $response = $this->get('/routes'); |
| 62 | + |
| 63 | + $response->assertStatus(200); |
| 64 | + $response->assertSee('Routes'); |
| 65 | + $response->assertSee('Middlewares'); |
| 66 | + $response->assertSee('Loading... Please wait...'); |
| 67 | + $response->assertSee('Routes per page'); |
| 68 | + |
| 69 | + $response->assertDontSee('Foo Bar'); |
| 70 | + $response->assertDontSee('Записей на странице'); |
| 71 | + } |
| 72 | + |
| 73 | + protected function setConfigLocale(string $app, string $package = null): void |
| 74 | + { |
| 75 | + Config::set('app.locale', $app); |
| 76 | + Config::set('pretty-routes.locale_force', $package ?: false); |
| 77 | + } |
| 78 | +} |
0 commit comments