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
|
|
|
|
17
|
|
|
final class StringTwigExtensionTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @dataProvider getMailHtml |
21
|
|
|
* |
22
|
|
|
* @param string $input |
23
|
|
|
* @param string $output |
24
|
|
|
*/ |
25
|
|
|
public function testAntispam(string $input, string $output): void |
26
|
|
|
{ |
27
|
|
|
$extension = new StringTwigExtension('spam', ['[AT]'], ['[DOT]']); |
28
|
|
|
|
29
|
|
|
$this->assertSame($output, $extension->antispam($input)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @dataProvider getMailText |
34
|
|
|
* |
35
|
|
|
* @param string $input |
36
|
|
|
* @param string $output |
37
|
|
|
*/ |
38
|
|
|
public function testAntispamText(string $input, string $output): void |
39
|
|
|
{ |
40
|
|
|
$extension = new StringTwigExtension('spam', ['[AT]'], ['[DOT]']); |
41
|
|
|
|
42
|
|
|
$this->assertSame($output, $extension->antispam($input, false)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public function getMailHtml() |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
[ |
52
|
|
|
'Lorem Ipsum <script>var link = "[email protected]"; </script> Sit Amet', |
53
|
|
|
'Lorem Ipsum <script>var link = "[email protected]"; </script> Sit Amet', |
54
|
|
|
], |
55
|
|
|
// TODO: Replace plain mails text in html |
56
|
|
|
// [ |
57
|
|
|
// 'Lorem Ipsum [email protected] Sit Amet', |
58
|
|
|
// 'Lorem Ipsum <span class="spam"><span>foo[DOT]sub</span>[AT]<span>bar[DOT]baz[DOT]tld</span></span> Sit Amet', |
59
|
|
|
// ], |
60
|
|
|
[ |
61
|
|
|
'Lorem Ipsum <a href="mailto:[email protected]">John Smith</a> Sit Amet', |
62
|
|
|
'Lorem Ipsum <span class="spam"><span>john</span>[AT]<span>smith[DOT]cool</span> (<span>John Smith</span>)</span> Sit Amet', |
63
|
|
|
], |
64
|
|
|
[ |
65
|
|
|
'Lorem Ipsum <a href="mailto:[email protected]">[email protected]</a> Sit Amet', |
66
|
|
|
'Lorem Ipsum <span class="spam"><span>foo[DOT]sub</span>[AT]<span>bar[DOT]baz[DOT]tld</span></span> Sit Amet', |
67
|
|
|
], |
68
|
|
|
[ |
69
|
|
|
'Lorem Ipsum <span class="spam"><span>foo[DOT]sub</span>[AT]<span>bar[DOT]baz[DOT]tld</span></span> Sit Amet', |
70
|
|
|
'Lorem Ipsum <span class="spam"><span>foo[DOT]sub</span>[AT]<span>bar[DOT]baz[DOT]tld</span></span> Sit Amet', |
71
|
|
|
], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
public function getMailText() |
79
|
|
|
{ |
80
|
|
|
return [ |
81
|
|
|
[ |
82
|
|
|
'Lorem Ipsum [email protected] Sit Amet', |
83
|
|
|
'Lorem Ipsum foo[DOT]sub[AT]bar[DOT]baz[DOT]tld Sit Amet', |
84
|
|
|
], |
85
|
|
|
[ |
86
|
|
|
'Lorem Ipsum foo[DOT]sub[AT]bar[DOT]baz[DOT]tld Sit Amet', |
87
|
|
|
'Lorem Ipsum foo[DOT]sub[AT]bar[DOT]baz[DOT]tld Sit Amet', |
88
|
|
|
], |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|