FontAwesomeTwigExtensionTest::test__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
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) 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\TwigFilter;
17
use Twig\TwigFunction;
18
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase;
19
use WBW\Bundle\CoreBundle\Twig\Extension\Assets\FontAwesomeTwigExtension;
20
21
/**
22
 * Font Awesome Twig extension test.
23
 *
24
 * @author webeweb <https://github.com/webeweb>
25
 * @package WBW\Bundle\CoreBundle\Tests\Twig\Extension\Assets
26
 */
27
class FontAwesomeTwigExtensionTest extends AbstractTestCase {
28
29
    /**
30
     * Test fontAwesomeIconFunction()
31
     *
32
     * @return void
33
     */
34
    public function testFontAwesomeIconFunction(): void {
35
36
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
37
38
        $arg = [
39
            "font"       => "s",
40
            "name"       => "camera-retro",
41
            "size"       => "lg",
42
            "fixedWidth" => true,
43
            "bordered"   => true,
44
            "pull"       => "left",
45
            "animation"  => "spin",
46
            "style"      => "color: #FFFFFF;",
47
        ];
48
        $exp = '<i class="fas fa-camera-retro fa-lg fa-fw fa-border fa-pull-left fa-spin" style="color: #FFFFFF;"></i>';
49
50
        $this->assertEquals($exp, $obj->fontAwesomeIconFunction($arg));
51
    }
52
53
    /**
54
     * Test fontAwesomeIconFunction()
55
     *
56
     * @return void
57
     */
58
    public function testFontAwesomeIconFunctionWithoutArguments(): void {
59
60
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
61
62
        $arg = [];
63
        $exp = '<i class="fa fa-home"></i>';
64
65
        $this->assertEquals($exp, $obj->fontAwesomeIconFunction($arg));
66
    }
67
68
    /**
69
     * Test fontAwesomeListFilter()
70
     *
71
     * @return void
72
     */
73
    public function testFontAwesomeListFilter(): void {
74
75
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
76
77
        $arg = $obj->fontAwesomeListIconFilter($obj->fontAwesomeIconFunction(), "content");
78
        $exp = '<ul class="fa-ul"><li><span class="fa-li"><i class="fa fa-home"></i></span>content</li></ul>';
79
80
        $this->assertEquals($exp, $obj->fontAwesomeListFilter($arg));
81
    }
82
83
    /**
84
     * Test fontAwesomeListIconFilter()
85
     *
86
     * @return void
87
     */
88
    public function testFontAwesomeListIconFilter(): void {
89
90
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
91
92
        $arg = $obj->fontAwesomeIconFunction();
93
        $exp = '<li><span class="fa-li"><i class="fa fa-home"></i></span></li>';
94
95
        $this->assertEquals($exp, $obj->fontAwesomeListIconFilter($arg, null));
96
    }
97
98
    /**
99
     * Test fontAwesomeListIconFilter()
100
     *
101
     * @return void
102
     */
103
    public function testFontAwesomeListIconFilterWithContent(): void {
104
105
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
106
107
        $arg = $obj->fontAwesomeIconFunction();
108
        $exp = '<li><span class="fa-li"><i class="fa fa-home"></i></span>content</li>';
109
110
        $this->assertEquals($exp, $obj->fontAwesomeListIconFilter($arg, "content"));
111
    }
112
113
    /**
114
     * Test getFilters()
115
     *
116
     * @return void
117
     */
118
    public function testGetFilters(): void {
119
120
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
121
122
        $res = $obj->getFilters();
123
        $this->assertCount(4, $res);
124
125
        $i = -1;
126
127
        $this->assertInstanceOf(TwigFilter::class, $res[++$i]);
128
        $this->assertEquals("fontAwesomeList", $res[$i]->getName());
129
        $this->assertEquals([$obj, "fontAwesomeListFilter"], $res[$i]->getCallable());
130
        $this->assertEquals(["html"], $res[$i]->getSafe(new Node()));
131
132
        $this->assertInstanceOf(TwigFilter::class, $res[++$i]);
133
        $this->assertEquals("faList", $res[$i]->getName());
134
        $this->assertEquals([$obj, "fontAwesomeListFilter"], $res[$i]->getCallable());
135
        $this->assertEquals(["html"], $res[$i]->getSafe(new Node()));
136
137
        $this->assertInstanceOf(TwigFilter::class, $res[++$i]);
138
        $this->assertEquals("fontAwesomeListIcon", $res[$i]->getName());
139
        $this->assertEquals([$obj, "fontAwesomeListIconFilter"], $res[$i]->getCallable());
140
        $this->assertEquals(["html"], $res[$i]->getSafe(new Node()));
141
142
        $this->assertInstanceOf(TwigFilter::class, $res[++$i]);
143
        $this->assertEquals("faListIcon", $res[$i]->getName());
144
        $this->assertEquals([$obj, "fontAwesomeListIconFilter"], $res[$i]->getCallable());
145
        $this->assertEquals(["html"], $res[$i]->getSafe(new Node()));
146
    }
147
148
    /**
149
     * Test getFunctions()
150
     *
151
     * @return void
152
     */
153
    public function testGetFunctions(): void {
154
155
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
156
157
        $res = $obj->getFunctions();
158
        $this->assertCount(2, $res);
159
160
        $i = -1;
161
162
        $this->assertInstanceOf(TwigFunction::class, $res[++$i]);
163
        $this->assertEquals("fontAwesomeIcon", $res[$i]->getName());
164
        $this->assertEquals([$obj, "fontAwesomeIconFunction"], $res[$i]->getCallable());
165
        $this->assertEquals(["html"], $res[$i]->getSafe(new Node()));
166
167
        $this->assertInstanceOf(TwigFunction::class, $res[++$i]);
168
        $this->assertEquals("faIcon", $res[$i]->getName());
169
        $this->assertEquals([$obj, "fontAwesomeIconFunction"], $res[$i]->getCallable());
170
        $this->assertEquals(["html"], $res[$i]->getSafe(new Node()));
171
    }
172
173
    /**
174
     * Test renderIcon()
175
     *
176
     * @return void
177
     */
178
    public function testRenderIcon(): void {
179
180
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
181
182
        $exp = '<i class="fa fa-camera-retro" style="color: #FFFFFF;"></i>';
183
184
        $this->assertEquals($exp, $obj->renderIcon("camera-retro", "color: #FFFFFF;"));
185
    }
186
187
    /**
188
     * Test __construct()
189
     *
190
     * @return void
191
     */
192
    public function test__construct(): void {
193
194
        $this->assertEquals("wbw.core.twig.extension.assets.font_awesome", FontAwesomeTwigExtension::SERVICE_NAME);
195
196
        $obj = new FontAwesomeTwigExtension($this->twigEnvironment);
197
198
        $this->assertInstanceOf(ExtensionInterface::class, $obj);
199
200
        $this->assertSame($this->twigEnvironment, $obj->getTwigEnvironment());
201
    }
202
}
203