Inheritance: extends Illuminate\Database\Eloquent\Model, use trait Stevebauman\Translation\Traits\LocaleTrait
Example #1
0
 public function testTranslationDefaultLocale()
 {
     $this->assertEquals('Test', Translation::translate('Test'));
     $locale = LocaleModel::first();
     $this->assertEquals('en', $locale->code);
     $this->assertEquals('English', $locale->name);
     $translation = TranslationModel::first();
     $this->assertEquals('Test', $translation->translation);
     $this->assertEquals($locale->getKey(), $translation->locale_id);
 }
Example #2
0
 private function assertCachingIsWorking($text, $replacements = [], $localeCode = 'en')
 {
     $hash = md5($text);
     // After translating this text, result should be cached
     // and next time we execute translate method with same
     // text, it should return value from cache instead of
     // touching the database.
     $this->assertEquals($text, Translation::translate($text, $replacements, $localeCode));
     $this->assertTrue(Cache::has("translation.{$localeCode}"));
     $this->assertTrue(Cache::has("translation.{$localeCode}.{$hash}"));
     // Delete all translation data from database.
     TranslationModel::query()->delete();
     LocaleModel::query()->delete();
     // Execute translation again
     $this->assertEquals($text, Translation::translate($text, $replacements, $localeCode));
     // Asserting that there are no inserted values after
     // translate method is executed means that db is not touched at all
     // and that translation and locale is cached properly.
     $this->assertEquals(0, TranslationModel::all()->count());
     $this->assertEquals(0, LocaleModel::all()->count());
 }