MeteoconsTwigExtensionTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 39
dl 0
loc 130
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A test__construct() 0 9 1
A testMeteoconsIconFunctionWithoutArguments() 0 8 1
A testMeteoconsIconFunctionWithStyle() 0 10 1
A testGetFunctions() 0 13 1
A testGetFilters() 0 6 1
A testMeteoconsIconFunction() 0 11 1
A testMeteoconsIconFunctionWithName() 0 10 1
A testRenderIcon() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2018 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\Twig\Extension\Assets;
13
14
use Twig\Extension\ExtensionInterface;
15
use Twig\Node\Node;
16
use Twig\TwigFunction;
17
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase;
18
use WBW\Bundle\CoreBundle\Twig\Extension\Assets\MeteoconsTwigExtension;
19
20
/**
21
 * Meteocons Twig extension test.
22
 *
23
 * @author webeweb <https://github.com/webeweb>
24
 * @package WBW\Bundle\CoreBundle\Tests\Twig\Extension\Assets
25
 */
26
class MeteoconsTwigExtensionTest extends AbstractTestCase {
27
28
    /**
29
     * Test getFilters()
30
     *
31
     * @return void
32
     */
33
    public function testGetFilters(): void {
34
35
        $obj = new MeteoconsTwigExtension($this->twigEnvironment);
36
37
        $res = $obj->getFilters();
38
        $this->assertCount(0, $res);
39
    }
40
41
    /**
42
     * Test getFunctions()
43
     *
44
     * @return void
45
     */
46
    public function testGetFunctions(): void {
47
48
        $obj = new MeteoconsTwigExtension($this->twigEnvironment);
49
50
        $res = $obj->getFunctions();
51
        $this->assertCount(1, $res);
52
53
        $i = -1;
54
55
        $this->assertInstanceOf(TwigFunction::class, $res[++$i]);
56
        $this->assertEquals("meteoconsIcon", $res[$i]->getName());
57
        $this->assertEquals([$obj, "meteoconsIconFunction"], $res[$i]->getCallable());
58
        $this->assertEquals(["html"], $res[$i]->getSafe(new Node()));
59
    }
60
61
    /**
62
     * Test meteoconsIconFunction()
63
     *
64
     * @return void
65
     */
66
    public function testMeteoconsIconFunction(): void {
67
68
        $obj = new MeteoconsTwigExtension($this->twigEnvironment);
69
70
        $arg = [
71
            "name"  => "B",
72
            "style" => "color: #FFFFFF;",
73
        ];
74
        $exp = '<i class="meteocons" data-meteocons="B" style="color: #FFFFFF;"></i>';
75
76
        $this->assertEquals($exp, $obj->meteoconsIconFunction($arg));
77
    }
78
79
    /**
80
     * Test meteoconsIconFunction()
81
     *
82
     * @return void
83
     */
84
    public function testMeteoconsIconFunctionWithName(): void {
85
86
        $obj = new MeteoconsTwigExtension($this->twigEnvironment);
87
88
        $arg = [
89
            "name" => "B",
90
        ];
91
        $exp = '<i class="meteocons" data-meteocons="B"></i>';
92
93
        $this->assertEquals($exp, $obj->meteoconsIconFunction($arg));
94
    }
95
96
    /**
97
     * Test meteoconsIconFunction()
98
     *
99
     * @return void
100
     */
101
    public function testMeteoconsIconFunctionWithStyle(): void {
102
103
        $obj = new MeteoconsTwigExtension($this->twigEnvironment);
104
105
        $arg = [
106
            "style" => "color: #FFFFFF;",
107
        ];
108
        $exp = '<i class="meteocons" data-meteocons="A" style="color: #FFFFFF;"></i>';
109
110
        $this->assertEquals($exp, $obj->meteoconsIconFunction($arg));
111
    }
112
113
    /**
114
     * Test meteoconsIconFunction()
115
     *
116
     * @return void
117
     */
118
    public function testMeteoconsIconFunctionWithoutArguments(): void {
119
120
        $obj = new MeteoconsTwigExtension($this->twigEnvironment);
121
122
        $arg = [];
123
        $exp = '<i class="meteocons" data-meteocons="A"></i>';
124
125
        $this->assertEquals($exp, $obj->meteoconsIconFunction($arg));
126
    }
127
128
    /**
129
     * Test renderIcon()
130
     *
131
     * @return void
132
     */
133
    public function testRenderIcon(): void {
134
135
        $obj = new MeteoconsTwigExtension($this->twigEnvironment);
136
137
        $exp = '<i class="meteocons" data-meteocons="B" style="color: #FFFFFF;"></i>';
138
139
        $this->assertEquals($exp, $obj->renderIcon("B", "color: #FFFFFF;"));
140
    }
141
142
    /**
143
     * Test __construct()
144
     *
145
     * @return void
146
     */
147
    public function test__construct(): void {
148
149
        $this->assertEquals("wbw.core.twig.extension.assets.meteocons", MeteoconsTwigExtension::SERVICE_NAME);
150
151
        $obj = new MeteoconsTwigExtension($this->twigEnvironment);
152
153
        $this->assertInstanceOf(ExtensionInterface::class, $obj);
154
155
        $this->assertSame($this->twigEnvironment, $obj->getTwigEnvironment());
156
    }
157
}
158