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\Asset; |
13
|
|
|
|
14
|
|
|
use Twig\Node\Node; |
15
|
|
|
use Twig\TwigFunction; |
16
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase; |
17
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\Asset\JQueryInputMaskTwigExtension; |
18
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\RendererTwigExtension; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* jQuery Input mask Twig extension test. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
24
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\Twig\Extension\Asset |
25
|
|
|
*/ |
26
|
|
|
class JQueryInputMaskTwigExtensionTest extends AbstractTestCase { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Renderer Twig extension. |
30
|
|
|
* |
31
|
|
|
* @var RendererTwigExtension |
32
|
|
|
*/ |
33
|
|
|
private $rendererTwigExtension; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritDoc} |
37
|
|
|
*/ |
38
|
|
|
protected function setUp(): void { |
39
|
|
|
parent::setUp(); |
40
|
|
|
|
41
|
|
|
// Set a Renderer Twig extension mock. |
42
|
|
|
$this->rendererTwigExtension = new RendererTwigExtension($this->twigEnvironment); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Tests the getFilters() method. |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function testGetFilters(): void { |
51
|
|
|
|
52
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
53
|
|
|
|
54
|
|
|
$res = $obj->getFilters(); |
55
|
|
|
$this->assertCount(0, $res); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Tests the getFunctions() method. |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function testGetFunctions(): void { |
64
|
|
|
|
65
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
66
|
|
|
|
67
|
|
|
$res = $obj->getFunctions(); |
68
|
|
|
$this->assertCount(7, $res); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[0]); |
71
|
|
|
$this->assertEquals("jQueryInputMask", $res[0]->getName()); |
72
|
|
|
$this->assertEquals([$obj, "jQueryInputMaskFunction"], $res[0]->getCallable()); |
73
|
|
|
$this->assertEquals(["html"], $res[0]->getSafe(new Node())); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[1]); |
76
|
|
|
$this->assertEquals("jQueryInputMaskPhoneNumber", $res[1]->getName()); |
77
|
|
|
$this->assertEquals([$obj, "jQueryInputMaskPhoneNumberFunction"], $res[1]->getCallable()); |
78
|
|
|
$this->assertEquals(["html"], $res[1]->getSafe(new Node())); |
79
|
|
|
|
80
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[2]); |
81
|
|
|
$this->assertEquals("jQueryInputMaskSIRETNumber", $res[2]->getName()); |
82
|
|
|
$this->assertEquals([$obj, "jQueryInputMaskSIRETNumberFunction"], $res[2]->getCallable()); |
83
|
|
|
$this->assertEquals(["html"], $res[2]->getSafe(new Node())); |
84
|
|
|
|
85
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[3]); |
86
|
|
|
$this->assertEquals("jQueryInputMaskSocialSecurityNumber", $res[3]->getName()); |
87
|
|
|
$this->assertEquals([$obj, "jQueryInputMaskSocialSecurityNumberFunction"], $res[3]->getCallable()); |
88
|
|
|
$this->assertEquals(["html"], $res[3]->getSafe(new Node())); |
89
|
|
|
|
90
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[4]); |
91
|
|
|
$this->assertEquals("jQueryInputMaskTime12", $res[4]->getName()); |
92
|
|
|
$this->assertEquals([$obj, "jQueryInputMaskTime12Function"], $res[4]->getCallable()); |
93
|
|
|
$this->assertEquals(["html"], $res[4]->getSafe(new Node())); |
94
|
|
|
|
95
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[5]); |
96
|
|
|
$this->assertEquals("jQueryInputMaskTime24", $res[5]->getName()); |
97
|
|
|
$this->assertEquals([$obj, "jQueryInputMaskTime24Function"], $res[5]->getCallable()); |
98
|
|
|
$this->assertEquals(["html"], $res[5]->getSafe(new Node())); |
99
|
|
|
|
100
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[6]); |
101
|
|
|
$this->assertEquals("jQueryInputMaskVATNumber", $res[6]->getName()); |
102
|
|
|
$this->assertEquals([$obj, "jQueryInputMaskVATNumberFunction"], $res[6]->getCallable()); |
103
|
|
|
$this->assertEquals(["html"], $res[6]->getSafe(new Node())); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Tests the jQueryInputMaskFunction() method. |
108
|
|
|
* |
109
|
|
|
* @return void |
110
|
|
|
*/ |
111
|
|
|
public function testJQueryInputMaskFunction(): void { |
112
|
|
|
|
113
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
114
|
|
|
|
115
|
|
|
$arg = ["selector" => "#selector", "mask" => "+33 9 99 99 99 99", "scriptTag" => true, "opts" => ["placeholder" => "+__ _ __ __ __ __"]]; |
116
|
|
|
$res = "<script type=\"text/javascript\">\n$('#selector').inputmask(\"+33 9 99 99 99 99\",{\"placeholder\":\"+__ _ __ __ __ __\"});\n</script>"; |
117
|
|
|
$this->assertEquals($res, $obj->jQueryInputMaskFunction($arg)); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Tests the jQueryInputMaskFunction() method. |
122
|
|
|
* |
123
|
|
|
* @return void |
124
|
|
|
*/ |
125
|
|
|
public function testJQueryInputMaskFunctionWithoutOptions(): void { |
126
|
|
|
|
127
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
128
|
|
|
|
129
|
|
|
$arg = ["selector" => "#selector"]; |
130
|
|
|
$res = '$(\'#selector\').inputmask("",[]);'; |
131
|
|
|
$this->assertEquals($res, $obj->jQueryInputMaskFunction($arg)); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Tests the jQueryInputMaskPhoneNumberFunction() method. |
136
|
|
|
* |
137
|
|
|
* @return void |
138
|
|
|
*/ |
139
|
|
|
public function testJQueryInputMaskPhoneNumberFunction(): void { |
140
|
|
|
|
141
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
142
|
|
|
|
143
|
|
|
$arg = ["selector" => "#selector"]; |
144
|
|
|
$res = '$(\'#selector\').inputmask("99 99 99 99 99",{"autoUnmask":true,"removeMaskOnSubmit":true,"placeholder":"__ __ __ __ __"});'; |
145
|
|
|
$this->assertEquals($res, $obj->jQueryInputMaskPhoneNumberFunction($arg)); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Tests the jQueryInputMaskSIRETNumberFunction() method. |
150
|
|
|
* |
151
|
|
|
* @return void |
152
|
|
|
*/ |
153
|
|
|
public function testJQueryInputMaskSIRETNumberFunction(): void { |
154
|
|
|
|
155
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
156
|
|
|
|
157
|
|
|
$arg = ["selector" => "#selector"]; |
158
|
|
|
$res = '$(\'#selector\').inputmask("999 999 999 99999",{"autoUnmask":true,"removeMaskOnSubmit":true,"placeholder":"___ ___ ___ _____"});'; |
159
|
|
|
$this->assertEquals($res, $obj->jQueryInputMaskSIRETNumberFunction($arg)); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Tests the jQueryInputMaskSocialSecurityNumberFunction() method. |
164
|
|
|
* |
165
|
|
|
* @return void |
166
|
|
|
*/ |
167
|
|
|
public function testJQueryInputMaskSocialSecurityNumberFunction(): void { |
168
|
|
|
|
169
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
170
|
|
|
|
171
|
|
|
$arg = ["selector" => "#selector"]; |
172
|
|
|
$res = '$(\'#selector\').inputmask("9 99 99 99 999 999 99",{"autoUnmask":true,"removeMaskOnSubmit":true,"placeholder":"_ __ __ __ ___ ___ __"});'; |
173
|
|
|
$this->assertEquals($res, $obj->jQueryInputMaskSocialSecurityNumberFunction($arg)); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Tests the jQueryInputMaskTime12Function() method. |
178
|
|
|
* |
179
|
|
|
* @return void |
180
|
|
|
*/ |
181
|
|
|
public function testJQueryInputMaskTime12Function(): void { |
182
|
|
|
|
183
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
184
|
|
|
|
185
|
|
|
$arg = ["selector" => "#selector"]; |
186
|
|
|
$res = '$(\'#selector\').inputmask("hh:mm t",{"autoUnmask":true,"removeMaskOnSubmit":true,"hourFormat":"12","placeholder":"__:__ _m"});'; |
187
|
|
|
$this->assertEquals($res, $obj->jQueryInputMaskTime12Function($arg)); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Tests the jQueryInputMaskTime24Function() method. |
192
|
|
|
* |
193
|
|
|
* @return void |
194
|
|
|
*/ |
195
|
|
|
public function testJQueryInputMaskTime24Function(): void { |
196
|
|
|
|
197
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
198
|
|
|
|
199
|
|
|
$arg = ["selector" => "#selector"]; |
200
|
|
|
$res = '$(\'#selector\').inputmask("hh:mm",{"autoUnmask":true,"removeMaskOnSubmit":true,"hourFormat":"24","placeholder":"__:__"});'; |
201
|
|
|
$this->assertEquals($res, $obj->jQueryInputMaskTime24Function($arg)); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Tests the jQueryInputMaskVATNumberFunction() method. |
206
|
|
|
* |
207
|
|
|
* @return void |
208
|
|
|
*/ |
209
|
|
|
public function testJQueryInputMaskVATNumberFunction(): void { |
210
|
|
|
|
211
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
212
|
|
|
|
213
|
|
|
$arg = ["selector" => "#selector"]; |
214
|
|
|
$res = '$(\'#selector\').inputmask("**999 999 999 99",{"autoUnmask":true,"removeMaskOnSubmit":true,"placeholder":"_____ ___ ___ __"});'; |
215
|
|
|
$this->assertEquals($res, $obj->jQueryInputMaskVATNumberFunction($arg)); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Tests the __construct() method. |
220
|
|
|
* |
221
|
|
|
* @return void |
222
|
|
|
*/ |
223
|
|
|
public function test__construct(): void { |
224
|
|
|
|
225
|
|
|
$this->assertEquals("wbw.core.twig.extension.asset.jquery_inputmask", JQueryInputMaskTwigExtension::SERVICE_NAME); |
226
|
|
|
|
227
|
|
|
$obj = new JQueryInputMaskTwigExtension($this->twigEnvironment, $this->rendererTwigExtension); |
228
|
|
|
|
229
|
|
|
$this->assertSame($this->twigEnvironment, $obj->getTwigEnvironment()); |
230
|
|
|
$this->assertSame($this->rendererTwigExtension, $obj->getRendererTwigExtension()); |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: