1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FlorianKoerner\ChimpDrill\Tests; |
4
|
|
|
|
5
|
|
|
use FlorianKoerner\ChimpDrill\ChimpDrill; |
6
|
|
|
|
7
|
|
|
class EscapingTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @return array |
11
|
|
|
*/ |
12
|
|
|
public function dataProvider() |
13
|
|
|
{ |
14
|
|
|
return array( |
15
|
|
|
array( |
16
|
|
|
'message' => 'Damn! Very cool PHP-Code: <?php echo "evil"; ?>', |
17
|
|
|
'placeholder' => array(), |
18
|
|
|
'expected' => 'Damn! Very cool PHP-Code: <?php echo "evil"; ?>' |
19
|
|
|
), |
20
|
|
|
array( |
21
|
|
|
'message' => 'And take a look at these HTML-Tags: <strong>Unbelievable!</strong>', |
22
|
|
|
'placeholder' => array(), |
23
|
|
|
'expected' => 'And take a look at these HTML-Tags: <strong>Unbelievable!</strong>' |
24
|
|
|
), |
25
|
|
|
array( |
26
|
|
|
'message' => 'Your input was *|INPUT|*. Thank you, *|NAME|*.', |
27
|
|
|
'placeholder' => array( |
28
|
|
|
'NAME' => 'John <hacks>', |
29
|
|
|
'INPUT' => '<?php var_dump($_SERVER); ?> <strong>I\'m a very bad boy</strong>' |
30
|
|
|
), |
31
|
|
|
'expected' => 'Your input was <?php var_dump($_SERVER); ?> <strong>I\'m a very bad boy</strong>. Thank you, John <hacks>.' |
32
|
|
|
), |
33
|
|
|
array( |
34
|
|
|
'message' => 'Your input was *|HTML:INPUT|*. Thank you, *|HTML:NAME|*.', |
35
|
|
|
'placeholder' => array( |
36
|
|
|
'NAME' => 'John <hacks>', |
37
|
|
|
'INPUT' => '<?php var_dump($_SERVER); ?> <strong>I\'m a very bad boy</strong>' |
38
|
|
|
), |
39
|
|
|
'expected' => 'Your input was <?php var_dump($_SERVER); ?> <strong>I\'m a very bad boy</strong>. Thank you, John <hacks>.' |
40
|
|
|
) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $message |
46
|
|
|
* @param array $placeholder |
47
|
|
|
* @param string $expected |
48
|
|
|
* |
49
|
|
|
* @dataProvider dataProvider |
50
|
|
|
*/ |
51
|
|
|
public function testEscaping($message, array $placeholder, $expected) |
52
|
|
|
{ |
53
|
|
|
$this->assertEquals($expected, (string) new ChimpDrill($message, $placeholder)); |
54
|
|
|
} |
55
|
|
|
} |