Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / test / libraries / PMA_sanitize_test.php
blobd6f855607fb0d1b77a4f5a1b40442778370de4cb
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * tests for PMA_sanitize()
6 * @package phpMyAdmin-test
7 */
9 /*
10 * Include to 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
18 /**
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]'));
27 /**
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]'));
38 /**
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]'));
47 /**
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]'));
56 /**
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]'));
65 /**
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]'));
74 /**
75 * Test escaping of HTML tags
77 public function testHtmlTags()
79 $this->assertEquals('&lt;div onclick=""&gt;',
80 PMA_sanitize('<div onclick="">'));
83 /**
84 * Tests basic BB code.
86 public function testBBCode()
88 $this->assertEquals('<strong>strong</strong>',
89 PMA_sanitize('[b]strong[/b]'));
92 /**
93 * Tests output escaping.
95 public function testEscape()
97 $this->assertEquals('&lt;strong&gt;strong&lt;/strong&gt;',
98 PMA_sanitize('[strong]strong[/strong]', true));