@@ -106,14 +106,14 @@ public function testBuildUrl()
106
106
{
107
107
$ authKey = '123456 ' ;
108
108
109
- $ expectedString = 'https://api.deepl.com/v1 /translate? ' . http_build_query (array (
109
+ $ expectedString = 'https://api.deepl.com/v2 /translate? ' . http_build_query (array (
110
110
'auth_key ' => $ authKey ,
111
111
'source_lang ' => 'de ' ,
112
112
'target_lang ' => 'en ' ,
113
113
'formality ' => 'default '
114
114
));
115
115
116
- $ deepl = new DeepL ($ authKey );
116
+ $ deepl = new DeepL ($ authKey );
117
117
118
118
$ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildUrl ' );
119
119
@@ -125,10 +125,33 @@ public function testBuildUrl()
125
125
/**
126
126
* Test buildUrl()
127
127
*/
128
- public function testBuildUrlWithTags ()
128
+ public function testBuildUrlV1 ()
129
129
{
130
130
$ authKey = '123456 ' ;
131
+
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 );
140
+
141
+ $ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildUrl ' );
142
+
143
+ $ return = $ buildUrl ->invokeArgs ($ deepl , array ('de ' , 'en ' ));
144
+
145
+ $ this ->assertEquals ($ expectedString , $ return );
146
+ }
147
+
148
+ /**
149
+ * Test buildUrl()
150
+ */
151
+ public function testBuildUrlWithTags ()
152
+ {
153
+ $ authKey = '123456 ' ;
154
+ $ expectedString = 'https://api.deepl.com/v2/translate? ' . http_build_query (array (
132
155
'auth_key ' => $ authKey ,
133
156
'source_lang ' => 'de ' ,
134
157
'target_lang ' => 'en ' ,
@@ -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
@@ -164,7 +211,7 @@ public function testBuildBody()
164
211
}
165
212
166
213
/**
167
- * Test translate() success
214
+ * Test translate() success with v2 API
168
215
*
169
216
* TEST REQUIRES VALID DEEPL AUTH KEY!!
170
217
*/
@@ -185,17 +232,38 @@ public function testTranslateSuccess()
185
232
}
186
233
187
234
/**
188
- * Test translate() success with v2 API
235
+ * Test translate() success with v1 API
236
+ *
237
+ * TEST REQUIRES VALID DEEPL AUTH KEY!!
238
+ */
239
+ public function testTranslateV1Success ()
240
+ {
241
+ if (self ::$ authKey === false ) {
242
+ $ this ->markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
243
+ }
244
+
245
+ $ deepl = new DeepL (self ::$ authKey , 1 );
246
+
247
+ $ germanText = 'Hallo Welt ' ;
248
+ $ expectedText = 'Hello World ' ;
249
+
250
+ $ translatedText = $ deepl ->translate ($ germanText );
251
+
252
+ $ this ->assertEquals ($ expectedText , $ translatedText );
253
+ }
254
+
255
+ /**
256
+ * Test translate() success with default v2 API
189
257
*
190
258
* TEST REQUIRES VALID DEEPL AUTH KEY!!
191
259
*/
192
- public function testTranslateV2Success ()
260
+ public function testTranslateWrongVersionSuccess ()
193
261
{
194
262
if (self ::$ authKey === false ) {
195
263
$ this ->markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
196
264
}
197
265
198
- $ deepl = new DeepL (self ::$ authKey , 2 );
266
+ $ deepl = new DeepL (self ::$ authKey , 3 );
199
267
200
268
$ germanText = 'Hallo Welt ' ;
201
269
$ expectedText = 'Hello World ' ;
0 commit comments