Completed
Pull Request — master (#31)
by
unknown
02:06
created

UploadTranslationSpec::it_has_translations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace spec\Akeneo\Crowdin\Api;
4
5
use Akeneo\Crowdin\Client;
6
use GuzzleHttp\Client as HttpClient;
7
use GuzzleHttp\Psr7\Request;
8
use GuzzleHttp\Psr7\Response;
9
use PhpSpec\ObjectBehavior;
10
use Prophecy\Argument;
11
12
class UploadTranslationSpec extends ObjectBehavior
13
{
14
    public 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
    public function it_should_be_an_api()
23
    {
24
        $this->shouldBeAnInstanceOf('Akeneo\Crowdin\Api\AbstractApi');
25
    }
26
27
    public 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
    public 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
    public function it_does_not_import_duplicates_by_default()
39
    {
40
        $this->areDuplicatesImported()->shouldBe(false);
41
    }
42
43
    public function it_does_not_import_equal_suggestions_by_default()
44
    {
45
        $this->areEqualSuggestionsImported()->shouldBe(false);
46
    }
47
48
    public function it_does_not_auto_approve_imported_by_default()
49
    {
50
        $this->areImportsAutoApproved()->shouldBe(false);
51
    }
52
53
    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...
54
    {
55
        $this->setLocale('fr');
56
        $content = '<xml></xml>';
57
        $response->getBody()->willReturn($content);
58
        $http->post('project/sylius/upload-translation?key=1234')->willReturn($response);
59
60
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
61
    }
62
63
    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...
64
    {
65
        $this->addTranslation('crowdin/path/file.yml',  'spec/fixtures/messages.en.yml');
66
        $content = '<xml></xml>';
67
        $response->getBody()->willReturn($content);
68
        $http->post('project/sylius/upload-translation?key=1234')->willReturn($response);
69
70
        $this->shouldThrow('\InvalidArgumentException')->duringExecute();
71
    }
72
73
    public function it_uploads_some_translations(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...
74
    {
75
        $this->addTranslation('crowdin/path/file.yml',  'spec/fixtures/messages.en.yml');
76
        $this->setLocale('fr');
77
        $content = '<xml></xml>';
78
        $response->getBody()->willReturn($content);
79
        $http->post(
80
            'project/sylius/upload-translation?key=1234',
81
            ['multipart' => [
82
                [
83
                    'name'      => 'files[crowdin/path/file.yml]',
84
                    'contents'  => '@spec/fixtures/messages.en.yml',
85
                ],
86
                [
87
                    'name'      => 'import_duplicates',
88
                    'contents'  => 0
89
                ],
90
                [
91
                    'name'      => 'import_eq_suggestions',
92
                    'contents'  => 0
93
                ],
94
                [
95
                    'name'      => 'auto_approve_imported',
96
                    'contents'  => 0
97
                ],
98
                [
99
                    'name'      => 'language',
100
                    'contents'  => 'fr'
101
                ],
102
            ]]
103
        )->willReturn($response);
104
        $this->execute()->shouldBe($content);
105
    }
106
}
107