@@ -173,6 +173,56 @@ public function test_translate_to_replicates_media_channels()
173173 $ this ->assertTrue ($ newPost ->hasMedia ('thumbnail ' ), 'Media was not replicated to the new translation ' );
174174 $ this ->assertEquals ($ media ->id , $ newPost ->getFirstMedia ('thumbnail ' )->id );
175175 }
176+
177+ public function test_model_translate_with_overwrites ()
178+ {
179+ Queue::fake ();
180+
181+ $ post = TestPost::create (['title ' => 'Hello ' , 'locale ' => 'en ' ]);
182+
183+ $ options = ['overwrites ' => ['content ' => 'Overwritten Content ' ]];
184+ $ history = model_translate ($ post , 'en ' , 'vi ' , $ options );
185+
186+ $ this ->assertInstanceOf (TranslateHistory::class, $ history );
187+
188+ Queue::assertPushed (ModelTranslateJob::class, function ($ job ) use ($ options ) {
189+ $ reflection = new \ReflectionClass ($ job );
190+ $ jobOptions = $ reflection ->getProperty ('options ' )->getValue ($ job );
191+ return $ jobOptions === $ options ;
192+ });
193+ }
194+
195+ public function test_translate_to_with_overwrites ()
196+ {
197+ $ this ->mock (Translator::class, function ($ mock ) {
198+ $ mock ->shouldReceive ('translate ' )
199+ ->with ('Hello ' , 'en ' , 'vi ' , false )
200+ ->andReturn ('Xin chào ' );
201+ });
202+
203+ $ post = TestPost::create (['title ' => 'Hello ' , 'content ' => 'Original Content ' , 'locale ' => 'en ' ]);
204+
205+ // We simulate the call without the job wrapper to test the trait logic directly
206+ $ result = $ post ->translateTo ('vi ' , 'en ' , [
207+ 'overwrites ' => [
208+ 'content ' => 'Overwritten Content ' ,
209+ ]
210+ ]);
211+
212+ $ this ->assertTrue ($ result );
213+
214+ $ this ->assertDatabaseHas ('test_posts ' , [
215+ 'title ' => 'Xin chào ' ,
216+ 'content ' => 'Overwritten Content ' ,
217+ 'locale ' => 'vi ' ,
218+ ]);
219+
220+ $ this ->assertDatabaseHas ('test_posts ' , [
221+ 'title ' => 'Hello ' ,
222+ 'content ' => 'Original Content ' ,
223+ 'locale ' => 'en ' ,
224+ ]);
225+ }
176226}
177227
178228class TestPost extends Model implements CanBeTranslated
0 commit comments