Browse Source

added some tests

tags/2.39
Alexander Kampmann 7 years ago
parent
commit
f84c191f8d
3 changed files with 102 additions and 44 deletions
  1. 11
    17
      build.xml
  2. 90
    26
      tests/xss_filter_test.php
  3. 1
    1
      util/db_update.php

+ 11
- 17
build.xml View File

@@ -1,16 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 
3 3
 <project name="friendica" default="test">
4
-	<!-- set up include directories, this is necessary for the tests to work -->
5
-	<php>
6
-		set_include_path(
7
-					get_include_path() . PATH_SEPARATOR
8
-					. 'include' . PATH_SEPARATOR 
9
-					. 'library' . PATH_SEPARATOR 
10
-					. 'library/phpsec' . PATH_SEPARATOR 
11
-					. '.' );
12
-	</php>
13
-	
14 4
 	<!-- ====================================================== -->
15 5
 	<!-- Target: clean-test -->
16 6
 	<!-- deletes directories with old test reports -->
@@ -32,16 +22,17 @@
32 22
 	<!-- this target runs all test files -->
33 23
 	<!-- =================================== -->
34 24
 	<target name="test" depends="prepare-test">
35
-		<coverage-setup database="./report/coverage-database">
25
+		<!-- coverage-setup database="./report/coverage-database">
36 26
 			<fileset dir=".">
37 27
 				<include name="**/*.php" />
38 28
 				<exclude name="*test.php"/>
39
-				<exclude name="./index.php"/>
40
-				<exclude name="./library/**"/>
29
+				<exclude name="index.php"/>
30
+				<exclude name="library/**"/>
41 31
 				<exclude name="doc/**"/>
32
+				<exclude name=".."/>
42 33
 			</fileset>
43
-		</coverage-setup>
44
-		<phpunit printsummary="true" >
34
+		</coverage-setup -->
35
+		<phpunit printsummary="true">
45 36
 			<batchtest>
46 37
 				<fileset dir="tests">
47 38
 					<include name="*test.php" />
@@ -50,9 +41,9 @@
50 41
 			<formatter type="xml" todir="report" outfile="testlog.xml" />
51 42
 		</phpunit>
52 43
 		<phpunitreport infile="report/testlog.xml" todir="report" />
53
-		<coverage-report outfile="report/coverage-database">
44
+		<!-- coverage-report outfile="report/coverage-database">
54 45
 		      <report todir="report" styledir="/home/phing/etc" />
55
-		    </coverage-report>
46
+		    </coverage-report -->
56 47
 	</target>
57 48
 
58 49
 	<!-- ===================================================== -->
@@ -75,6 +66,9 @@
75 66
 		<docblox title="Friendica API" destdir="./doc/api">
76 67
 			<fileset dir=".">
77 68
 				<include name="**/*.php" />
69
+				<include name="README"/>
70
+				<include name="INSTALL.txt"/>
71
+				<include name="LICENSE"/>
78 72
 			</fileset>
79 73
 		</docblox>
80 74
 	</target>

+ 90
- 26
tests/xss_filter_test.php View File

@@ -1,16 +1,26 @@
1 1
 <?php
2 2
 /**
3
-* Tests, without pHPUnit by now
4
-* @package test.util
5
-*/
3
+ * Tests, without pHPUnit by now
4
+ * @package test.util
5
+ */
6 6
 
7
-require_once('include/text.php'); 
7
+require_once("include/template_processor.php");
8
+require_once('include/text.php');
8 9
 
9 10
 class AntiXSSTest extends PHPUnit_Framework_TestCase {
10 11
 
11
-/**
12
-* test no tags
13
-*/
12
+	public function setUp() {
13
+		set_include_path(
14
+				get_include_path() . PATH_SEPARATOR
15
+				. 'include' . PATH_SEPARATOR
16
+				. 'library' . PATH_SEPARATOR
17
+				. 'library/phpsec' . PATH_SEPARATOR
18
+				. '.' );
19
+	}
20
+
21
+	/**
22
+	 * test no tags
23
+	 */
14 24
 	public function testEscapeTags() {
15 25
 		$invalidstring='<submit type="button" onclick="alert(\'failed!\');" />';
16 26
 
@@ -53,12 +63,12 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
53 63
 		$autoname1=autoname(-23);
54 64
 		$this->assertEquals(0, count($autoname1));
55 65
 	}
56
-	
57
-// 	public function testAutonameMaxLength() {
58
-// 		$autoname2=autoname(PHP_INT_MAX);
59
-// 		$this->assertEquals(PHP_INT_MAX, count($autoname2));
60
-// 	}
61
-	
66
+
67
+	// 	public function testAutonameMaxLength() {
68
+	// 		$autoname2=autoname(PHP_INT_MAX);
69
+	// 		$this->assertEquals(PHP_INT_MAX, count($autoname2));
70
+	// 	}
71
+
62 72
 	public function testAutonameLength1() {
63 73
 		$autoname3=autoname(1);
64 74
 		$this->assertEquals(1, count($autoname3));
@@ -68,7 +78,7 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
68 78
 	 *xmlify and unxmlify
69 79
 	 */
70 80
 	public function testXmlify() {
71
-		$text="<tag>I want to break\n this!11!<?hard?></tag>"; 
81
+		$text="<tag>I want to break\n this!11!<?hard?></tag>";
72 82
 		$xml=xmlify($text); //test whether it actually may be part of a xml document
73 83
 		$retext=unxmlify($text);
74 84
 
@@ -85,7 +95,7 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
85 95
 		$this->assertEquals(12, hex2bin(bin2hex(12)));
86 96
 		$this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX)));
87 97
 	}
88
-	
98
+
89 99
 	/**
90 100
 	 * test expand_acl
91 101
 	 */
@@ -93,7 +103,7 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
93 103
 		$text="<1><2><3>";
94 104
 		$this->assertEquals(array(1, 2, 3), expand_acl($text));
95 105
 	}
96
-	
106
+
97 107
 	public function testExpandAclBigNumber() {
98 108
 		$text="<1><279012><15>";
99 109
 		$this->assertEquals(array(1, 279012, 15), expand_acl($text));
@@ -133,19 +143,19 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
133 143
 		$text="Another> invalid> string>"; //should be invalid
134 144
 		$this->assertEquals(array(), expand_acl($text));
135 145
 	}
136
-	
146
+
137 147
 	public function testExpandAclOpenOnly() {
138 148
 		$text="<Another< invalid string<"; //should be invalid
139 149
 		$this->assertEquals(array(), expand_acl($text));
140 150
 	}
141
-	
151
+
142 152
 	public function testExpandAclNoMatching1() {
143 153
 		$text="<Another<> invalid <string>"; //should be invalid
144 154
 		$this->assertEquals(array(), expand_acl($text));
145 155
 	}
146
-	
156
+
147 157
 	public function testExpandAclNoMatching2() {
148
-		$text="<1>2><3>"; 
158
+		$text="<1>2><3>";
149 159
 		$this->assertEquals(array(), expand_acl($text));
150 160
 	}
151 161
 
@@ -166,7 +176,7 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
166 176
 		$this->assertTrue(attribute_contains($testAttr, "class3"));
167 177
 		$this->assertFalse(attribute_contains($testAttr, "class2"));
168 178
 	}
169
-	
179
+
170 180
 	public function testAttributeContainsEmpty() {
171 181
 		$testAttr="";
172 182
 		$this->assertFalse(attribute_contains($testAttr, "class2"));
@@ -176,17 +186,71 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
176 186
 		$testAttr="--... %\$ä() /(=?}";
177 187
 		$this->assertFalse(attribute_contains($testAttr, "class2"));
178 188
 	}
179
-	
189
+
180 190
 	/**
181 191
 	 * test get_tags
182 192
 	 */
193
+	public function testGetTagsShortPerson() {
194
+		$text="hi @Mike"; 
195
+		
196
+		$tags=get_tags($text);
197
+		
198
+		$this->assertEquals("@Mike", $tags[0]);
199
+	}
200
+	
201
+	public function testGetTagsShortTag() {
202
+		$text="This is a #test_case";
203
+	
204
+		$tags=get_tags($text);
205
+	
206
+		$this->assertEquals("#test_case", $tags[0]);
207
+	}
208
+	
209
+	public function testGetTagsShortTagAndPerson() {
210
+		$text="hi @Mike This is a #test_case";
211
+	
212
+		$tags=get_tags($text);
213
+	
214
+		$this->assertEquals("@Mike", $tags[0]);
215
+		$this->assertEquals("#test_case", $tags[1]);
216
+	}
217
+	
218
+	public function testGetTagsShortTagAndPersonSpecialChars() {
219
+		$text="hi @Mike, This is a #test_case.";
220
+	
221
+		$tags=get_tags($text);
222
+	
223
+		$this->assertEquals("@Mike", $tags[0]);
224
+		$this->assertEquals("#test_case", $tags[1]);
225
+	}
226
+	
227
+	public function testGetTagsPersonOnly() {
228
+		$text="@Mike I saw the Theme Dev group was created."; 
229
+		
230
+		$tags=get_tags($text);
231
+		
232
+		$this->assertEquals("@Mike", $tags[0]);
233
+	}
234
+	
235
+	public function testGetTags2Persons1TagSpecialChars() {
236
+		$text="hi @Mike, I'm just writing #test_cases, so"
237
+		." so @somebody@friendica.com may change #things.";
238
+	
239
+		$tags=get_tags($text);
240
+	
241
+		$this->assertEquals("@Mike", $tags[0]);
242
+		$this->assertEquals("#test_cases", $tags[1]);
243
+		$this->assertEquals("@somebody@friendica.com", $tags[2]);
244
+		$this->assertEquals("#things", $tags[3]);
245
+	}
246
+	
183 247
 	public function testGetTags() {
184 248
 		$text="hi @Mike, I'm just writing #test_cases, "
185 249
 		." so @somebody@friendica.com may change #things. Of course I "
186 250
 		."look for a lot of #pitfalls, like #tags at the end of a sentence "
187 251
 		."@comment. I hope noone forgets about @fullstops.because that might"
188 252
 		." break #things. @Mike@campino@friendica.eu is also #nice, isn't it? "
189
-		."Now, add a @first_last tag. "; 
253
+		."Now, add a @first_last tag. ";
190 254
 		//check whether this are all variants (no, auto-stuff is missing).
191 255
 
192 256
 		$tags=get_tags($text);
@@ -210,8 +274,8 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
210 274
 		$tags=get_tags("");
211 275
 		$this->assertEquals(0, count($tags));
212 276
 	}
213
-//function qp, quick and dirty??
214
-//get_mentions
215
-//get_contact_block, bis Zeile 538
277
+	//function qp, quick and dirty??
278
+	//get_mentions
279
+	//get_contact_block, bis Zeile 538
216 280
 }
217 281
 ?>

+ 1
- 1
util/db_update.php View File

@@ -26,7 +26,7 @@ echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n";
26 26
 
27 27
 if($build != DB_UPDATE_VERSION) {
28 28
 	echo "Updating database...";
29
-	check_config();
29
+	check_config($a);
30 30
 	echo "Done\n";
31 31
 }
32 32
 

Loading…
Cancel
Save