]> git.mxchange.org Git - friendica.git/blob - tests/xss_filter_tests.php
Merge branch 'master' of git://github.com/friendica/friendica
[friendica.git] / tests / xss_filter_tests.php
1 <?php
2 /**
3 * Tests, without pHPUnit by now
4 * @package test.util
5 */
6
7 require_once(text.php); 
8
9 /**
10 * test no tags
11 */
12 $invalidstring='<submit type="button" onclick="alert(\'failed!\');" />'
13
14 $validstring=notags($invalidstring); 
15 $escapedString=escape_tags($invalidstring); 
16
17 assert("[submit type="button" onclick="alert(\'failed!\');" /]", $validstring); 
18 assert("what ever", $escapedString); 
19
20 /**
21 *autonames should be random, even length
22 */
23 $autoname1=autoname(10); 
24 $autoname2=autoname(10); 
25
26 assertNotEquals($autoname1, $autoname2); 
27
28 /**
29 *autonames should be random, odd length
30 */
31 $autoname1=autoname(9); 
32 $autoname2=autoname(9); 
33
34 assertNotEquals($autoname1, $autoname2); 
35
36 /**
37 * try to fail autonames
38 */
39 $autoname1=autoname(0); 
40 $autoname2=autoname(MAX_VALUE); 
41 $autoname3=autoname(1); 
42 assert(count($autoname1), 0); 
43 assert(count($autoname2), MAX_VALUE); 
44 assert(count($autoname3), 1); 
45
46 /**
47 *xmlify and unxmlify
48 */
49 $text="<tag>I want to break\n this!11!<?hard?></tag>"
50 $xml=xmlify($text); //test whether it actually may be part of a xml document
51 $retext=unxmlify($text); 
52
53 assert($text, $retext); 
54
55 /**
56 * test hex2bin and reverse
57 */
58
59 assert(-3, hex2bin(bin2hex(-3))); 
60 assert(0, hex2bin(bin2hex(0))); 
61 assert(12, hex2bin(bin2hex(12))); 
62 assert(MAX_INT, hex2bin(bin2hex(MAX_INT))); 
63
64 /**
65 * test expand_acl
66 */
67 $text="<1><2><3>"; 
68 assert(array(1, 2, 3), $text); 
69
70 $text="<1><279012><15>"; 
71 assert(array(1, 279012, 15), $text); 
72
73 $text="<1><279012><tt>"; //maybe that's invalid
74 assert(array(1, 279012, "tt"), $text); 
75
76 $text="<1><279 012><tt>"; //maybe that's invalid
77 assert(array(1, "279 012", "tt"), $text); 
78
79 $text=""; //maybe that's invalid
80 assert(array(), $text); 
81
82 $text="According to documentation, that's invalid. "; //should be invalid
83 assert(array(), $text); 
84
85 $text="<Another invalid string"; //should be invalid
86 assert(array(), $text); 
87
88 $text="Another invalid> string"; //should be invalid
89 assert(array(), $text); 
90
91 $text="Another> invalid> string>"; //should be invalid
92 assert(array(), $text); 
93
94 /**
95 * test attribute contains
96 */
97 $testAttr="class1 notclass2 class3"; 
98 assertTrue(attribute_contains($testAttr, "class3")); 
99 assertFalse(attribute_contains($testAttr, "class2")); 
100
101 $testAttr=""; 
102 assertFalse(attribute_contains($testAttr, "class2")); 
103
104 $testAttr="--... %$ยง() /(=?}"; 
105 assertFalse(attribute_contains($testAttr, "class2")); 
106
107 /**
108 * test get_tags
109 */
110 $text="hi @Mike, I'm just writing #test_cases, "; 
111 $text.=" so @somebody@friendica.com may change #things. Of course I "; 
112 $text.="look for a lot of #pitfalls, like #tags at the end of a sentence "; 
113 $text.="@comment. I hope noone forgets about @fullstops.because that might"; 
114 $text.=" break #things. @Mike@campino@friendica.eu is also #nice, isn't it? "; 
115 $text.="Now, add a @first_last tag. "
116 //check whether this are all variants (no, auto-stuff is missing). 
117
118 $tags=get_tags($text); 
119
120 assert("@Mike", $tags[0]); 
121 assert("#test_cases", $tags[1]); 
122 assert("@somebody@friendica.com", $tags[2]); 
123 assert("#things", $tags[3]); 
124 assert("#pitfalls", $tags[4]); 
125 assert("#tags", $tags[5]); 
126 assert("@comment", $tags[6]); 
127 assert("@fullstops", $tags[7]); 
128 assert("#things", $tags[8]); 
129 assert("@Mike", $tags[9]); 
130 assert("@campino@friendica.eu", $tags[10]); 
131 assert("#nice", $tags[11]); 
132 assert("@first_last", $tags[12]); 
133
134 $tags=get_tags(""); 
135 assert(0, count($tags)); 
136
137 //function qp, quick and dirty??
138 //get_mentions
139 //get_contact_block, bis Zeile 538
140 ?>