Completed
Push — master ( efeaa7...112f38 )
by Dimitrios
07:29
created

test_it_creates_a_new_translation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
use Dimsav\Translatable\Test\Model\Country;
4
use Dimsav\Translatable\Test\Model\CountryStrict;
5
use Dimsav\Translatable\Test\Model\CountryWithCustomLocaleKey;
6
use Dimsav\Translatable\Test\Model\Food;
7
8
class TranslatableTest extends TestsBase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    public function test_it_finds_the_default_translation_class()
11
    {
12
        $country = new Country();
13
        $this->assertEquals(
14
            'Dimsav\Translatable\Test\Model\CountryTranslation',
15
            $country->getTranslationModelNameDefault());
16
    }
17
18
    public function test_it_finds_the_translation_class_with_suffix_set()
19
    {
20
        App::make('config')->set('translatable.translation_suffix', 'Trans');
21
        $country = new Country();
22
        $this->assertEquals(
23
            'Dimsav\Translatable\Test\Model\CountryTrans',
24
            $country->getTranslationModelName());
25
    }
26
27
    public function test_it_returns_custom_TranslationModelName()
28
    {
29
        $country = new Country();
30
31
        $this->assertEquals(
32
            $country->getTranslationModelNameDefault(),
33
            $country->getTranslationModelName()
34
        );
35
36
        $country->translationModel = 'MyAwesomeCountryTranslation';
37
        $this->assertEquals(
38
            'MyAwesomeCountryTranslation',
39
            $country->getTranslationModelName()
40
        );
41
    }
42
43
    public function test_it_returns_relation_key()
44
    {
45
        $country = new Country();
46
        $this->assertEquals('country_id', $country->getRelationKey());
47
48
        $country->translationForeignKey = 'my_awesome_key';
49
        $this->assertEquals('my_awesome_key', $country->getRelationKey());
50
    }
51
52
    public function test_it_returns_the_translation()
53
    {
54
        /** @var Country $country */
55
        $country = Country::whereCode('gr')->first();
56
57
        $englishTranslation = $country->translate('el');
58
        $this->assertEquals('Ελλάδα', $englishTranslation->name);
59
60
        $englishTranslation = $country->translate('en');
61
        $this->assertEquals('Greece', $englishTranslation->name);
62
63
        $this->app->setLocale('el');
64
        $englishTranslation = $country->translate();
65
        $this->assertEquals('Ελλάδα', $englishTranslation->name);
66
67
        $this->app->setLocale('en');
68
        $englishTranslation = $country->translate();
69
        $this->assertEquals('Greece', $englishTranslation->name);
70
    }
71
72
    public function test_it_returns_the_translation_with_accessor()
73
    {
74
        /** @var Country $country */
75
        $country = Country::whereCode('gr')->first();
76
77
        $this->assertEquals('Ελλάδα', $country->{'name:el'});
78
        $this->assertEquals('Greece', $country->{'name:en'});
79
    }
80
81
    public function test_it_returns_null_when_the_locale_doesnt_exist()
82
    {
83
        /** @var Country $country */
84
        $country = Country::whereCode('gr')->first();
85
86
        $this->assertSame(null, $country->{'name:unknown-locale'});
87
    }
88
89 View Code Duplication
    public function test_it_saves_translations()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
    {
91
        $country = Country::whereCode('gr')->first();
92
93
        $country->name = '1234';
94
        $country->save();
95
96
        $country = Country::whereCode('gr')->first();
97
        $this->assertEquals('1234', $country->name);
98
    }
99
100
    public function test_it_saves_translations_with_mutator()
101
    {
102
        $country = Country::whereCode('gr')->first();
103
104
        $country->{'name:en'} = '1234';
105
        $country->{'name:el'} = '5678';
106
        $country->save();
107
108
        $country = Country::whereCode('gr')->first();
109
110
        $this->app->setLocale('en');
111
        $translation = $country->translate();
112
        $this->assertEquals('1234', $translation->name);
113
114
        $this->app->setLocale('el');
115
        $translation = $country->translate();
116
        $this->assertEquals('5678', $translation->name);
117
    }
118
119
    public function test_it_uses_default_locale_to_return_translations()
120
    {
121
        $country = Country::whereCode('gr')->first();
122
123
        $country->translate('el')->name = 'abcd';
124
125
        $this->app->setLocale('el');
126
        $this->assertEquals('abcd', $country->name);
127
        $country->save();
128
129
        $country = Country::whereCode('gr')->first();
130
        $this->assertEquals('abcd', $country->translate('el')->name);
131
    }
132
133
    public function test_it_creates_translations()
134
    {
135
        $country = new Country();
136
        $country->code = 'be';
0 ignored issues
show
Documentation introduced by
The property code does not exist on object<Dimsav\Translatable\Test\Model\Country>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
137
        $country->save();
138
139
        $country = Country::whereCode('be')->first();
140
        $country->name = 'Belgium';
141
        $country->save();
142
143
        $country = Country::whereCode('be')->first();
144
        $this->assertEquals('Belgium', $country->name);
145
    }
146
147 View Code Duplication
    public function test_it_creates_translations_using_the_shortcut()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148
    {
149
        $country = new Country();
150
        $country->code = 'be';
0 ignored issues
show
Documentation introduced by
The property code does not exist on object<Dimsav\Translatable\Test\Model\Country>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
151
        $country->name = 'Belgium';
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Dimsav\Translatable\Test\Model\Country>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
152
        $country->save();
153
154
        $country = Country::whereCode('be')->first();
155
        $this->assertEquals('Belgium', $country->name);
156
    }
157
158
    public function test_it_creates_translations_using_mass_assignment()
159
    {
160
        $data = [
161
            'code' => 'be',
162
            'name' => 'Belgium',
163
        ];
164
        $country = Country::create($data);
165
        $this->assertEquals('be', $country->code);
0 ignored issues
show
Documentation introduced by
The property code does not exist on object<Dimsav\Translatable\Test\Model\Country>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
166
        $this->assertEquals('Belgium', $country->name);
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Dimsav\Translatable\Test\Model\Country>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
167
    }
168
169
    public function test_it_creates_translations_using_mass_assignment_and_locales()
170
    {
171
        $data = [
172
            'code' => 'be',
173
            'en' => ['name' => 'Belgium'],
174
            'fr' => ['name' => 'Belgique'],
175
        ];
176
        $country = Country::create($data);
177
        $this->assertEquals('be', $country->code);
0 ignored issues
show
Documentation introduced by
The property code does not exist on object<Dimsav\Translatable\Test\Model\Country>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
178
        $this->assertEquals('Belgium', $country->translate('en')->name);
179
        $this->assertEquals('Belgique', $country->translate('fr')->name);
180
181
        $country = Country::whereCode('be')->first();
182
        $this->assertEquals('Belgium', $country->translate('en')->name);
183
        $this->assertEquals('Belgique', $country->translate('fr')->name);
184
    }
185
186
    public function test_it_skips_mass_assignment_if_attributes_non_fillable()
187
    {
188
        $data = [
189
            'code' => 'be',
190
            'en' => ['name' => 'Belgium'],
191
            'fr' => ['name' => 'Belgique'],
192
        ];
193
        $country = CountryStrict::create($data);
194
        $this->assertEquals('be', $country->code);
0 ignored issues
show
Documentation introduced by
The property code does not exist on object<Dimsav\Translatab...st\Model\CountryStrict>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
195
        $this->assertNull($country->translate('en'));
196
        $this->assertNull($country->translate('fr'));
197
    }
198
199
    public function test_it_returns_if_object_has_translation()
200
    {
201
        $country = Country::find(1);
202
        $this->assertTrue($country->hasTranslation('en'));
203
        $this->assertFalse($country->hasTranslation('abc'));
204
    }
205
206
    public function test_it_returns_default_translation()
207
    {
208
        App::make('config')->set('translatable.fallback_locale', 'de');
209
210
        $country = Country::find(1);
211
        $this->assertSame($country->getTranslation('ch', true)->name, 'Griechenland');
212
        $this->assertSame($country->translateOrDefault('ch')->name, 'Griechenland');
213
        $this->assertSame($country->getTranslation('ch', false), null);
214
    }
215
216
    public function test_fallback_option_in_config_overrides_models_fallback_option()
217
    {
218
        App::make('config')->set('translatable.fallback_locale', 'de');
219
220
        $country = Country::find(1);
221
        $this->assertEquals($country->getTranslation('ch', true)->locale, 'de');
222
223
        $country->useTranslationFallback = false;
224
        $this->assertEquals($country->getTranslation('ch', true)->locale, 'de');
225
226
        $country->useTranslationFallback = true;
227
        $this->assertEquals($country->getTranslation('ch')->locale, 'de');
228
229
        $country->useTranslationFallback = false;
230
        $this->assertSame($country->getTranslation('ch'), null);
231
    }
232
233
    public function test_configuration_defines_if_fallback_is_used()
234
    {
235
        App::make('config')->set('translatable.fallback_locale', 'de');
236
        App::make('config')->set('translatable.use_fallback', true);
237
238
        $country = Country::find(1);
239
        $this->assertEquals($country->getTranslation('ch')->locale, 'de');
240
    }
241
242
    public function test_useTranslationFallback_overrides_configuration()
243
    {
244
        App::make('config')->set('translatable.fallback_locale', 'de');
245
        App::make('config')->set('translatable.use_fallback', true);
246
        $country = Country::find(1);
247
        $country->useTranslationFallback = false;
248
        $this->assertSame($country->getTranslation('ch'), null);
249
    }
250
251
    public function test_it_returns_null_if_fallback_is_not_defined()
252
    {
253
        App::make('config')->set('translatable.fallback_locale', 'ch');
254
255
        $country = Country::find(1);
256
        $this->assertSame($country->getTranslation('pl', true), null);
257
    }
258
259
    public function test_it_fills_a_non_default_language_with_fallback_set()
260
    {
261
        App::make('config')->set('translatable.fallback_locale', 'en');
262
263
        $country = new Country();
264
        $country->fill([
265
            'code' => 'gr',
266
            'en' => ['name' => 'Greece'],
267
            'de' => ['name' => 'Griechenland'],
268
        ]);
269
270
        $this->assertEquals($country->translate('en')->name, 'Greece');
271
    }
272
273
    public function test_it_creates_a_new_translation()
274
    {
275
        App::make('config')->set('translatable.fallback_locale', 'en');
276
277
        $country = Country::create(['code' => 'gr']);
278
        $country->getNewTranslation('en')->name = 'Greece';
279
        $country->save();
280
281
        $this->assertEquals($country->translate('en')->name, 'Greece');
282
    }
283
284
    public function test_the_locale_key_is_locale_by_default()
285
    {
286
        $country = Country::find(1);
287
        $this->assertEquals($country->getLocaleKey(), 'locale');
288
    }
289
290
    public function test_the_locale_key_can_be_overridden_in_configuration()
291
    {
292
        App::make('config')->set('translatable.locale_key', 'language_id');
293
294
        $country = Country::find(1);
295
        $this->assertEquals($country->getLocaleKey(), 'language_id');
296
    }
297
298
    public function test_the_locale_key_can_be_customized_per_model()
299
    {
300
        $country = CountryWithCustomLocaleKey::find(1);
301
        $this->assertEquals($country->getLocaleKey(), 'language_id');
302
    }
303
304
    public function test_it_reads_the_configuration()
305
    {
306
        $this->assertEquals(App::make('config')->get('translatable.translation_suffix'), 'Translation');
307
    }
308
309
    public function test_getting_translation_does_not_create_translation()
310
    {
311
        $country = Country::with('translations')->find(1);
0 ignored issues
show
Bug introduced by
The method find does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
312
        $translation = $country->getTranslation('abc', false);
313
        $this->assertSame($translation, null);
314
    }
315
316
    public function test_getting_translated_field_does_not_create_translation()
317
    {
318
        $this->app->setLocale('en');
319
        $country = new Country(['code' => 'pl']);
320
        $country->save();
321
322
        $country->name;
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Dimsav\Translatable\Test\Model\Country>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
323
324
        $this->assertSame($country->getTranslation('en'), null);
325
    }
326
327
    /**
328
     * @expectedException Dimsav\Translatable\Exception\LocalesNotDefinedException
329
     */
330
    public function test_if_locales_are_not_defined_throw_exception()
331
    {
332
        $this->app->config->set('translatable.locales', []);
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
333
        new Country(['code' => 'pl']);
334
    }
335
336
    public function test_it_has_methods_that_return_always_a_translation()
337
    {
338
        $country = Country::find(1)->first();
339
        $this->assertSame('abc', $country->translateOrNew('abc')->locale);
340
    }
341
342
    public function test_configuration_overrides_fillable()
343
    {
344
        App::make('config')->set('translatable.always_fillable', true);
345
346
        $country = new CountryStrict([
347
            'en' => ['name' => 'Not fillable'],
348
            'code' => 'te',
349
        ]);
350
351
        $this->assertSame($country->getTranslation('en')->name, 'Not fillable');
352
    }
353
354
    public function test_it_returns_if_attribute_is_translated()
355
    {
356
        $country = new Country();
357
358
        $this->assertTrue($country->isTranslationAttribute('name'));
359
        $this->assertFalse($country->isTranslationAttribute('some-field'));
360
    }
361
362
    public function test_config_overrides_apps_locale()
363
    {
364
        $country = Country::find(1);
365
        App::make('config')->set('translatable.locale', 'de');
366
367
        $this->assertSame('Griechenland', $country->name);
368
    }
369
370
    public function test_locales_as_array_keys_are_properly_detected()
371
    {
372
        $this->app->config->set('translatable.locales', ['en' => ['US', 'GB']]);
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
373
374
        $data = [
375
            'en' => ['name' => 'French fries'],
376
            'en-US' => ['name' => 'American french fries'],
377
            'en-GB' => ['name' => 'Chips'],
378
        ];
379
        $frenchFries = Food::create($data);
380
381
        $this->assertSame('French fries', $frenchFries->getTranslation('en')->name);
382
        $this->assertSame('Chips', $frenchFries->getTranslation('en-GB')->name);
383
        $this->assertSame('American french fries', $frenchFries->getTranslation('en-US')->name);
384
    }
385
386
    public function test_locale_separator_can_be_configured()
387
    {
388
        $this->app->config->set('translatable.locales', ['en' => ['GB']]);
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
389
        $this->app->config->set('translatable.locale_separator', '_');
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
390
        $data = [
391
            'en_GB' => ['name' => 'Chips'],
392
        ];
393
        $frenchFries = Food::create($data);
394
395
        $this->assertSame('Chips', $frenchFries->getTranslation('en_GB')->name);
396
    }
397
398
    public function test_fallback_for_country_based_locales()
399
    {
400
        $this->app->config->set('translatable.use_fallback', true);
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
401
        $this->app->config->set('translatable.fallback_locale', 'fr');
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
402
        $this->app->config->set('translatable.locales', ['en' => ['US', 'GB'], 'fr']);
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
403
        $this->app->config->set('translatable.locale_separator', '-');
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
404
        $data = [
405
            'id' => 1,
406
            'fr' => ['name' => 'frites'],
407
            'en-GB' => ['name' => 'chips'],
408
            'en' => ['name' => 'french fries'],
409
        ];
410
        Food::create($data);
411
        $fries = Food::find(1);
412
        $this->assertSame('french fries', $fries->getTranslation('en-US')->name);
413
    }
414
415
    public function test_to_array_and_fallback_with_country_based_locales_enabled()
416
    {
417
        $this->app->config->set('translatable.use_fallback', true);
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
418
        $this->app->config->set('translatable.fallback_locale', 'fr');
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
419
        $this->app->config->set('translatable.locales', ['en' => ['GB'], 'fr']);
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
420
        $this->app->config->set('translatable.locale_separator', '-');
0 ignored issues
show
Bug introduced by
The property config does not seem to exist. Did you mean monologConfigurator?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
421
        $data = [
422
            'id' => 1,
423
            'fr' => ['name' => 'frites'],
424
        ];
425
        Food::create($data);
426
        $fritesArray = Food::find(1)->toArray();
427
        $this->assertSame('frites', $fritesArray['name']);
428
    }
429
}
430