From 1a7defc4fb4cb574405f5b9d958ab503257208d8 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 12 Oct 2018 15:00:51 +0200 Subject: [PATCH 1/2] #526 - add unittest for customized translation model --- tests/TranslatableTest.php | 13 +++++++++++++ tests/models/CountryWithCustomLocaleKey.php | 1 - .../models/CountryWithCustomTranslationModel.php | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/models/CountryWithCustomTranslationModel.php diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index e16943d..46a32d8 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -5,6 +5,7 @@ use Dimsav\Translatable\Test\Model\Country; use Dimsav\Translatable\Test\Model\CountryStrict; use Dimsav\Translatable\Test\Model\CountryWithCustomLocaleKey; +use Dimsav\Translatable\Test\Model\CountryWithCustomTranslationModel; class TranslatableTest extends TestsBase { @@ -317,6 +318,18 @@ public function test_the_locale_key_can_be_customized_per_model() $this->assertEquals($country->getLocaleKey(), 'language_id'); } + public function test_the_translation_model_can_be_customized() + { + $country = CountryWithCustomTranslationModel::create([ + 'code' => 'es', + 'name:en' => 'Spain', + 'name:de' => 'Spanien', + ]); + $this->assertTrue($country->exists()); + $this->assertEquals($country->translate('en')->name, 'Spain'); + $this->assertEquals($country->translate('de')->name, 'Spanien'); + } + public function test_it_reads_the_configuration() { $this->assertEquals(App::make('config')->get('translatable.translation_suffix'), 'Translation'); diff --git a/tests/models/CountryWithCustomLocaleKey.php b/tests/models/CountryWithCustomLocaleKey.php index dd20f44..7275c64 100644 --- a/tests/models/CountryWithCustomLocaleKey.php +++ b/tests/models/CountryWithCustomLocaleKey.php @@ -11,7 +11,6 @@ class CountryWithCustomLocaleKey extends Eloquent public $table = 'countries'; public $translatedAttributes = ['name']; - public $translationModel = 'Dimsav\Translatable\Test\Model\CountryTranslation'; /* * You can customize per model, which attribute will diff --git a/tests/models/CountryWithCustomTranslationModel.php b/tests/models/CountryWithCustomTranslationModel.php new file mode 100644 index 0000000..38f13d9 --- /dev/null +++ b/tests/models/CountryWithCustomTranslationModel.php @@ -0,0 +1,15 @@ + Date: Fri, 12 Oct 2018 15:06:41 +0200 Subject: [PATCH 2/2] fix php cs --- tests/models/CountryWithCustomTranslationModel.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/models/CountryWithCustomTranslationModel.php b/tests/models/CountryWithCustomTranslationModel.php index 38f13d9..4d617a0 100644 --- a/tests/models/CountryWithCustomTranslationModel.php +++ b/tests/models/CountryWithCustomTranslationModel.php @@ -3,7 +3,6 @@ namespace Dimsav\Translatable\Test\Model; use Dimsav\Translatable\Translatable; -use Illuminate\Database\Eloquent\Model as Eloquent; class CountryWithCustomTranslationModel extends Country {