it_should_not_allow_not_existing_translation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace spec\Akeneo\Crowdin\Api;
4
5
use Akeneo\Crowdin\Client;
6
use Akeneo\Crowdin\FileReader;
7
use GuzzleHttp\Client as HttpClient;
8
use GuzzleHttp\Psr7\Request;
9
use GuzzleHttp\Psr7\Response;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
13
class UploadTranslationSpec extends ObjectBehavior
14
{
15
    public function let(Client $client, HttpClient $http, FileReader $fileReader)
16
    {
17
        $client->getHttpClient()->willReturn($http);
18
        $client->getProjectIdentifier()->willReturn('sylius');
19
        $client->getProjectApiKey()->willReturn('1234');
20
        $this->beConstructedWith($client, $fileReader);
21
    }
22
23
    public function it_should_be_an_api()
24
    {
25
        $this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi');
26
    }
27
28
    public function it_should_not_allow_not_existing_translation()
29
    {
30
        $this->shouldThrow('\InvalidArgumentException')->duringAddTranslation('crowdin/path/file.yml', '/tmp/my-file.yml');
31
    }
32
33
    public function it_has_translations()
34
    {
35
        $this->addTranslation('spec/fixtures/messages.en.yml', 'crowdin/path/file.csv');
36
        $this->getTranslations()->shouldHaveCount(1);
37
    }
38
39
    public function it_does_not_import_duplicates_by_default()
40
    {
41
        $this->areDuplicatesImported()->shouldBe(false);
42
    }
43
44
    public function it_does_not_import_equal_suggestions_by_default()
45
    {
46
        $this->areEqualSuggestionsImported()->shouldBe(false);
47
    }
48
49
    public function it_does_not_auto_approve_imported_by_default()
50
    {
51
        $this->areImportsAutoApproved()->shouldBe(false);
52
    }
53
54
    public function it_should_not_allow_upload_with_no_translation(HttpClient $http, Request $request, Response $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        $this->setLocale('fr');
57
        $content = '<xml></xml>';
58
        $response->getBody()->willReturn($content);
59
        $http->post('project/sylius/upload-translation?key=1234')->willReturn($response);
60
61
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
62
    }
63
64
    public function it_should_not_allow_upload_with_no_locale(HttpClient $http, Request $request, Response $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
        $this->addTranslation('spec/fixtures/messages.en.yml', 'crowdin/path/file.yml');
67
        $content = '<xml></xml>';
68
        $response->getBody()->willReturn($content);
69
        $http->post('project/sylius/upload-translation?key=1234')->willReturn($response);
70
71
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
72
    }
73
74
    public function it_uploads_some_translations(FileReader $fileReader, HttpClient $http, Request $request, Response $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        $this->addTranslation('spec/fixtures/messages.en.yml', 'crowdin/path/file.yml');
77
        $this->setLocale('fr');
78
        $content = '<xml></xml>';
79
        $response->getBody()->willReturn($content);
80
        $fakeResource = '[fake resource]';
81
        $fileReader->readTranslation(Argument::any())->willReturn($fakeResource);
82
        $http->post(
83
            'project/sylius/upload-translation?key=1234',
84
            ['multipart' => [
85
                [
86
                    'name'      => 'import_duplicates',
87
                    'contents'  => 0
88
                ],
89
                [
90
                    'name'      => 'import_eq_suggestions',
91
                    'contents'  => 0
92
                ],
93
                [
94
                    'name'      => 'auto_approve_imported',
95
                    'contents'  => 0
96
                ],
97
                [
98
                    'name'      => 'language',
99
                    'contents'  => 'fr'
100
                ],
101
                [
102
                    'name'      => 'files[crowdin/path/file.yml]',
103
                    'contents'  => $fakeResource,
104
                ],
105
            ]]
106
        )->willReturn($response);
107
        $this->execute()->shouldBe($content);
108
    }
109
}
110