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

Commit 2584a89

Browse files
Merge pull request #4 from Baby-Markt/feature/travis-deepl-tests
MASTER: Feature/travis deepl tests
2 parents 026c528 + 93eea66 commit 2584a89

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

tests/DeepLTest.php

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,25 @@
1010
class DeepLTest extends \PHPUnit_Framework_TestCase
1111
{
1212
/**
13-
* DeepL Auth Key (Set if you want to test all methods)
13+
* DeepL Auth Key.
1414
*
15-
* @var string
15+
* @var bool|string
1616
*/
17-
private $authKey = '';
17+
protected static $authKey = false;
18+
19+
/**
20+
* Setup DeepL Auth Key.
21+
*/
22+
public static function setUpBeforeClass()
23+
{
24+
parent::setUpBeforeClass();
25+
26+
if (($authKey = getenv('DEEPL_AUTH_KEY')) === false) {
27+
return;
28+
}
29+
30+
self::$authKey = $authKey;
31+
}
1832

1933
/**
2034
* Get protected method
@@ -98,32 +112,37 @@ public function testBuildUrl()
98112
}
99113

100114
/**
101-
* Test buildBody()
115+
* Test buildUrl()
102116
*/
103-
public function testBuildBody()
117+
public function testBuildUrlWithTags()
104118
{
105-
$expectedString = 'text=Hallo%20Welt';
119+
$expectedString = 'https://api.deepl.com/v1/translate?auth_key=123456&source_lang=de&target_lang=en&tag_handling=xml&ignore_tags=x';
106120

107121
$authKey = '123456';
108122
$deepl = new DeepL($authKey);
109123

110-
$buildUrl = self::getMethod('\BabyMarkt\DeepL\DeepL', 'buildBody');
124+
$buildUrl = self::getMethod('\BabyMarkt\DeepL\DeepL', 'buildUrl');
111125

112-
$return = $buildUrl->invokeArgs($deepl, array('Hallo Welt'));
126+
$return = $buildUrl->invokeArgs($deepl, array('de', 'en', array('xml'), array('x')));
113127

114128
$this->assertEquals($expectedString, $return);
115129
}
116130

117131
/**
118-
* Test translate() calls
132+
* Test buildBody()
119133
*/
120-
public function testTranslate()
134+
public function testBuildBody()
121135
{
122-
return;
136+
$expectedString = 'text=Hallo%20Welt';
123137

124-
$mock = $this->getMockBuilder('\BabyMarkt\DeepL\DeepL');
138+
$authKey = '123456';
139+
$deepl = new DeepL($authKey);
140+
141+
$buildUrl = self::getMethod('\BabyMarkt\DeepL\DeepL', 'buildBody');
125142

126-
// TODO: test if translate methods calls correct methods
143+
$return = $buildUrl->invokeArgs($deepl, array('Hallo Welt'));
144+
145+
$this->assertEquals($expectedString, $return);
127146
}
128147

129148
/**
@@ -133,11 +152,11 @@ public function testTranslate()
133152
*/
134153
public function testTranslateSuccess()
135154
{
136-
if (!$this->authKey) {
137-
return;
155+
if (self::$authKey === false) {
156+
$this->markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
138157
}
139158

140-
$deepl = new DeepL($this->authKey);
159+
$deepl = new DeepL(self::$authKey);
141160

142161
$germanText = 'Hallo Welt';
143162
$expectedText = 'Hello World';
@@ -154,11 +173,11 @@ public function testTranslateSuccess()
154173
*/
155174
public function testTranslateV2Success()
156175
{
157-
if (!$this->authKey) {
158-
return;
176+
if (self::$authKey === false) {
177+
$this->markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
159178
}
160179

161-
$deepl = new DeepL($this->authKey, 2);
180+
$deepl = new DeepL(self::$authKey, 2);
162181

163182
$germanText = 'Hallo Welt';
164183
$expectedText = 'Hello World';
@@ -175,11 +194,11 @@ public function testTranslateV2Success()
175194
*/
176195
public function testTranslateTagHandlingSuccess()
177196
{
178-
if (!$this->authKey) {
179-
return;
197+
if (self::$authKey === false) {
198+
$this->markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
180199
}
181200

182-
$deepl = new DeepL($this->authKey);
201+
$deepl = new DeepL(self::$authKey);
183202

184203
$englishText = '<strong>text to translate</strong>';
185204
$expectedText = '<strong>zu übersetzender Text</strong>';
@@ -201,14 +220,14 @@ public function testTranslateTagHandlingSuccess()
201220
*/
202221
public function testTranslateIgnoreTagsSuccess()
203222
{
204-
if (!$this->authKey) {
205-
return;
223+
if (self::$authKey === false) {
224+
$this->markTestSkipped('DeepL Auth Key (DEEPL_AUTH_KEY) is not configured.');
206225
}
207226

208-
$deepl = new DeepL($this->authKey);
227+
$deepl = new DeepL(self::$authKey);
209228

210229
$englishText = '<strong>text to do not translate</strong><p>text to translate</p>';
211-
$expectedText = '<strong>Text, der nicht übersetzt werden soll</strong><p>zu übersetzender Text</p>';
230+
$expectedText = '<strong>text to do not translate</strong><p>zu übersetzender Text</p>';
212231

213232
$translatedText = $deepl->translate(
214233
$englishText,

0 commit comments

Comments
 (0)