testFunctionActionWithStatus404()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2021 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Tests\Controller;
13
14
use WBW\Bundle\CoreBundle\Controller\TwigController;
15
use WBW\Bundle\CoreBundle\Tests\AbstractWebTestCase;
16
17
/**
18
 * Twig controller test.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Bundle\CoreBundle\Tests\Controller
22
 */
23
class TwigControllerTest extends AbstractWebTestCase {
24
25
    /**
26
     * Test functionAction()
27
     *
28
     * @return void
29
     */
30
    public function testFunctionAction(): void {
31
32
        $arg = ["font" => "s", "name" => "camera-retro", "size" => "lg", "fixedWidth" => true, "bordered" => true, "pull" => "left", "animation" => "spin", "style" => "color: #FFFFFF;"];
33
        $exp = '<i class="fas fa-camera-retro fa-lg fa-fw fa-border fa-pull-left fa-spin" style="color: #FFFFFF;"></i>';
34
35
        $client = $this->client;
36
37
        $client->request("POST", "/twig/function/fontAwesomeIcon", ["args" => [$arg]]);
38
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
39
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
40
41
        // Check the JSON response.
42
        $res = json_decode($client->getResponse()->getContent(), true);
43
44
        $this->assertEquals($exp, $res[0]);
45
    }
46
47
    /**
48
     * Test functionAction()
49
     *
50
     * @return void
51
     */
52
    public function testFunctionActionWithStatus404(): void {
53
54
        $client = $this->client;
55
56
        $client->request("POST", "/twig/function/exception");
57
        $this->assertEquals(404, $client->getResponse()->getStatusCode());
58
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
59
    }
60
61
    /**
62
     * Test resourceAction()
63
     *
64
     * @return void
65
     */
66
    public function testResourceAction(): void {
67
68
        $client = $this->client;
69
70
        $client->request("GET", "/twig/resource/404.js");
71
        $this->assertEquals(404, $client->getResponse()->getStatusCode());
72
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
73
    }
74
75
    /**
76
     * Test resourceAction()
77
     *
78
     * @return void
79
     */
80
    public function testResourceActionWithJavascript(): void {
81
82
        $client = $this->client;
83
84
        $client->request("GET", "/twig/resource/WBWCoreLeaflet.js");
85
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
86
        $this->assertEquals("application/javascript", $client->getResponse()->headers->get("Content-Type"));
87
        $this->assertNotNull($client->getResponse()->headers->get("Last-Modified"));
88
    }
89
90
    /**
91
     * Test resourceAction()
92
     *
93
     * @return void
94
     */
95
    public function testResourceActionWithStylesheet(): void {
96
97
        $client = $this->client;
98
99
        $client->request("GET", "/twig/resource/WBWCoreTest.css");
100
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
101
        $this->assertEquals("text/css; charset=utf-8", $client->getResponse()->headers->get("Content-Type"));
102
        $this->assertNotNull($client->getResponse()->headers->get("Last-Modified"));
103
    }
104
105
    /**
106
     * Test __construct()
107
     *
108
     * @return void
109
     */
110
    public function test__construct(): void {
111
112
        $this->assertEquals("wbw.core.controller.twig", TwigController::SERVICE_NAME);
113
    }
114
}
115