Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 74948a9

Browse files
committed
- add Test for languages-function
- add 2 Tests for buildBaseUrl
1 parent 363bc29 commit 74948a9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/DeepLTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,66 @@ public function testUsage()
354354
$this->assertArrayHasKey('character_count', $response);
355355
$this->assertArrayHasKey('character_limit', $response);
356356
}
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+
}
357419
}

0 commit comments

Comments
 (0)