/** * @test */ public function it_flushes_cache() { $cacheMock = Mockery::mock(\Waavi\Translation\Cache\SimpleRepository::class); $this->app->bind('translation.cache.repository', function ($app) use($cacheMock) { return $cacheMock; }); $cacheMock->shouldReceive('flush')->with('en', 'translatable', '*'); $dummy = new Dummy(); $dummy->title = 'Dummy title'; $dummy->text = 'Dummy text'; $saved = $dummy->save() ? true : false; $this->assertTrue($saved); }
/** * @test */ public function to_array_features_translated_attributes() { $dummy = Dummy::create(['title' => 'Dummy title', 'text' => 'Dummy text']); $this->assertEquals(1, Dummy::count()); // Change the text on the translation object: $titleTranslation = $this->translationRepository->findByLangCode('en', $dummy->translationCodeFor('title')); $titleTranslation->text = 'Translated text'; $titleTranslation->save(); // Verify that toArray pulls from the translation and not model's value, and that the _translation attributes are hidden $this->assertEquals(['title' => 'Translated text', 'text' => 'Dummy text'], $dummy->makeHidden(['created_at', 'updated_at', 'slug', 'id'])->toArray()); }