This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 321
/
ScopesTest.php
76 lines (65 loc) · 2.58 KB
/
ScopesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
use Dimsav\Translatable\Test\Model\Country;
use Dimsav\Translatable\Test\Model\CountryStrict;
use Dimsav\Translatable\Test\Model\CountryWithCustomLocaleKey;
class ScopesTest extends TestsBase
{
public function test_translated_in_scope_returns_only_translated_records_for_this_locale()
{
$translatedCountries = Country::translatedIn('fr')->get();
$this->assertEquals($translatedCountries->count(), 1);
}
public function test_translated_in_scope_works_with_default_locale()
{
App::setLocale('de');
$translatedCountries = Country::translatedIn()->get();
$this->assertSame($translatedCountries->count(), 1);
$this->assertSame('Griechenland', $translatedCountries->first()->name);
}
public function test_translated_scope_returns_records_with_at_least_one_translation()
{
$translatedCountries = Country::translated()->get();
$this->assertEquals($translatedCountries->count(), 2);
}
public function test_lists_of_translated_fields()
{
App::setLocale('de');
$list = [[
'id' => '1',
'name' => 'Griechenland',
]];
$this->assertEquals($list, Country::listsTranslations('name')->get()->toArray());
}
public function test_lists_of_translated_fields_with_fallback()
{
App::make('config')->set('translatable.fallback_locale', 'en');
App::setLocale('de');
$country = new Country();
$country->useTranslationFallback = true;
$list = [[
'id' => '1',
'name' => 'Griechenland',
],[
'id' => '2',
'name' => 'France',
]];
$this->assertEquals($list, $country->listsTranslations('name')->get()->toArray());
}
public function test_scope_withTranslation_without_fallback()
{
$result = Country::withTranslation()->first();
$loadedTranslations = $result->toArray()['translations'];
$this->assertCount(1, $loadedTranslations);
$this->assertSame('Greece', $loadedTranslations[0]['name']);
}
public function test_scope_withTranslation_with_fallback()
{
App::make('config')->set('translatable.fallback_locale', 'de');
App::make('config')->set('translatable.use_fallback', true);
$result = Country::withTranslation()->first();
$loadedTranslations = $result->toArray()['translations'];
$this->assertCount(2, $loadedTranslations);
$this->assertSame('Greece', $loadedTranslations[0]['name']);
$this->assertSame('Griechenland', $loadedTranslations[1]['name']);
}
}