@@ -44,7 +44,7 @@ public function it_wont_interfere_when_setting_non_translatable_attributes()
44
44
}
45
45
46
46
/** @test */
47
- public function it_can_get_a_translatable_attribute_using_a_method ()
47
+ public function it_can_get_a_translation ()
48
48
{
49
49
$ post = new Post ();
50
50
$ post ->title_en = 'Test en ' ;
@@ -56,7 +56,67 @@ public function it_can_get_a_translatable_attribute_using_a_method()
56
56
}
57
57
58
58
/** @test */
59
- public function it_can_get_a_translatable_attribute_using_a_property ()
59
+ public function it_can_get_a_translation_using_a_fallback ()
60
+ {
61
+ $ post = new Post ();
62
+ $ post ->title_en = 'Test en ' ;
63
+ $ post ->title_nl = 'Test nl ' ;
64
+
65
+ $ this ->assertEquals ('Test nl ' , $ post ->getTranslation ('title ' , 'nl ' , true ));
66
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslation ('title ' , 'en ' , true ));
67
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslation ('title ' , 'fr ' , true ));
68
+ }
69
+
70
+ /** @test */
71
+ public function it_can_get_a_translation_without_using_a_fallback ()
72
+ {
73
+ $ post = new Post ();
74
+ $ post ->title_en = 'Test en ' ;
75
+ $ post ->title_nl = 'Test nl ' ;
76
+
77
+ $ this ->assertEquals ('Test nl ' , $ post ->getTranslation ('title ' , 'nl ' , false ));
78
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslation ('title ' , 'en ' , false ));
79
+ $ this ->assertNull ($ post ->getTranslation ('title ' , 'fr ' , false ));
80
+ }
81
+
82
+ /** @test */
83
+ public function it_can_get_a_translation_with_a_fallback ()
84
+ {
85
+ $ post = new Post ();
86
+ $ post ->title_en = 'Test en ' ;
87
+ $ post ->title_nl = 'Test nl ' ;
88
+
89
+ $ this ->assertEquals ('Test nl ' , $ post ->getTranslationWithFallback ('title ' , 'nl ' ));
90
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslationWithFallback ('title ' , 'en ' ));
91
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslationWithFallback ('title ' , 'fr ' ));
92
+ }
93
+
94
+ /** @test */
95
+ public function it_can_get_a_translation_without_a_fallback ()
96
+ {
97
+ $ post = new Post ();
98
+ $ post ->title_en = 'Test en ' ;
99
+ $ post ->title_nl = 'Test nl ' ;
100
+
101
+ $ this ->assertEquals ('Test nl ' , $ post ->getTranslationWithoutFallback ('title ' , 'nl ' ));
102
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslationWithoutFallback ('title ' , 'en ' ));
103
+ $ this ->assertNull ($ post ->getTranslationWithoutFallback ('title ' , 'fr ' ));
104
+ }
105
+
106
+ /** @test */
107
+ public function it_can_get_a_translatable_attribute_using_a_method_with_a_fallback ()
108
+ {
109
+ $ post = new Post ();
110
+ $ post ->title_en = 'Test en ' ;
111
+ $ post ->title_nl = null ;
112
+
113
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslation ('title ' , 'nl ' , true ));
114
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslation ('title ' , 'en ' , true ));
115
+ $ this ->assertEquals ('Test en ' , $ post ->getTranslation ('title ' , 'fr ' , true ));
116
+ }
117
+
118
+ /** @test */
119
+ public function it_can_get_a_translation_using_a_property ()
60
120
{
61
121
$ post = new Post ();
62
122
$ post ->title_en = 'Test en ' ;
@@ -73,7 +133,7 @@ public function it_can_get_a_translatable_attribute_using_a_property()
73
133
}
74
134
75
135
/** @test */
76
- public function it_can_get_a_translatable_attribute_using_an_accessor ()
136
+ public function it_can_get_a_translation_using_an_accessor ()
77
137
{
78
138
$ post = new Post ();
79
139
$ post ->field_with_accessor_en = 'Test en ' ;
0 commit comments