Skip to content
This repository was archived by the owner on Jun 18, 2019. It is now read-only.

Commit cf6c8dc

Browse files
authored
Merge pull request #527 from dimsav/issue-526
add unittest for customized translation model
2 parents e6f458e + 6d01a87 commit cf6c8dc

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

tests/TranslatableTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Dimsav\Translatable\Test\Model\Country;
66
use Dimsav\Translatable\Test\Model\CountryStrict;
77
use Dimsav\Translatable\Test\Model\CountryWithCustomLocaleKey;
8+
use Dimsav\Translatable\Test\Model\CountryWithCustomTranslationModel;
89

910
class TranslatableTest extends TestsBase
1011
{
@@ -317,6 +318,18 @@ public function test_the_locale_key_can_be_customized_per_model()
317318
$this->assertEquals($country->getLocaleKey(), 'language_id');
318319
}
319320

321+
public function test_the_translation_model_can_be_customized()
322+
{
323+
$country = CountryWithCustomTranslationModel::create([
324+
'code' => 'es',
325+
'name:en' => 'Spain',
326+
'name:de' => 'Spanien',
327+
]);
328+
$this->assertTrue($country->exists());
329+
$this->assertEquals($country->translate('en')->name, 'Spain');
330+
$this->assertEquals($country->translate('de')->name, 'Spanien');
331+
}
332+
320333
public function test_it_reads_the_configuration()
321334
{
322335
$this->assertEquals(App::make('config')->get('translatable.translation_suffix'), 'Translation');

tests/models/CountryWithCustomLocaleKey.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class CountryWithCustomLocaleKey extends Eloquent
1111

1212
public $table = 'countries';
1313
public $translatedAttributes = ['name'];
14-
public $translationModel = 'Dimsav\Translatable\Test\Model\CountryTranslation';
1514

1615
/*
1716
* You can customize per model, which attribute will
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Dimsav\Translatable\Test\Model;
4+
5+
use Dimsav\Translatable\Translatable;
6+
7+
class CountryWithCustomTranslationModel extends Country
8+
{
9+
use Translatable;
10+
11+
public $table = 'countries';
12+
public $translationForeignKey = 'country_id';
13+
public $translationModel = 'Dimsav\Translatable\Test\Model\CountryTranslation';
14+
}

0 commit comments

Comments
 (0)