@@ -113,7 +113,30 @@ public function testBuildUrl()
113
113
'formality ' => 'default '
114
114
));
115
115
116
- $ deepl = new DeepL ($ authKey );
116
+ $ deepl = new DeepL ($ authKey );
117
+
118
+ $ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildUrl ' );
119
+
120
+ $ return = $ buildUrl ->invokeArgs ($ deepl , array ('de ' , 'en ' ));
121
+
122
+ $ this ->assertEquals ($ expectedString , $ return );
123
+ }
124
+
125
+ /**
126
+ * Test buildUrl()
127
+ */
128
+ public function testBuildUrlV1 ()
129
+ {
130
+ $ authKey = '123456 ' ;
131
+
132
+ $ expectedString = 'https://api.deepl.com/v1/translate? ' . http_build_query (array (
133
+ 'auth_key ' => $ authKey ,
134
+ 'source_lang ' => 'de ' ,
135
+ 'target_lang ' => 'en ' ,
136
+ 'formality ' => 'default '
137
+ ));
138
+
139
+ $ deepl = new DeepL ($ authKey , 1 );
117
140
118
141
$ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildUrl ' );
119
142
@@ -137,7 +160,31 @@ public function testBuildUrlWithTags()
137
160
'formality ' => 'default '
138
161
));
139
162
140
- $ deepl = new DeepL ($ authKey );
163
+ $ deepl = new DeepL ($ authKey );
164
+
165
+ $ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildUrl ' );
166
+
167
+ $ return = $ buildUrl ->invokeArgs ($ deepl , array ('de ' , 'en ' , array ('xml ' ), array ('x ' )));
168
+
169
+ $ this ->assertEquals ($ expectedString , $ return );
170
+ }
171
+
172
+ /**
173
+ * Test buildUrl()
174
+ */
175
+ public function testBuildUrlWithTagsV1 ()
176
+ {
177
+ $ authKey = '123456 ' ;
178
+ $ expectedString = 'https://api.deepl.com/v1/translate? ' . http_build_query (array (
179
+ 'auth_key ' => $ authKey ,
180
+ 'source_lang ' => 'de ' ,
181
+ 'target_lang ' => 'en ' ,
182
+ 'tag_handling ' => 'xml ' ,
183
+ 'ignore_tags ' => 'x ' ,
184
+ 'formality ' => 'default '
185
+ ));
186
+
187
+ $ deepl = new DeepL ($ authKey , 1 );
141
188
142
189
$ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildUrl ' );
143
190
@@ -205,6 +252,27 @@ public function testTranslateV1Success()
205
252
$ this ->assertEquals ($ expectedText , $ translatedText );
206
253
}
207
254
255
+ /**
256
+ * Test translate() success with default v2 API
257
+ *
258
+ * TEST REQUIRES VALID DEEPL AUTH KEY!!
259
+ */
260
+ public function testTranslateWrongVersionSuccess ()
261
+ {
262
+ if (self ::$ authKey === false ) {
263
+ $ this ->markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
264
+ }
265
+
266
+ $ deepl = new DeepL (self ::$ authKey , 3 );
267
+
268
+ $ germanText = 'Hallo Welt ' ;
269
+ $ expectedText = 'Hello World ' ;
270
+
271
+ $ translatedText = $ deepl ->translate ($ germanText );
272
+
273
+ $ this ->assertEquals ($ expectedText , $ translatedText );
274
+ }
275
+
208
276
/**
209
277
* Test translate() with tag handling success
210
278
*
0 commit comments