@@ -918,4 +918,56 @@ public function test_it_returns_first_existing_translation_as_fallback()
918918 $ this ->assertInstanceOf (CountryTranslation::class, $ translation );
919919 $ this ->assertEquals ($ helper ->getCountryLocale ('de ' , 'DE ' ), $ translation ->locale );
920920 }
921+
922+ public function test_it_uses_translation_relation_if_locale_matches ()
923+ {
924+ $ this ->app ->make ('config ' )->set ('translatable.use_fallback ' , false );
925+ $ this ->app ->setLocale ('de ' );
926+
927+ /** @var Country $country */
928+ $ country = Country::find (1 );
929+ $ country ->load ('translation ' );
930+ $ this ->assertTrue ($ country ->relationLoaded ('translation ' ));
931+ $ this ->assertFalse ($ country ->relationLoaded ('translations ' ));
932+
933+ $ translation = $ country ->getTranslation ();
934+ $ this ->assertInstanceOf (CountryTranslation::class, $ translation );
935+ $ this ->assertEquals ('de ' , $ translation ->locale );
936+ $ this ->assertFalse ($ country ->relationLoaded ('translations ' ));
937+ }
938+
939+ public function test_it_uses_translations_relation_if_locale_does_not_match ()
940+ {
941+ $ this ->app ->make ('config ' )->set ('translatable.use_fallback ' , false );
942+ $ this ->app ->setLocale ('de ' );
943+
944+ /** @var Country $country */
945+ $ country = Country::find (1 );
946+ $ country ->load ('translation ' );
947+ $ this ->assertTrue ($ country ->relationLoaded ('translation ' ));
948+ $ this ->assertFalse ($ country ->relationLoaded ('translations ' ));
949+ $ this ->app ->setLocale ('en ' );
950+
951+ $ translation = $ country ->getTranslation ();
952+ $ this ->assertInstanceOf (CountryTranslation::class, $ translation );
953+ $ this ->assertEquals ('en ' , $ translation ->locale );
954+ $ this ->assertTrue ($ country ->relationLoaded ('translations ' ));
955+ }
956+
957+ public function test_it_does_not_load_translation_relation_if_not_already_loaded ()
958+ {
959+ $ this ->app ->make ('config ' )->set ('translatable.use_fallback ' , false );
960+ $ this ->app ->setLocale ('de ' );
961+
962+ /** @var Country $country */
963+ $ country = Country::find (1 );
964+ $ this ->assertFalse ($ country ->relationLoaded ('translation ' ));
965+ $ this ->assertFalse ($ country ->relationLoaded ('translations ' ));
966+
967+ $ translation = $ country ->getTranslation ();
968+ $ this ->assertInstanceOf (CountryTranslation::class, $ translation );
969+ $ this ->assertEquals ('de ' , $ translation ->locale );
970+ $ this ->assertFalse ($ country ->relationLoaded ('translation ' ));
971+ $ this ->assertTrue ($ country ->relationLoaded ('translations ' ));
972+ }
921973}
0 commit comments