1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the syntaxhighligter-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2017 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\SyntaxHighlighterBundle\Tests\Twig\Extension; |
13
|
|
|
|
14
|
|
|
use Exception; |
15
|
|
|
use PHPUnit_Framework_TestCase; |
16
|
|
|
use Twig_Node; |
17
|
|
|
use Twig_SimpleFunction; |
18
|
|
|
use WBW\Bundle\SyntaxHighlighterBundle\Twig\Extension\SyntaxHighlighterTwigExtension; |
19
|
|
|
use WBW\Library\Core\Exception\File\FileNotFoundException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* SyntaxHighlighter Twig extension test. |
23
|
|
|
* |
24
|
|
|
* @author webeweb <https://github.com/webeweb/> |
25
|
|
|
* @package WBW\Bundle\SyntaxHighlighterBundle\Tests\Twig\Extension |
26
|
|
|
* @version 2.4.3 |
27
|
|
|
* @final |
28
|
|
|
*/ |
29
|
|
|
final class SyntaxHighlighterTwigExtensionTest extends PHPUnit_Framework_TestCase { |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Tests the getFunctions() method. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function testGetFunctions() { |
37
|
|
|
|
38
|
|
|
$obj = new SyntaxHighlighterTwigExtension(getcwd()); |
39
|
|
|
|
40
|
|
|
$this->assertCount(2, $obj->getFunctions()); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf(Twig_SimpleFunction::class, $obj->getFunctions()[0]); |
43
|
|
|
$this->assertEquals("syntaxHighlighterScript", $obj->getFunctions()[0]->getName()); |
44
|
|
|
$this->assertEquals([$obj, "syntaxHighlighterScriptFunction"], $obj->getFunctions()[0]->getCallable()); |
45
|
|
|
$this->assertEquals(["html"], $obj->getFunctions()[0]->getSafe(new Twig_Node())); |
46
|
|
|
|
47
|
|
|
$this->assertInstanceOf(Twig_SimpleFunction::class, $obj->getFunctions()[1]); |
48
|
|
|
$this->assertEquals("syntaxHighlighterStyle", $obj->getFunctions()[1]->getName()); |
49
|
|
|
$this->assertEquals([$obj, "syntaxHighlighterStyleFunction"], $obj->getFunctions()[1]->getCallable()); |
50
|
|
|
$this->assertEquals(["html"], $obj->getFunctions()[1]->getSafe(new Twig_Node())); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Tests the syntaxHighlighterScriptFunction() method. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
public function testSyntaxHighlighterScriptFunction() { |
59
|
|
|
|
60
|
|
|
$obj = new SyntaxHighlighterTwigExtension(getcwd()); |
61
|
|
|
|
62
|
|
|
try { |
63
|
|
|
$obj->syntaxHighlighterScriptFunction("exception"); |
64
|
|
|
} catch (Exception $ex) { |
65
|
|
|
$this->assertInstanceOf(FileNotFoundException::class, $ex); |
66
|
|
|
$this->assertEquals("The file \"syntaxhighlighter-3.0.83/scripts/exception.js\" is not found", $ex->getMessage()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$res1 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shCore.js\" type=\"text/javascript\"></script>"; |
70
|
|
|
$this->assertEquals($res1, $obj->syntaxHighlighterScriptFunction("shCore")); |
71
|
|
|
|
72
|
|
|
$res2 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shLegacy.js\" type=\"text/javascript\"></script>"; |
73
|
|
|
$this->assertEquals($res2, $obj->syntaxHighlighterScriptFunction("shLegacy")); |
74
|
|
|
|
75
|
|
|
$res3 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/XRegExp.js\" type=\"text/javascript\"></script>"; |
76
|
|
|
$this->assertEquals($res3, $obj->syntaxHighlighterScriptFunction("XRegExp")); |
77
|
|
|
|
78
|
|
|
$resB1 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushAS3.js\" type=\"text/javascript\"></script>"; |
79
|
|
|
$this->assertEquals($resB1, $obj->syntaxHighlighterScriptFunction("shBrushAS3")); |
80
|
|
|
|
81
|
|
|
$resB2 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushAppleScript.js\" type=\"text/javascript\"></script>"; |
82
|
|
|
$this->assertEquals($resB2, $obj->syntaxHighlighterScriptFunction("shBrushAppleScript")); |
83
|
|
|
|
84
|
|
|
$resB3 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushBash.js\" type=\"text/javascript\"></script>"; |
85
|
|
|
$this->assertEquals($resB3, $obj->syntaxHighlighterScriptFunction("shBrushBash")); |
86
|
|
|
|
87
|
|
|
$resB4 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushCSharp.js\" type=\"text/javascript\"></script>"; |
88
|
|
|
$this->assertEquals($resB4, $obj->syntaxHighlighterScriptFunction("shBrushCSharp")); |
89
|
|
|
|
90
|
|
|
$resB5 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushColdFusion.js\" type=\"text/javascript\"></script>"; |
91
|
|
|
$this->assertEquals($resB5, $obj->syntaxHighlighterScriptFunction("shBrushColdFusion")); |
92
|
|
|
|
93
|
|
|
$resB6 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushCpp.js\" type=\"text/javascript\"></script>"; |
94
|
|
|
$this->assertEquals($resB6, $obj->syntaxHighlighterScriptFunction("shBrushCpp")); |
95
|
|
|
|
96
|
|
|
$resB7 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushCss.js\" type=\"text/javascript\"></script>"; |
97
|
|
|
$this->assertEquals($resB7, $obj->syntaxHighlighterScriptFunction("shBrushCss")); |
98
|
|
|
|
99
|
|
|
$resB8 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushDelphi.js\" type=\"text/javascript\"></script>"; |
100
|
|
|
$this->assertEquals($resB8, $obj->syntaxHighlighterScriptFunction("shBrushDelphi")); |
101
|
|
|
|
102
|
|
|
$resB9 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushDiff.js\" type=\"text/javascript\"></script>"; |
103
|
|
|
$this->assertEquals($resB9, $obj->syntaxHighlighterScriptFunction("shBrushDiff")); |
104
|
|
|
|
105
|
|
|
$resB10 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushErlang.js\" type=\"text/javascript\"></script>"; |
106
|
|
|
$this->assertEquals($resB10, $obj->syntaxHighlighterScriptFunction("shBrushErlang")); |
107
|
|
|
|
108
|
|
|
$resB11 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushGroovy.js\" type=\"text/javascript\"></script>"; |
109
|
|
|
$this->assertEquals($resB11, $obj->syntaxHighlighterScriptFunction("shBrushGroovy")); |
110
|
|
|
|
111
|
|
|
$resB12 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushJScript.js\" type=\"text/javascript\"></script>"; |
112
|
|
|
$this->assertEquals($resB12, $obj->syntaxHighlighterScriptFunction("shBrushJScript")); |
113
|
|
|
|
114
|
|
|
$resB13 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushJava.js\" type=\"text/javascript\"></script>"; |
115
|
|
|
$this->assertEquals($resB13, $obj->syntaxHighlighterScriptFunction("shBrushJava")); |
116
|
|
|
|
117
|
|
|
$resB14 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushJavaFX.js\" type=\"text/javascript\"></script>"; |
118
|
|
|
$this->assertEquals($resB14, $obj->syntaxHighlighterScriptFunction("shBrushJavaFX")); |
119
|
|
|
|
120
|
|
|
$resB15 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushPerl.js\" type=\"text/javascript\"></script>"; |
121
|
|
|
$this->assertEquals($resB15, $obj->syntaxHighlighterScriptFunction("shBrushPerl")); |
122
|
|
|
|
123
|
|
|
$resB16 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushPhp.js\" type=\"text/javascript\"></script>"; |
124
|
|
|
$this->assertEquals($resB16, $obj->syntaxHighlighterScriptFunction("shBrushPhp")); |
125
|
|
|
|
126
|
|
|
$resB17 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushPlain.js\" type=\"text/javascript\"></script>"; |
127
|
|
|
$this->assertEquals($resB17, $obj->syntaxHighlighterScriptFunction("shBrushPlain")); |
128
|
|
|
|
129
|
|
|
$resB18 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushPowerShell.js\" type=\"text/javascript\"></script>"; |
130
|
|
|
$this->assertEquals($resB18, $obj->syntaxHighlighterScriptFunction("shBrushPowerShell")); |
131
|
|
|
|
132
|
|
|
$resB19 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushPython.js\" type=\"text/javascript\"></script>"; |
133
|
|
|
$this->assertEquals($resB19, $obj->syntaxHighlighterScriptFunction("shBrushPython")); |
134
|
|
|
|
135
|
|
|
$resB20 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushRuby.js\" type=\"text/javascript\"></script>"; |
136
|
|
|
$this->assertEquals($resB20, $obj->syntaxHighlighterScriptFunction("shBrushRuby")); |
137
|
|
|
|
138
|
|
|
$resB21 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushSass.js\" type=\"text/javascript\"></script>"; |
139
|
|
|
$this->assertEquals($resB21, $obj->syntaxHighlighterScriptFunction("shBrushSass")); |
140
|
|
|
|
141
|
|
|
$resB22 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushScala.js\" type=\"text/javascript\"></script>"; |
142
|
|
|
$this->assertEquals($resB22, $obj->syntaxHighlighterScriptFunction("shBrushScala")); |
143
|
|
|
|
144
|
|
|
$resB23 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushSql.js\" type=\"text/javascript\"></script>"; |
145
|
|
|
$this->assertEquals($resB23, $obj->syntaxHighlighterScriptFunction("shBrushSql")); |
146
|
|
|
|
147
|
|
|
$resB24 = "<script src=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/scripts/shBrushXml.js\" type=\"text/javascript\"></script>"; |
148
|
|
|
$this->assertEquals($resB24, $obj->syntaxHighlighterScriptFunction("shBrushXml")); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Tests the syntaxHighlighterStyleFunction() method. |
153
|
|
|
* |
154
|
|
|
* @return void |
155
|
|
|
*/ |
156
|
|
|
public function testSyntaxHighlighterStyleFunction() { |
157
|
|
|
|
158
|
|
|
$obj = new SyntaxHighlighterTwigExtension(getcwd()); |
159
|
|
|
|
160
|
|
|
try { |
161
|
|
|
$obj->syntaxHighlighterStyleFunction("exception"); |
162
|
|
|
} catch (Exception $ex) { |
163
|
|
|
$this->assertInstanceOf(FileNotFoundException::class, $ex); |
164
|
|
|
$this->assertEquals("The file \"syntaxhighlighter-3.0.83/styles/exception.css\" is not found", $ex->getMessage()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$res0 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCore.css\" rel=\"stylesheet\" type=\"text/css\">"; |
168
|
|
|
$this->assertEquals($res0, $obj->syntaxHighlighterStyleFunction("shCore")); |
169
|
|
|
|
170
|
|
|
$resC1 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCoreDefault.css\" rel=\"stylesheet\" type=\"text/css\">"; |
171
|
|
|
$this->assertEquals($resC1, $obj->syntaxHighlighterStyleFunction("shCoreDefault")); |
172
|
|
|
|
173
|
|
|
$resC2 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCoreDjango.css\" rel=\"stylesheet\" type=\"text/css\">"; |
174
|
|
|
$this->assertEquals($resC2, $obj->syntaxHighlighterStyleFunction("shCoreDjango")); |
175
|
|
|
|
176
|
|
|
$resC3 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCoreEclipse.css\" rel=\"stylesheet\" type=\"text/css\">"; |
177
|
|
|
$this->assertEquals($resC3, $obj->syntaxHighlighterStyleFunction("shCoreEclipse")); |
178
|
|
|
|
179
|
|
|
$resC4 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCoreEmacs.css\" rel=\"stylesheet\" type=\"text/css\">"; |
180
|
|
|
$this->assertEquals($resC4, $obj->syntaxHighlighterStyleFunction("shCoreEmacs")); |
181
|
|
|
|
182
|
|
|
$resC5 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCoreFadeToGrey.css\" rel=\"stylesheet\" type=\"text/css\">"; |
183
|
|
|
$this->assertEquals($resC5, $obj->syntaxHighlighterStyleFunction("shCoreFadeToGrey")); |
184
|
|
|
|
185
|
|
|
$resC6 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCoreMDUltra.css\" rel=\"stylesheet\" type=\"text/css\">"; |
186
|
|
|
$this->assertEquals($resC6, $obj->syntaxHighlighterStyleFunction("shCoreMDUltra")); |
187
|
|
|
|
188
|
|
|
$resC7 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCoreMidnight.css\" rel=\"stylesheet\" type=\"text/css\">"; |
189
|
|
|
$this->assertEquals($resC7, $obj->syntaxHighlighterStyleFunction("shCoreMidnight")); |
190
|
|
|
|
191
|
|
|
$resC8 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shCoreRDark.css\" rel=\"stylesheet\" type=\"text/css\">"; |
192
|
|
|
$this->assertEquals($resC8, $obj->syntaxHighlighterStyleFunction("shCoreRDark")); |
193
|
|
|
|
194
|
|
|
$resT1 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shThemeDefault.css\" rel=\"stylesheet\" type=\"text/css\">"; |
195
|
|
|
$this->assertEquals($resT1, $obj->syntaxHighlighterStyleFunction("shThemeDefault")); |
196
|
|
|
|
197
|
|
|
$resT2 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shThemeDjango.css\" rel=\"stylesheet\" type=\"text/css\">"; |
198
|
|
|
$this->assertEquals($resT2, $obj->syntaxHighlighterStyleFunction("shThemeDjango")); |
199
|
|
|
|
200
|
|
|
$resT3 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shThemeEclipse.css\" rel=\"stylesheet\" type=\"text/css\">"; |
201
|
|
|
$this->assertEquals($resT3, $obj->syntaxHighlighterStyleFunction("shThemeEclipse")); |
202
|
|
|
|
203
|
|
|
$resT4 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shThemeEmacs.css\" rel=\"stylesheet\" type=\"text/css\">"; |
204
|
|
|
$this->assertEquals($resT4, $obj->syntaxHighlighterStyleFunction("shThemeEmacs")); |
205
|
|
|
|
206
|
|
|
$resT5 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shThemeFadeToGrey.css\" rel=\"stylesheet\" type=\"text/css\">"; |
207
|
|
|
$this->assertEquals($resT5, $obj->syntaxHighlighterStyleFunction("shThemeFadeToGrey")); |
208
|
|
|
|
209
|
|
|
$resT6 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shThemeMDUltra.css\" rel=\"stylesheet\" type=\"text/css\">"; |
210
|
|
|
$this->assertEquals($resT6, $obj->syntaxHighlighterStyleFunction("shThemeMDUltra")); |
211
|
|
|
|
212
|
|
|
$resT7 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shThemeMidnight.css\" rel=\"stylesheet\" type=\"text/css\">"; |
213
|
|
|
$this->assertEquals($resT7, $obj->syntaxHighlighterStyleFunction("shThemeMidnight")); |
214
|
|
|
|
215
|
|
|
$resT8 = "<link href=\"/bundles/syntaxhighlighter/syntaxhighlighter-3.0.83/styles/shThemeRDark.css\" rel=\"stylesheet\" type=\"text/css\">"; |
216
|
|
|
$this->assertEquals($resT8, $obj->syntaxHighlighterStyleFunction("shThemeRDark")); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
} |
220
|
|
|
|