|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Akeneo\Crowdin\Api; |
|
4
|
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
use Prophecy\Argument; |
|
7
|
|
|
use Akeneo\Crowdin\Client; |
|
8
|
|
|
use Guzzle\Http\Client as HttpClient; |
|
9
|
|
|
use Guzzle\Http\Message\Response; |
|
10
|
|
|
use Guzzle\Http\Message\Request; |
|
11
|
|
|
|
|
12
|
|
|
class UploadTranslationSpec extends ObjectBehavior |
|
13
|
|
|
{ |
|
14
|
|
|
function let(Client $client, HttpClient $http) |
|
15
|
|
|
{ |
|
16
|
|
|
$client->getHttpClient()->willReturn($http); |
|
17
|
|
|
$client->getProjectIdentifier()->willReturn('sylius'); |
|
18
|
|
|
$client->getProjectApiKey()->willReturn('1234'); |
|
19
|
|
|
$this->beConstructedWith($client); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
function it_should_be_an_api() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function it_should_not_allow_not_existing_translation() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->shouldThrow('\InvalidArgumentException')->duringAddTranslation('crowdin/path/file.yml', '/tmp/my-file.yml'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function it_has_translations() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->addTranslation('crowdin/path/file.csv', 'spec/fixtures/messages.en.yml'); |
|
35
|
|
|
$this->getTranslations()->shouldHaveCount(1); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_does_not_import_duplicates_by_default() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->areDuplicatesImported()->shouldBe(false); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
function it_does_not_import_equal_suggestions_by_default() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->areEqualSuggestionsImported()->shouldBe(false); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_does_not_auto_approve_imported_by_default() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->areImportsAutoApproved()->shouldBe(false); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_should_not_allow_upload_with_no_translation(HttpClient $http, Request $request, Response $response) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->setLocale('fr'); |
|
56
|
|
|
$content = '<xml></xml>'; |
|
57
|
|
|
$response->getBody(true)->willReturn($content); |
|
58
|
|
|
$request->send()->willReturn($response); |
|
59
|
|
|
$http->post('project/sylius/upload-translation?key=1234')->willReturn($request); |
|
60
|
|
|
|
|
61
|
|
|
$this->shouldThrow('\InvalidArgumentException')->duringExecute(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
function it_should_not_allow_upload_with_no_locale(HttpClient $http, Request $request, Response $response) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->addTranslation('crowdin/path/file.yml', 'spec/fixtures/messages.en.yml'); |
|
67
|
|
|
$content = '<xml></xml>'; |
|
68
|
|
|
$response->getBody(true)->willReturn($content); |
|
69
|
|
|
$request->send()->willReturn($response); |
|
70
|
|
|
$http->post('project/sylius/upload-translation?key=1234')->willReturn($request); |
|
71
|
|
|
|
|
72
|
|
|
$this->shouldThrow('\InvalidArgumentException')->duringExecute(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
function it_uploads_some_translations(HttpClient $http, Request $request, Response $response) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->addTranslation('crowdin/path/file.yml', 'spec/fixtures/messages.en.yml'); |
|
78
|
|
|
$this->setLocale('fr'); |
|
79
|
|
|
$content = '<xml></xml>'; |
|
80
|
|
|
$response->getBody(true)->willReturn($content); |
|
81
|
|
|
$request->send()->willReturn($response); |
|
82
|
|
|
$http->post( |
|
83
|
|
|
'project/sylius/upload-translation?key=1234', |
|
84
|
|
|
array(), |
|
85
|
|
|
array( |
|
86
|
|
|
'files[crowdin/path/file.yml]' => '@spec/fixtures/messages.en.yml', |
|
87
|
|
|
'import_duplicates' => 0, |
|
88
|
|
|
'import_eq_suggestions' => 0, |
|
89
|
|
|
'auto_approve_imported' => 0, |
|
90
|
|
|
'language' => 'fr', |
|
91
|
|
|
) |
|
92
|
|
|
)->willReturn($request); |
|
93
|
|
|
$this->execute()->shouldBe($content); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|