Completed
Push — master ( e4a474...3a3d8d )
by Guillaume
02:43
created

TemplateControllerTest::testCGetInvalide()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 10
Ratio 76.92 %

Importance

Changes 0
Metric Value
dl 10
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Starkerxp\CampaignBundle\Tests\Manager;
4
5
use Starkerxp\StructureBundle\Test\WebTest;
6
7
class TemplateControllerTest extends WebTest
8
{
9
10
    /**
11
     * @group template
12
     * @group post
13
     * @group controller
14
     */
15 View Code Duplication
    public function testPostValide()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        $this->loadFixtureFiles(['@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml']);
18
19
        $data = [
20
            'name' => "Mon nom",
21
            'object' => "Mon sujet",
22
            'message' => "Mon message",
23
            'type' => "email",
24
        ];
25
        $client = $this->getAuthClient();
26
        $client->request('POST', '/api/templates', $data);
27
        $response = $client->getResponse();
28
        $this->assertEquals(201, $response->getStatusCode());
29
        $manager = $this->getContainer()->get('starkerxp_campaign.manager.template');
30
        $templates = $manager->findAll();
31
        $this->assertCount(1, $templates);
32
    }
33
34
    /**
35
     * @group template
36
     * @group post
37
     * @group controller
38
     */
39
    public function testPostInvalide()
40
    {
41
        $this->loadFixtureFiles(['@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml']);
42
        $client = $this->getAuthClient();
43
        $client->request('POST', '/api/templates', []);
44
        $response = $client->getResponse();
45
        $this->assertEquals(400, $response->getStatusCode());
46
        $body = json_decode($response->getContent(), true)['payload'];
47
        $this->assertArrayHasKey("name", $body);
48
        $this->assertArrayHasKey("object", $body);
49
        $this->assertArrayHasKey("message", $body);
50
        $this->assertArrayNotHasKey("type", $body);
51
    }
52
53
54
    /**
55
     * @group template
56
     * @group put
57
     * @group controller
58
     */
59
    public function testPutValide()
60
    {
61
        $this->loadFixtureFiles(
62
            [
63
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
64
65
                '@StarkerxpCampaignBundle/Tests/DataFixtures/TemplateManager/DefaultTemplate.yml',
66
            ]
67
        );
68
        $manager = $this->getContainer()->get('starkerxp_campaign.manager.template');
69
        $listeTemplates = $manager->getRepository()->findAll();
70
        $this->assertCount(1, $listeTemplates);
71
        $templateDepart = $manager->toArray($listeTemplates[0], ['name', 'object', 'message']);
72
        $data = [
73
            'name' => "Mon nom",
74
            'object' => "Mon sujet",
75
            'message' => "Mon message",
76
            'type' => "email",
77
        ];
78
        $client = $this->getAuthClient();
79
        $client->request('PUT', '/api/templates/'.$listeTemplates[0]->getId(), $data);
80
        $response = $client->getResponse();
81
        $this->assertEquals(204, $response->getStatusCode());
82
        $manager->clear();
83
        $templates = $manager->findAll();
84
        $this->assertCount(1, $templates);
85
        $templateFinal = $manager->toArray($templates[0], ['name', 'object', 'message', 'type']);
86
        $this->assertNotEquals($templateDepart, $templateFinal);
87
        $this->assertEquals($data, $templateFinal);
88
    }
89
90
    /**
91
     * @group template
92
     * @group put
93
     * @group controller
94
     */
95 View Code Duplication
    public function testPutInvalide()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $this->loadFixtureFiles(
98
            [
99
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
100
                '@StarkerxpCampaignBundle/Tests/DataFixtures/TemplateManager/DefaultTemplate.yml',
101
            ]
102
        );
103
        $manager = $this->getContainer()->get('starkerxp_campaign.manager.template');
104
        $listeTemplates = $manager->getRepository()->findAll();
105
        $this->assertCount(1, $listeTemplates);
106
        $client = $this->getAuthClient();
107
        $data = [
108
            "type" => "test",
109
        ];
110
        $client->request('PUT', '/api/templates/'.$listeTemplates[0]->getId(), $data);
111
        $response = $client->getResponse();
112
        $this->assertEquals(400, $response->getStatusCode());
113
        $body = json_decode($response->getContent(), true)['payload'];
114
        $this->assertArrayHasKey("type", $body);
115
    }
116
117
    /**
118
     * @group template
119
     * @group put
120
     * @group controller
121
     */
122
    public function testPutSansResultat()
123
    {
124
        $this->loadFixtureFiles(
125
            [
126
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
127
128
            ]
129
        );
130
        $data = [
131
            'name' => "Mon nom",
132
            'object' => "Mon sujet",
133
            'message' => "Mon message",
134
            'type' => "email",
135
        ];
136
        $client = $this->getAuthClient();
137
        $client->request('PUT', '/api/templates/404', $data);
138
        $response = $client->getResponse();
139
        $this->assertEquals(404, $response->getStatusCode());
140
        $body = json_decode($response->getContent(), true);
141
        $this->assertNotEmpty($body);
142
    }
143
144
145
    /**
146
     * @group template
147
     * @group cget
148
     * @group controller
149
     */
150
    public function testCGetValideAvecResultats()
151
    {
152
        $this->loadFixtureFiles(
153
            [
154
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
155
156
                '@StarkerxpCampaignBundle/Tests/DataFixtures/TemplateManager/TemplateManager.yml',
157
            ]
158
        );
159
        $client = $this->getAuthClient();
160
        $client->request('GET', '/api/templates', []);
161
        $response = $client->getResponse();
162
        $this->assertEquals(200, $response->getStatusCode());
163
        $body = json_decode($response->getContent(), true);
164
        $this->assertCount(10, $body);
165
        foreach ($body as $element) {
166
            $this->assertArrayHasKey("id", $element);
167
            $this->assertArrayHasKey("name", $element);
168
            $this->assertArrayHasKey("object", $element);
169
            $this->assertArrayHasKey("message", $element);
170
            $this->assertArrayHasKey("type", $element);
171
        }
172
    }
173
174
    /**
175
     * @group template
176
     * @group cget
177
     * @group controller
178
     */
179 View Code Duplication
    public function testCGetValideSansResultat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
180
    {
181
        $this->loadFixtureFiles(
182
            [
183
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
184
185
            ]
186
        );
187
        $client = $this->getAuthClient();
188
        $client->request('GET', '/api/templates', []);
189
        $response = $client->getResponse();
190
        $this->assertEquals(200, $response->getStatusCode());
191
        $body = json_decode($response->getContent(), true);
192
        $this->assertCount(0, $body);
193
    }
194
195
    /**
196
     * @group template
197
     * @group cget
198
     * @group controller
199
     */
200 View Code Duplication
    public function testCGetInvalide()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
201
    {
202
        $this->loadFixtureFiles(
203
            [
204
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
205
206
            ]
207
        );
208
        $client = $this->getAuthClient();
209
        $client->request('GET', '/api/templates', ["filter_erreur" => "+h"]);
210
        $response = $client->getResponse();
211
        $this->assertEquals(400, $response->getStatusCode());
212
    }
213
214
    /**
215
     * @group template
216
     * @group get
217
     * @group controller
218
     */
219
    public function testGetValideAvecResultats()
220
    {
221
        $this->loadFixtureFiles(
222
            [
223
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
224
225
                '@StarkerxpCampaignBundle/Tests/DataFixtures/TemplateManager/TemplateManager.yml',
226
            ]
227
        );
228
        $manager = $this->getContainer()->get('starkerxp_campaign.manager.template');
229
        $listeTemplates = $manager->getRepository()->findAll();
230
        $this->assertCount(10, $listeTemplates);
231
        $client = $this->getAuthClient();
232
        $client->request('GET', '/api/templates/'.$listeTemplates[0]->getId(), []);
233
        $response = $client->getResponse();
234
        $this->assertEquals(200, $response->getStatusCode());
235
        $body = json_decode($response->getContent(), true);
236
        $this->assertCount(5, $body);
237
        $this->assertArrayHasKey("id", $body);
238
        $this->assertArrayHasKey("name", $body);
239
        $this->assertArrayHasKey("object", $body);
240
        $this->assertArrayHasKey("message", $body);
241
        $this->assertArrayHasKey("type", $body);
242
    }
243
244
    /**
245
     * @group template
246
     * @group get
247
     * @group controller
248
     */
249 View Code Duplication
    public function testGetValideSansResultat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
    {
251
        $this->loadFixtureFiles(
252
            [
253
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
254
255
            ]
256
        );
257
        $client = $this->getAuthClient();
258
        $client->request('GET', '/api/templates/404', []);
259
        $response = $client->getResponse();
260
        $this->assertEquals(404, $response->getStatusCode());
261
        $body = json_decode($response->getContent(), true);
262
        $this->assertNotEmpty($body);
263
    }
264
265
    /**
266
     * @group template
267
     * @group get
268
     * @group controller
269
     */
270 View Code Duplication
    public function testGetInvalide()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
271
    {
272
        $this->loadFixtureFiles(
273
            [
274
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
275
276
            ]
277
        );
278
        $client = $this->getAuthClient();
279
        $client->request('GET', '/api/templates/500', ["filter_erreur" => "+h"]);
280
        $response = $client->getResponse();
281
        $this->assertEquals(400, $response->getStatusCode());
282
    }
283
284
    /**
285
     * @group template
286
     * @group delete
287
     * @group controller
288
     */
289 View Code Duplication
    public function testDeleteValide()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
290
    {
291
        $this->loadFixtureFiles(
292
            [
293
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
294
295
                '@StarkerxpCampaignBundle/Tests/DataFixtures/TemplateManager/DefaultTemplate.yml',
296
            ]
297
        );
298
        $manager = $this->getContainer()->get('starkerxp_campaign.manager.template');
299
        $listeTemplates = $manager->getRepository()->findAll();
300
        $this->assertCount(1, $listeTemplates);
301
        $client = $this->getAuthClient();
302
        $client->request('DELETE', '/api/templates/'.$listeTemplates[0]->getId());
303
        $response = $client->getResponse();
304
        $this->assertEquals(204, $response->getStatusCode());
305
        $manager->clear();
306
        $templates = $manager->findAll();
307
        $this->assertCount(0, $templates);
308
    }
309
310
    /**
311
     * @group template
312
     * @group delete
313
     * @group controller
314
     */
315 View Code Duplication
    public function testDeleteSansResultat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
316
    {
317
        $this->loadFixtureFiles(
318
            [
319
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
320
321
            ]
322
        );
323
        $client = $this->getAuthClient();
324
        $client->request('DELETE', '/api/templates/404', []);
325
        $response = $client->getResponse();
326
        $this->assertEquals(404, $response->getStatusCode());
327
        $body = json_decode($response->getContent(), true);
328
        $this->assertNotEmpty($body);
329
    }
330
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
331