@@ -106,14 +106,14 @@ public function testBuildUrl()
106106 {
107107 $ authKey = '123456 ' ;
108108
109- $ expectedString = 'https://api.deepl.com/v1 /translate? ' . http_build_query (array (
109+ $ expectedString = 'https://api.deepl.com/v2 /translate? ' . http_build_query (array (
110110 'auth_key ' => $ authKey ,
111111 'source_lang ' => 'de ' ,
112112 'target_lang ' => 'en ' ,
113113 'formality ' => 'default '
114114 ));
115115
116- $ deepl = new DeepL ($ authKey );
116+ $ deepl = new DeepL ($ authKey );
117117
118118 $ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildUrl ' );
119119
@@ -125,10 +125,33 @@ public function testBuildUrl()
125125 /**
126126 * Test buildUrl()
127127 */
128- public function testBuildUrlWithTags ()
128+ public function testBuildUrlV1 ()
129129 {
130130 $ authKey = '123456 ' ;
131+
131132 $ 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 (
132155 'auth_key ' => $ authKey ,
133156 'source_lang ' => 'de ' ,
134157 'target_lang ' => 'en ' ,
@@ -137,7 +160,31 @@ public function testBuildUrlWithTags()
137160 'formality ' => 'default '
138161 ));
139162
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 );
141188
142189 $ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildUrl ' );
143190
@@ -164,7 +211,7 @@ public function testBuildBody()
164211 }
165212
166213 /**
167- * Test translate() success
214+ * Test translate() success with v2 API
168215 *
169216 * TEST REQUIRES VALID DEEPL AUTH KEY!!
170217 */
@@ -185,17 +232,38 @@ public function testTranslateSuccess()
185232 }
186233
187234 /**
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
189257 *
190258 * TEST REQUIRES VALID DEEPL AUTH KEY!!
191259 */
192- public function testTranslateV2Success ()
260+ public function testTranslateWrongVersionSuccess ()
193261 {
194262 if (self ::$ authKey === false ) {
195263 $ this ->markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
196264 }
197265
198- $ deepl = new DeepL (self ::$ authKey , 2 );
266+ $ deepl = new DeepL (self ::$ authKey , 3 );
199267
200268 $ germanText = 'Hallo Welt ' ;
201269 $ expectedText = 'Hello World ' ;
0 commit comments