Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convenience method to return tags with already translated and decoded…
… name and slug fields (#175) * Return tags with translated name and slug fields * add line before return * final tweaks * fix styling * tests for tagsTranslated * readme examples updated * fix test style * remove whitespace * add void return type to test setUp method
- Loading branch information
1 parent
4964bc4
commit b068c9b
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Spatie\Translatable\Test; | ||
|
||
use Spatie\Tags\Tag; | ||
use Spatie\Tags\Test\TestCase; | ||
use Spatie\Tags\Test\TestModel; | ||
|
||
class HasTagsTranslatedTest extends TestCase | ||
{ | ||
/** @var \Spatie\Tags\Test\TestModel */ | ||
protected $testModel; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->testModel = TestModel::create(['name' => 'default']); | ||
} | ||
|
||
/** @test */ | ||
public function it_provides_models_with_tag_name_and_slug_already_translated() | ||
{ | ||
$this->testModel->attachTag('My Tag'); | ||
|
||
$locale = app()->getLocale(); | ||
$translated = $this->testModel->tagsTranslated->first()->toArray(); | ||
|
||
$this->assertEquals($translated['name_translated'], $translated['name'][$locale]); | ||
$this->assertEquals($translated['slug_translated'], $translated['slug'][$locale]); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_provide_models_with_tag_name_and_slug_translated_for_alternate_locales() | ||
{ | ||
$this->testModel->attachTag('My Tag'); | ||
|
||
$locale = 'fr'; | ||
|
||
$tag = $this->testModel->tags->first(); | ||
$tag->setTranslation('name', $locale, 'Mon tag'); | ||
$tag->save(); | ||
|
||
$translated = $this->testModel->tagsTranslated($locale)->first()->toArray(); | ||
|
||
$this->assertEquals($translated['name_translated'], $translated['name'][$locale]); | ||
$this->assertEquals($translated['slug_translated'], $translated['slug'][$locale]); | ||
} | ||
} |