LikeableControllerTest::testLike()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 9.248
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\KI\CoreBundle\Controller;
4
5
use Tests\KI\CoreBundle\WebTestCase;
6
7
// Tests généraux à toutes les classes
8
class LikeableControllerTest extends WebTestCase
9
{
10
    public function testLike()
11
    {
12
        $this->client->request('POST', '/newsitems/le-jeu/like');
13
        $response = $this->client->getResponse();
14
        $this->assertJsonResponse($response, 204);
15
16
        $this->client->request('GET', '/newsitems/le-jeu');
17
        $this->assertJsonResponse($this->client->getResponse(), 200);
18
        $response = json_decode($this->client->getResponse()->getContent(), true);
19
        $this->assertArrayHasKey('like', $response);
20
        $this->assertArrayHasKey('dislike', $response);
21
        $this->assertTrue($response['like']);
22
        $this->assertTrue(!$response['dislike']);
23
24
        $this->client->request('POST', '/newsitems/le-jeu/dislike');
25
        $response = $this->client->getResponse();
26
        $this->assertJsonResponse($response, 204);
27
28
        $this->client->request('GET', '/newsitems/le-jeu');
29
        $this->assertJsonResponse($this->client->getResponse(), 200);
30
        $response = json_decode($this->client->getResponse()->getContent(), true);
31
        $this->assertArrayHasKey('like', $response);
32
        $this->assertArrayHasKey('dislike', $response);
33
        $this->assertTrue(!$response['like']);
34
        $this->assertTrue($response['dislike']);
35
36
        $this->client->request('DELETE', '/newsitems/le-jeu/like');
37
        $response = $this->client->getResponse();
38
        $this->assertJsonResponse($response, 204);
39
40
        $this->client->request('DELETE', '/newsitems/le-jeu/dislike');
41
        $response = $this->client->getResponse();
42
        $this->assertJsonResponse($response, 204);
43
44
        $this->client->request('POST', '/courses/mecanique-des-structures/exercices/final-016/like');
45
        $response = $this->client->getResponse();
46
        $this->assertJsonResponse($response, 204);
47
48
        $this->client->request('DELETE', '/courses/mecanique-des-structures/exercices/final-016/like');
49
        $response = $this->client->getResponse();
50
        $this->assertJsonResponse($response, 204);
51
    }
52
}
53