-
Notifications
You must be signed in to change notification settings - Fork 790
/
FilterTest.php
31 lines (27 loc) · 1.14 KB
/
FilterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
class FilterTest extends PHPUnit_Framework_TestCase
{
/**
* When argument contains bad code the encoded (and therefore un-dangerous) string should be returned
*/
public function testXSSFilterWithBadCode()
{
$codeBefore = "Hello <script>var http = new XMLHttpRequest(); http.open('POST', 'example.com/my_account/delete.php', true);</script>";
$codeAfter = "Hello <script>var http = new XMLHttpRequest(); http.open('POST', 'example.com/my_account/delete.php', true);</script>";
$this->assertEquals($codeAfter, Filter::XSSFilter($codeBefore));
}
/**
* For every type other than strings the method should return the untouched passed argument
*/
public function testXSSFilterWithNonStringArguments()
{
$integer = 123;
$array = [1, 2, 3];
$float = 17.001;
$null = null;
$this->assertEquals($integer, Filter::XSSFilter($integer));
$this->assertEquals($array, Filter::XSSFilter($array));
$this->assertEquals($float, Filter::XSSFilter($float));
$this->assertNull(Filter::XSSFilter($null));
}
}