Completed
Push — master ( 9c3bdf...25b499 )
by Lucas
25:24 queued 15:40
created

TranslatableRequiredTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 113
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testPutWithAcceptableTranslatableRequests() 0 8 1
A testPutMethodIncludeRequiredTranslatable() 0 9 1
B acceptableDataProvider() 0 24 1
B unacceptableDataProvider() 0 36 1
1
<?php
2
/**
3
 * TranslatableRequiredTest class file
4
 */
5
6
namespace Graviton\CoreBundle\Tests\Controller;
7
8
use Graviton\TestBundle\Test\RestTestCase;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
13
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
14
 * @link     http://swisscom.ch
15
 */
16
class TranslatableRequiredTest extends RestTestCase
17
{
18
19
    /**
20
     * test stuff that the backend should accept
21
     *
22
     * @dataProvider acceptableDataProvider
23
     *
24
     * @param array $data data to post
25
     *
26
     * @return void
27
     */
28
    public function testPutWithAcceptableTranslatableRequests($data)
29
    {
30
        $client = static::createRestClient();
31
        $client->put('/testcase/translatable-required/testdata', $data);
32
33
        $this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode());
34
        $this->assertEmpty($client->getResults());
35
    }
36
37
    /**
38
     * test stuff that the backend should accept
39
     *
40
     * @dataProvider unacceptableDataProvider
41
     *
42
     * @param array  $data          data to post
43
     * @param string $complainField field to complain about
44
     *
45
     * @return void
46
     */
47
    public function testPutMethodIncludeRequiredTranslatable($data, $complainField)
48
    {
49
        $client = static::createRestClient();
50
        $client->put('/testcase/translatable-required/testdata', $data);
51
52
        $this->assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
53
        $this->assertSame('children['.$complainField.']', $client->getResults()[0]->propertyPath);
54
        $this->assertSame('This value is not valid.', $client->getResults()[0]->message);
55
    }
56
57
    /**
58
     * Posts that the backend shall accept
59
     *
60
     * @return array data
61
     */
62
    public function acceptableDataProvider()
63
    {
64
        return [
65
            'omit-optional' => [
66
                'data' => [
67
                    'id' => 'testdata',
68
                    'required' => [
69
                        'en' => 'Test'
70
                    ]
71
                ]
72
            ],
73
            'with-optional' => [
74
                'data' => [
75
                    'id' => 'testdata',
76
                    'optional' => [
77
                        'en' => 'Test'
78
                    ]        ,
79
                    'required' => [
80
                        'en' => 'Test'
81
                    ]
82
                ]
83
            ]
84
        ];
85
    }
86
87
    /**
88
     * Posts that the backend shall NOT accept
89
     *
90
     * @return array data
91
     */
92
    public function unacceptableDataProvider()
93
    {
94
        return [
95
            'omit-required' => [
96
                'data' => [
97
                    'id' => 'testdata',
98
                    'optional' => [
99
                        'en' => 'Test'
100
                    ]
101
                ],
102
                'complainField' => 'required'
103
            ],
104
            'empty-optional' => [
105
                'data' => [
106
                    'id' => 'testdata',
107
                    'optional' => [],
108
                    'required' => [
109
                        'en' => 'Test'
110
                    ]
111
                ],
112
                'complainField' => 'optional'
113
            ],
114
            'empty-no-default' => [
115
                'data' => [
116
                    'id' => 'testdata',
117
                    'optional' => [
118
                        'es' => 'Vamos a la playa'
119
                    ],
120
                    'required' => [
121
                        'en' => 'Test'
122
                    ]
123
                ],
124
                'complainField' => 'optional'
125
            ]
126
        ];
127
    }
128
}
129