EventsControllerTest::testGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\KI\PublicationBundle\Controller;
4
5
use Tests\KI\CoreBundle\WebTestCase;
6
7
class EventsControllerTest extends WebTestCase
8
{
9
    // On crée une ressource sur laquelle seront effectués les tests.
10
    // Ne pas oublier de supprimer à la fin avec le test DELETE.
11
    public function testPost()
12
    {
13
        $this->client->request('POST', '/events', [
14
            'name' => 'Manger des chips',
15
            'text' => 'C\'est bon',
16
            'startDate' => 151515,
17
            'endDate' => 314159,
18
            'entryMethod' => 'libre',
19
            'place' => 'DTC',
20
            'sendMail' => true,
21
            'authorClub' => 'bde',
22
        ]);
23
        $response = $this->client->getResponse();
24
        $this->assertJsonResponse($response, 201);
25
26
        // On vérifie qu'un mail a été envoyé
27
        $mailCollector = $this->client->getProfile()->getCollector('swiftmailer');
28
        $this->assertEquals(2, $mailCollector->getMessageCount());
29
30
        $collectedMessages = $mailCollector->getMessages();
31
        $message = $collectedMessages[0];
32
33
        // On vérifie le message
34
        $this->assertInstanceOf('Swift_Message', $message);
35
        $this->assertTrue(!empty($message->getSubject()));
36
        $this->assertEquals('[email protected]', key($message->getFrom()));
37
    }
38
39 View Code Duplication
    public function testGet()
40
    {
41
        $this->client->request('GET', '/events');
42
        $response = $this->client->getResponse();
43
        $this->assertJsonResponse($response, 200);
44
45
        $this->client->request('GET', '/events/manger-des-chips');
46
        $response = $this->client->getResponse();
47
        $this->assertJsonResponse($response, 200);
48
49
        $this->client->request('GET', '/events/manger-des-chips/attendees');
50
        $response = $this->client->getResponse();
51
        $this->assertJsonResponse($response, 200);
52
53
        $this->client->request('GET', '/events/manger-des-chips/pookies');
54
        $response = $this->client->getResponse();
55
        $this->assertJsonResponse($response, 200);
56
57
        $this->client->request('GET', '/events/sjoajsiohaysahais-asbsksaba7');
58
        $response = $this->client->getResponse();
59
        $this->assertJsonResponse($response, 404);
60
    }
61
62
    public function testPatch()
63
    {
64
        $this->client->request(
65
            'PATCH',
66
            '/events/manger-des-chips',
67
            ['endDate' => 12345]
68
        );
69
        $response = $this->client->getResponse();
70
        $this->assertJsonResponse($response, 204);
71
72
        $this->client->request(
73
            'PATCH',
74
            '/events/manger-des-chips',
75
            ['text' => '']
76
        );
77
        $response = $this->client->getResponse();
78
        $this->assertJsonResponse($response, 400);
79
80
        $this->client->request(
81
            'PATCH',
82
            '/events/sjoajsiohaysahais-asbsksaba7',
83
            ['username' => 'miam', 'email' => '[email protected]']
84
        );
85
        $response = $this->client->getResponse();
86
        $this->assertJsonResponse($response, 404);
87
    }
88
89 View Code Duplication
    public function testAttend()
90
    {
91
        $this->client->request('POST', '/events/manger-des-chips/attend');
92
        $response = $this->client->getResponse();
93
        $this->assertJsonResponse($response, 204);
94
95
        $this->client->request('DELETE', '/events/manger-des-chips/attend');
96
        $response = $this->client->getResponse();
97
        $this->assertJsonResponse($response, 204);
98
99
        $this->client->request('POST', '/events/manger-des-chips/decline');
100
        $response = $this->client->getResponse();
101
        $this->assertJsonResponse($response, 204);
102
103
        $this->client->request('DELETE', '/events/manger-des-chips/decline');
104
        $response = $this->client->getResponse();
105
        $this->assertJsonResponse($response, 204);
106
107
        $this->client->request('DELETE', '/events/manger-des-chips/decline');
108
        $response = $this->client->getResponse();
109
        $this->assertJsonResponse($response, 400);
110
    }
111
112 View Code Duplication
    public function testDelete()
113
    {
114
        $this->client->request('DELETE', '/events/manger-des-chips');
115
        $response = $this->client->getResponse();
116
        $this->assertJsonResponse($response, 204);
117
118
        $this->client->request('DELETE', '/events/manger-des-chips');
119
        $response = $this->client->getResponse();
120
        $this->assertJsonResponse($response, 404);
121
    }
122
123
    //Tests relatifs au shotgun
124
125
    public function testPostShotgunEvent()
126
    {
127
        $this->client->request('POST', '/events', [
128
            'name' => 'Semaine Ski',
129
            'text' => 'Il fait froid',
130
            'startDate' => 151515,
131
            'endDate' => 31415,
132
            'entryMethod' => 'Shotgun',
133
            'shotgunDate' => 101010,
134
            'shotgunLimit' => 1,
135
            'shotgunText' => 'Il est deux heures du matin, et tout va bien',
136
            'place' => 'Far Far Away',
137
            'sendMail' => true,
138
        ]);
139
        $response = $this->client->getResponse();
140
        $this->assertJsonResponse($response, 201);
141
    }
142
143
    public function testPostShotgun()
144
    {
145
        $this->client->request(
146
            'POST',
147
            '/events/semaine-ski/shotgun',
148
            ['motivation' => 'moimoimoimoi']
149
        );
150
        $response = $this->client->getResponse();
151
        $this->assertJsonResponse($response, 204);
152
    }
153
154
    public function testPatchShotgun()
155
    {
156
        $this->client->request('PATCH', '/events/semaine-ski/shotgun', ['motivation' => 'lolololol']);
157
        $response = $this->client->getResponse();
158
        $this->assertJsonResponse($response, 204);
159
160
        $this->client->request('PATCH', '/events/semaine-ski/shotgun', []);
161
        $response = $this->client->getResponse();
162
        $this->assertJsonResponse($response, 400);
163
164
        $this->client->request('PATCH', '/events/dfsgjkdnv/shotgun', ['motivation' => 'miam']);
165
        $response = $this->client->getResponse();
166
        $this->assertJsonResponse($response, 404);
167
    }
168
169
    public function testGetShotgun()
170
    {
171
        $this->client->request('GET', '/events/semaine-ski/shotgun');
172
        $response = $this->client->getResponse();
173
        $this->assertJsonResponse($response, 200);
174
        $results = json_decode($response->getContent(), true);
175
        $this->assertNotEquals($results, null);
176
        $this->assertArrayHasKey('status', $results);
177
        $this->assertArrayHasKey('fail', $results);
178
        $this->assertArrayHasKey('limit', $results);
179
        $this->assertArrayHasKey('shotgunText', $results);
180
    }
181
182 View Code Duplication
    public function testDeleteShotgun()
183
    {
184
        $this->client->request('DELETE', '/events/semaine-ski/shotgun');
185
        $response = $this->client->getResponse();
186
        $this->assertJsonResponse($response, 204);
187
188
        $this->client->request('DELETE', '/events/semaine-ski/shotgun');
189
        $response = $this->client->getResponse();
190
        $this->assertJsonResponse($response, 404);
191
    }
192
193
    public function testDeleteShotgunEvent()
194
    {
195
        $this->client->request('DELETE', '/events/semaine-ski');
196
        $response = $this->client->getResponse();
197
        $this->assertJsonResponse($response, 204);
198
    }
199
}
200