1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[email protected]> |
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 Core23\AntiSpamBundle\Tests\Twig\Extension; |
13
|
|
|
|
14
|
|
|
use Core23\AntiSpamBundle\Twig\Extension\StringTwigExtension; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use Twig\TwigFilter; |
17
|
|
|
|
18
|
|
|
final class StringTwigExtensionTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
public function testGetFilters(): void |
21
|
|
|
{ |
22
|
|
|
$extension = new StringTwigExtension('spam', ['[AT]'], ['[DOT]']); |
23
|
|
|
|
24
|
|
|
$filters = $extension->getFilters(); |
25
|
|
|
|
26
|
|
|
static::assertNotCount(0, $filters); |
27
|
|
|
|
28
|
|
|
foreach ($filters as $filter) { |
29
|
|
|
static::assertInstanceOf(TwigFilter::class, $filter); |
30
|
|
|
static::assertIsCallable($filter->getCallable()); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @dataProvider getMailHtml |
36
|
|
|
*/ |
37
|
|
|
public function testAntispam(string $input, string $output): void |
38
|
|
|
{ |
39
|
|
|
$extension = new StringTwigExtension('spam', ['[AT]'], ['[DOT]']); |
40
|
|
|
|
41
|
|
|
static::assertSame($output, $extension->antispam($input)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @dataProvider getMailText |
46
|
|
|
*/ |
47
|
|
|
public function testAntispamText(string $input, string $output): void |
48
|
|
|
{ |
49
|
|
|
$extension = new StringTwigExtension('spam', ['[AT]'], ['[DOT]']); |
50
|
|
|
|
51
|
|
|
static::assertSame($output, $extension->antispam($input, false)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getMailHtml(): iterable |
55
|
|
|
{ |
56
|
|
|
// @noinspection JSUnusedLocalSymbols |
57
|
|
|
return [ |
58
|
|
|
[ |
59
|
|
|
'Lorem Ipsum <script>const link = "[email protected]"; </script> Sit Amet', |
60
|
|
|
'Lorem Ipsum <script>const link = "[email protected]"; </script> Sit Amet', |
61
|
|
|
], |
62
|
|
|
// TODO: Replace plain mails text in html |
63
|
|
|
// [ |
64
|
|
|
// 'Lorem Ipsum [email protected] Sit Amet', |
65
|
|
|
// 'Lorem Ipsum <span class="spam"><span>foo[DOT]sub</span>[AT]<span>bar[DOT]baz[DOT]tld</span></span> Sit Amet', |
66
|
|
|
// ], |
67
|
|
|
[ |
68
|
|
|
'Lorem Ipsum <a href="mailto:[email protected]">John Smith</a> Sit Amet', |
69
|
|
|
'Lorem Ipsum <span class="spam"><span>john</span>[AT]<span>smith[DOT]cool</span> (<span>John Smith</span>)</span> Sit Amet', |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
'Lorem Ipsum <a href="mailto:[email protected]">[email protected]</a> Sit Amet', |
73
|
|
|
'Lorem Ipsum <span class="spam"><span>foo[DOT]sub</span>[AT]<span>bar[DOT]baz[DOT]tld</span></span> Sit Amet', |
74
|
|
|
], |
75
|
|
|
[ |
76
|
|
|
'Lorem Ipsum <span class="spam"><span>foo[DOT]sub</span>[AT]<span>bar[DOT]baz[DOT]tld</span></span> Sit Amet', |
77
|
|
|
'Lorem Ipsum <span class="spam"><span>foo[DOT]sub</span>[AT]<span>bar[DOT]baz[DOT]tld</span></span> Sit Amet', |
78
|
|
|
], |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getMailText(): iterable |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
[ |
86
|
|
|
'Lorem Ipsum [email protected] Sit Amet', |
87
|
|
|
'Lorem Ipsum foo[DOT]sub[AT]bar[DOT]baz[DOT]tld Sit Amet', |
88
|
|
|
], |
89
|
|
|
[ |
90
|
|
|
'Lorem Ipsum foo[DOT]sub[AT]bar[DOT]baz[DOT]tld Sit Amet', |
91
|
|
|
'Lorem Ipsum foo[DOT]sub[AT]bar[DOT]baz[DOT]tld Sit Amet', |
92
|
|
|
], |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|