2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * tests for PMA_sanitize()
6 * @package phpMyAdmin-test
12 require_once 'libraries/sanitizing.lib.php';
13 require_once 'libraries/url_generating.lib.php';
14 require_once 'libraries/core.lib.php';
16 class PMA_sanitize_test
extends PHPUnit_Framework_TestCase
19 * Tests for proper escaping of XSS.
21 public function testXssInHref()
23 $this->assertEquals('[a@javascript:alert(\'XSS\');@target]link</a>',
24 PMA_sanitize('[a@javascript:alert(\'XSS\');@target]link[/a]'));
28 * Tests correct generating of link redirector.
30 public function testLink()
32 unset($GLOBALS['server']);
33 unset($GLOBALS['lang']);
34 $this->assertEquals('<a href="./url.php?url=http%3A%2F%2Fwww.phpmyadmin.net%2F" target="target">link</a>',
35 PMA_sanitize('[a@http://www.phpmyadmin.net/@target]link[/a]'));
39 * Tests links to documentation.
41 public function testLinkDoc()
43 $this->assertEquals('<a href="./Documentation.html">doc</a>',
44 PMA_sanitize('[a@./Documentation.html]doc[/a]'));
48 * Tests link target validation.
50 public function testInvalidTarget()
52 $this->assertEquals('[a@./Documentation.html@INVALID9]doc</a>',
53 PMA_sanitize('[a@./Documentation.html@INVALID9]doc[/a]'));
57 * Tests XSS escaping after valid link.
59 public function testLinkDocXss()
61 $this->assertEquals('[a@./Documentation.html" onmouseover="alert(foo)"]doc</a>',
62 PMA_sanitize('[a@./Documentation.html" onmouseover="alert(foo)"]doc[/a]'));
66 * Tests proper handling of multi link code.
68 public function testLinkAndXssInHref()
70 $this->assertEquals('<a href="./Documentation.html">doc</a>[a@javascript:alert(\'XSS\');@target]link</a>',
71 PMA_sanitize('[a@./Documentation.html]doc[/a][a@javascript:alert(\'XSS\');@target]link[/a]'));
75 * Test escaping of HTML tags
77 public function testHtmlTags()
79 $this->assertEquals('<div onclick="">',
80 PMA_sanitize('<div onclick="">'));
84 * Tests basic BB code.
86 public function testBBCode()
88 $this->assertEquals('<strong>strong</strong>',
89 PMA_sanitize('[b]strong[/b]'));
93 * Tests output escaping.
95 public function testEscape()
97 $this->assertEquals('<strong>strong</strong>',
98 PMA_sanitize('[strong]strong[/strong]', true));