@@ -204,4 +204,76 @@ public function it_can_update_all_translation_records_with_single_assignment()
204204 self ::assertEquals ($ locale ->name . ' description 2 ' , $ product ->description );
205205 }
206206 }
207+
208+ /** @test */
209+ public function it_can_be_filled_and_saved_with_alternative_data_structure ()
210+ {
211+ $ product = new Product ();
212+ $ product ->fill ([
213+ 'product_category_id ' => 3 ,
214+ 'en ' => [
215+ 'title ' => 'English title ' ,
216+ 'description ' => 'English description ' ,
217+ ],
218+ 'es ' => [
219+ 'title ' => 'Spanish title ' ,
220+ 'description ' => 'Spanish description ' ,
221+ ],
222+ 'de ' => [
223+ 'title ' => 'German title ' ,
224+ 'description ' => 'German description ' ,
225+ ],
226+ 'published ' => true
227+ ])->save ();
228+
229+ $ product = Product::orderBy ('id ' , 'desc ' )->first ();
230+
231+ foreach (I18n::getAllLocale () as $ locale ) {
232+ $ product ->translateTo ($ locale );
233+
234+ self ::assertEquals ($ locale ->name . ' title ' , $ product ->title );
235+ self ::assertEquals ($ locale ->name . ' description ' , $ product ->description );
236+ }
237+ }
238+
239+ /** @test */
240+ public function it_can_be_filled_and_updated_with_alternative_data_structure ()
241+ {
242+ $ original = Product::create ([
243+ 'product_category_id ' => 3 ,
244+ 'en ' => [
245+ 'title ' => 'English title ' ,
246+ 'description ' => 'English description ' ,
247+ ],
248+ 'es ' => [
249+ 'title ' => 'Spanish title ' ,
250+ 'description ' => 'Spanish description ' ,
251+ ],
252+ 'published ' => true
253+ ]);
254+
255+ $ product = Product::find ($ original ->id );
256+ $ product ->fill ([
257+ 'en ' => [
258+ 'title ' => 'English title 2 ' ,
259+ 'description ' => 'English description 2 ' ,
260+ ],
261+ 'es ' => [
262+ 'title ' => 'Spanish title 2 ' ,
263+ 'description ' => 'Spanish description 2 ' ,
264+ ],
265+ 'de ' => [
266+ 'title ' => 'German title 2 ' ,
267+ 'description ' => 'German description 2 ' ,
268+ ],
269+ ])->save ();
270+ $ product = Product::find ($ original ->id );
271+
272+ foreach (I18n::getAllLocale () as $ locale ) {
273+ $ product ->translateTo ($ locale );
274+
275+ self ::assertEquals ($ locale ->name . ' title 2 ' , $ product ->title );
276+ self ::assertEquals ($ locale ->name . ' description 2 ' , $ product ->description );
277+ }
278+ }
207279}
0 commit comments