@@ -354,4 +354,66 @@ public function testUsage()
354
354
$ this ->assertArrayHasKey ('character_count ' , $ response );
355
355
$ this ->assertArrayHasKey ('character_limit ' , $ response );
356
356
}
357
+
358
+ /**
359
+ * Test languages() has certain array-keys
360
+ *
361
+ * TEST REQUIRES VALID DEEPL AUTH KEY!!
362
+ */
363
+ public function testLanguages ()
364
+ {
365
+ if (self ::$ authKey === false ) {
366
+ $ this ->markTestSkipped ('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured. ' );
367
+ }
368
+
369
+ $ deepl = new DeepL (self ::$ authKey );
370
+ $ response = $ deepl ->languages ();
371
+
372
+ foreach ($ response as $ language ) {
373
+ $ this ->assertArrayHasKey ('language ' , $ language );
374
+ $ this ->assertArrayHasKey ('name ' , $ language );
375
+ }
376
+
377
+ }
378
+
379
+ /**
380
+ * Test buildBaseUrl()
381
+ */
382
+ public function testbuildBaseUrl ()
383
+ {
384
+ $ authKey = '123456 ' ;
385
+
386
+ $ expectedString = 'https://api.deepl.com/v2/translate? ' . http_build_query (array (
387
+ 'auth_key ' => $ authKey
388
+ ));
389
+
390
+ $ deepl = new DeepL ($ authKey );
391
+
392
+ $ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildBaseUrl ' );
393
+
394
+ $ return = $ buildUrl ->invokeArgs ($ deepl ,array ());
395
+
396
+ $ this ->assertEquals ($ expectedString , $ return );
397
+ }
398
+
399
+ /**
400
+ * Test buildBaseUrl() with own host
401
+ */
402
+ public function testbuildBaseUrlHost ()
403
+ {
404
+ $ authKey = '123456 ' ;
405
+ $ host = 'myownhost.dev ' ;
406
+
407
+ $ expectedString = 'https:// ' .$ host .'/v2/translate? ' . http_build_query (array (
408
+ 'auth_key ' => $ authKey
409
+ ));
410
+
411
+ $ deepl = new DeepL ($ authKey , 2 , $ host );
412
+
413
+ $ buildUrl = self ::getMethod ('\BabyMarkt\DeepL\DeepL ' , 'buildBaseUrl ' );
414
+
415
+ $ return = $ buildUrl ->invokeArgs ($ deepl ,array ());
416
+
417
+ $ this ->assertEquals ($ expectedString , $ return );
418
+ }
357
419
}
0 commit comments