|
4 | 4 | use Astrotomic\Translatable\Test\Model\Person; |
5 | 5 | use Astrotomic\Translatable\Test\Model\Country; |
6 | 6 | use Astrotomic\Translatable\Test\Model\CountryStrict; |
| 7 | +use Astrotomic\Translatable\Test\Model\CountryTranslation; |
7 | 8 | use Astrotomic\Translatable\Test\Model\CountryWithCustomLocaleKey; |
8 | 9 | use Astrotomic\Translatable\Test\Model\CountryWithCustomTranslationModel; |
9 | 10 |
|
@@ -785,4 +786,36 @@ protected function isEmptyTranslatableAttribute(string $key, $value): bool |
785 | 786 | $this->app->setLocale('fr'); |
786 | 787 | $this->assertSame('1', $city->name); |
787 | 788 | } |
| 789 | + |
| 790 | + public function test_translation_relation() |
| 791 | + { |
| 792 | + $this->app->make('config')->set('translatable.fallback_locale', 'fr'); |
| 793 | + $this->app->make('config')->set('translatable.use_fallback', true); |
| 794 | + $this->app->setLocale('en'); |
| 795 | + |
| 796 | + $translation = Country::find(1)->translation; |
| 797 | + $this->assertInstanceOf(CountryTranslation::class, $translation); |
| 798 | + $this->assertEquals('en', $translation->locale); |
| 799 | + } |
| 800 | + |
| 801 | + public function test_translation_relation_fallback() |
| 802 | + { |
| 803 | + $this->app->make('config')->set('translatable.fallback_locale', 'fr'); |
| 804 | + $this->app->make('config')->set('translatable.use_fallback', true); |
| 805 | + $this->app->setLocale('xyz'); |
| 806 | + |
| 807 | + $translation = Country::find(1)->translation; |
| 808 | + $this->assertInstanceOf(CountryTranslation::class, $translation); |
| 809 | + $this->assertEquals('fr', $translation->locale); |
| 810 | + } |
| 811 | + |
| 812 | + public function test_translation_relation_not_found() |
| 813 | + { |
| 814 | + $this->app->make('config')->set('translatable.fallback_locale', 'xyz'); |
| 815 | + $this->app->make('config')->set('translatable.use_fallback', true); |
| 816 | + $this->app->setLocale('xyz'); |
| 817 | + |
| 818 | + $translation = Country::find(1)->translation; |
| 819 | + $this->assertNull($translation); |
| 820 | + } |
788 | 821 | } |
0 commit comments