TranslationTest.php
1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Stichoza\GoogleTranslate\Tests;
use PHPUnit\Framework\TestCase;
use Stichoza\GoogleTranslate\GoogleTranslate;
class TranslationTest extends TestCase
{
public $tr;
public function setUp()
{
$this->tr = new GoogleTranslate();
}
public function testTranslationEquality()
{
try {
$resultOne = GoogleTranslate::trans('Hello', 'ka', 'en');
} catch (\ErrorException $e) {
$resultOne = null;
}
$resultTwo = $this->tr->setSource('en')->setTarget('ka')->translate('Hello');
$this->assertEquals($resultOne, $resultTwo, 'გამარჯობა');
}
public function testUTF16Translation()
{
try {
$resultOne = GoogleTranslate::trans('yes 👍🏽', 'de', 'en');
} catch (\ErrorException $e) {
$resultOne = null;
}
$resultTwo = $this->tr->setSource('en')->setTarget('de')->translate('yes 👍🏽');
$this->assertEquals($resultOne, $resultTwo, 'ja 👍🏽');
}
public function testRawResponse()
{
$rawResult = $this->tr->getResponse('cat');
$this->assertTrue(is_array($rawResult), 'Method getResponse() should return an array.');
}
}