]> git.mxchange.org Git - friendica.git/commitdiff
splitted tests into several files
authorAlexander Kampmann <programmer@nurfuerspam.de>
Wed, 14 Mar 2012 11:54:49 +0000 (12:54 +0100)
committerAlexander Kampmann <programmer@nurfuerspam.de>
Wed, 14 Mar 2012 11:54:49 +0000 (12:54 +0100)
tests/autoname_test.php [new file with mode: 0755]
tests/contains_attribute_test.php [new file with mode: 0755]
tests/expand_acl_test.php [new file with mode: 0755]
tests/xss_filter_test.php

diff --git a/tests/autoname_test.php b/tests/autoname_test.php
new file mode 100755 (executable)
index 0000000..9dae920
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+/**
+ * this file contains tests for the autoname function
+ * 
+ * @package test.util
+ */
+
+/** required, it is the file under test */
+require_once('include/text.php');
+
+/**
+ * TestCase for the autoname function
+ * 
+ * @author Alexander Kampmann
+ * @package test.util
+ */
+class AutonameTest extends PHPUnit_Framework_TestCase {
+       /**\r
+        *autonames should be random, even length\r
+        */\r
+       public function testAutonameEven() {\r
+               $autoname1=autoname(10);\r
+               $autoname2=autoname(10);\r
+       \r
+               $this->assertNotEquals($autoname1, $autoname2);\r
+       }\r
+       \r
+       /**\r
+        *autonames should be random, odd length\r
+        */\r
+       public function testAutonameOdd() {\r
+               $autoname1=autoname(9);\r
+               $autoname2=autoname(9);\r
+       \r
+               $this->assertNotEquals($autoname1, $autoname2);\r
+       }\r
+       \r
+       /**\r
+        * try to fail autonames\r
+        */\r
+       public function testAutonameNoLength() {\r
+               $autoname1=autoname(0);\r
+               $this->assertEquals(0, count($autoname1));\r
+       }\r
+       
+       /**
+        * try to fail it with invalid input
+        * 
+        * TODO: What's corect behaviour here? An exception?
+        */\r
+       public function testAutonameNegativeLength() {\r
+               $autoname1=autoname(-23);\r
+               $this->assertEquals(0, count($autoname1));\r
+       }\r
+       \r
+       //      public function testAutonameMaxLength() {\r
+       //              $autoname2=autoname(PHP_INT_MAX);\r
+       //              $this->assertEquals(PHP_INT_MAX, count($autoname2));\r
+       //      }\r
+       
+       /**
+        * test with a length, that may be too short
+        */\r
+       public function testAutonameLength1() {\r
+               $autoname1=autoname(1);\r
+               $this->assertEquals(1, count($autoname1));
+               
+               $autoname2=autoname(1);\r
+               $this->assertEquals(1, count($autoname2));
+               
+               $this->assertFalse($autoname1==$autoname2); \r
+       }
+}
\ No newline at end of file
diff --git a/tests/contains_attribute_test.php b/tests/contains_attribute_test.php
new file mode 100755 (executable)
index 0000000..b0bb06a
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**\r
+ * this test tests the contains_attribute function\r
+ *\r
+ * @package test.util\r
+ */\r
+\r
+/** required, it is the file under test */\r
+require_once('include/text.php');\r
+\r
+/**\r
+ * TestCase for the contains_attribute function\r
+ *\r
+ * @author Alexander Kampmann\r
+ * @package test.util\r
+ */\r
+class ContainsAttributeTest extends PHPUnit_Framework_TestCase {
+       /**\r
+        * test attribute contains\r
+        */\r
+       public function testAttributeContains1() {\r
+               $testAttr="class1 notclass2 class3";\r
+               $this->assertTrue(attribute_contains($testAttr, "class3"));\r
+               $this->assertFalse(attribute_contains($testAttr, "class2"));\r
+       }\r
+       \r
+       /**\r
+        * test attribute contains\r
+        */\r
+       public function testAttributeContains2() {\r
+               $testAttr="class1 not-class2 class3";\r
+               $this->assertTrue(attribute_contains($testAttr, "class3"));\r
+               $this->assertFalse(attribute_contains($testAttr, "class2"));\r
+       }\r
+       
+       /**
+        * test with empty input
+        */\r
+       public function testAttributeContainsEmpty() {\r
+               $testAttr="";\r
+               $this->assertFalse(attribute_contains($testAttr, "class2"));\r
+       }\r
+       
+       /**
+        * test input with special chars
+        */\r
+       public function testAttributeContainsSpecialChars() {\r
+               $testAttr="--... %\$ä() /(=?}";\r
+               $this->assertFalse(attribute_contains($testAttr, "class2"));\r
+       }
+}
\ No newline at end of file
diff --git a/tests/expand_acl_test.php b/tests/expand_acl_test.php
new file mode 100755 (executable)
index 0000000..b516a3f
--- /dev/null
@@ -0,0 +1,142 @@
+<?php
+/**
+ * this test tests the expand_acl function
+ *
+ * @package test.util
+ */
+
+/** required, it is the file under test */
+require_once('include/text.php');
+
+/**\r
+ * TestCase for the expand_acl function\r
+ *\r
+ * @author Alexander Kampmann\r
+ * @package test.util\r
+ */\r
+class ExpandAclTest extends PHPUnit_Framework_TestCase {
+       
+       /**\r
+        * test expand_acl, perfect input\r
+        */\r
+       public function testExpandAclNormal() {\r
+               $text='<1><2><3>';\r
+               $this->assertEquals(array(1, 2, 3), expand_acl($text));\r
+       }\r
+       
+       /**
+        * test with a big number
+        */\r
+       public function testExpandAclBigNumber() {\r
+               $text='<1><'.PHP_INT_MAX.'><15>';\r
+               $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));\r
+       }\r
+       
+       /**
+        * test with a string in it. 
+        * 
+        * TODO: is this valid input? Otherwise: should there be an exception?
+        */\r
+       public function testExpandAclString() {\r
+               $text="<1><279012><tt>"; \r
+               $this->assertEquals(array(1, 279012, 'tt'), expand_acl($text));\r
+       }\r
+       
+       /**
+        * test with a ' ' in it. 
+        * 
+        * TODO: is this valid input? Otherwise: should there be an exception?
+        */\r
+       public function testExpandAclSpace() {\r
+               $text="<1><279 012><32>"; \r
+               $this->assertEquals(array(1, "279 012", "32"), expand_acl($text));\r
+       }\r
+       
+       /**
+        * test empty input
+        */\r
+       public function testExpandAclEmpty() {\r
+               $text=""; \r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }\r
+       
+       /**
+        * test invalid input, no < at all
+        * 
+        * TODO: should there be an exception?
+        */\r
+       public function testExpandAclNoBrackets() {\r
+               $text="According to documentation, that's invalid. "; //should be invalid\r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }\r
+       
+       /**\r
+        * test invalid input, just open <\r
+        *\r
+        * TODO: should there be an exception?\r
+        */\r
+       public function testExpandAclJustOneBracket1() {\r
+               $text="<Another invalid string"; //should be invalid\r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }\r
+       
+       /**\r
+        * test invalid input, just close >\r
+        *\r
+        * TODO: should there be an exception?\r
+        */\r
+       public function testExpandAclJustOneBracket2() {\r
+               $text="Another invalid> string"; //should be invalid\r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }\r
+       
+       /**\r
+        * test invalid input, just close >\r
+        *\r
+        * TODO: should there be an exception?\r
+        */\r
+       public function testExpandAclCloseOnly() {\r
+               $text="Another> invalid> string>"; //should be invalid\r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }\r
+       
+       /**\r
+        * test invalid input, just open <\r
+        *\r
+        * TODO: should there be an exception?\r
+        */\r
+       public function testExpandAclOpenOnly() {\r
+               $text="<Another< invalid string<"; //should be invalid\r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }\r
+       
+       /**\r
+        * test invalid input, open and close do not match\r
+        *\r
+        * TODO: should there be an exception?\r
+        */\r
+       public function testExpandAclNoMatching1() {\r
+               $text="<Another<> invalid <string>"; //should be invalid\r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }\r
+       
+       /**\r
+        * test invalid input, open and close do not match\r
+        *\r
+        * TODO: should there be an exception?\r
+        */\r
+       public function testExpandAclNoMatching2() {\r
+               $text="<1>2><3>";\r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }
+       
+       /**\r
+        * test invalid input, empty <>\r
+        *\r
+        * TODO: should there be an exception? Or array(1, 3)\r
+        */\r
+       public function testExpandAclEmptyMatch() {\r
+               $text="<1><><3>";\r
+               $this->assertEquals(array(), expand_acl($text));\r
+       }
+}
\ No newline at end of file
index fe944c2a748779011ed8e1d5ed69b1e8e641a2f6..d7dcf0472bd698c84df6487d7d1144b2d0e7b1d3 100644 (file)
@@ -1,24 +1,16 @@
 <?php
 /**
+ * tests several functions which are used to prevent xss attacks
+ * 
  * @package test.util
  */
 
-require_once("include/template_processor.php");
 require_once('include/text.php');
 
 class AntiXSSTest extends PHPUnit_Framework_TestCase {
 
-       public function setUp() {
-               set_include_path(\r
-                               get_include_path() . PATH_SEPARATOR\r
-                               . 'include' . PATH_SEPARATOR\r
-                               . 'library' . PATH_SEPARATOR\r
-                               . 'library/phpsec' . PATH_SEPARATOR\r
-                               . '.' );
-       }
-
        /**
-        * test no tags
+        * test, that tags are escaped
         */
        public function testEscapeTags() {
                $invalidstring='<submit type="button" onclick="alert(\'failed!\');" />';
@@ -30,49 +22,6 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals("&lt;submit type=&quot;button&quot; onclick=&quot;alert('failed!');&quot; /&gt;", $escapedString);
        }
 
-       /**
-        *autonames should be random, even length
-        */
-       public function testAutonameEven() {
-               $autoname1=autoname(10);
-               $autoname2=autoname(10);
-
-               $this->assertNotEquals($autoname1, $autoname2);
-       }
-
-       /**
-        *autonames should be random, odd length
-        */
-       public function testAutonameOdd() {
-               $autoname1=autoname(9);
-               $autoname2=autoname(9);
-
-               $this->assertNotEquals($autoname1, $autoname2);
-       }
-
-       /**
-        * try to fail autonames
-        */
-       public function testAutonameNoLength() {
-               $autoname1=autoname(0);
-               $this->assertEquals(0, count($autoname1));
-       }
-
-       public function testAutonameNegativeLength() {
-               $autoname1=autoname(-23);
-               $this->assertEquals(0, count($autoname1));
-       }
-
-       //      public function testAutonameMaxLength() {
-       //              $autoname2=autoname(PHP_INT_MAX);
-       //              $this->assertEquals(PHP_INT_MAX, count($autoname2));
-       //      }
-
-       public function testAutonameLength1() {
-               $autoname3=autoname(1);
-               $this->assertEquals(1, count($autoname3));
-       }
-
        /**
         *xmlify and unxmlify
         */
@@ -87,7 +36,6 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
        /**
         * test hex2bin and reverse
         */
-
        public function testHex2Bin() {
                $this->assertEquals(-3, hex2bin(bin2hex(-3)));
                $this->assertEquals(0, hex2bin(bin2hex(0)));
@@ -95,97 +43,6 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX)));
        }
 
-       /**
-        * test expand_acl
-        */
-       public function testExpandAclNormal() {
-               $text="<1><2><3>";
-               $this->assertEquals(array(1, 2, 3), expand_acl($text));
-       }
-
-       public function testExpandAclBigNumber() {
-               $text="<1><279012><15>";
-               $this->assertEquals(array(1, 279012, 15), expand_acl($text));
-       }
-
-       public function testExpandAclString() {
-               $text="<1><279012><tt>"; //maybe that's invalid
-               $this->assertEquals(array(1, 279012, 'tt'), expand_acl($text));
-       }
-
-       public function testExpandAclSpace() {
-               $text="<1><279 012><32>"; //maybe that's invalid
-               $this->assertEquals(array(1, "279 012", "32"), expand_acl($text));
-       }
-
-       public function testExpandAclEmpty() {
-               $text=""; //maybe that's invalid
-               $this->assertEquals(array(), expand_acl($text));
-       }
-
-       public function testExpandAclNoBrackets() {
-               $text="According to documentation, that's invalid. "; //should be invalid
-               $this->assertEquals(array(), expand_acl($text));
-       }
-
-       public function testExpandAclJustOneBracket1() {
-               $text="<Another invalid string"; //should be invalid
-               $this->assertEquals(array(), expand_acl($text));
-       }
-
-       public function testExpandAclJustOneBracket2() {
-               $text="Another invalid> string"; //should be invalid
-               $this->assertEquals(array(), expand_acl($text));
-       }
-
-       public function testExpandAclCloseOnly() {
-               $text="Another> invalid> string>"; //should be invalid
-               $this->assertEquals(array(), expand_acl($text));
-       }
-
-       public function testExpandAclOpenOnly() {
-               $text="<Another< invalid string<"; //should be invalid
-               $this->assertEquals(array(), expand_acl($text));
-       }
-
-       public function testExpandAclNoMatching1() {
-               $text="<Another<> invalid <string>"; //should be invalid
-               $this->assertEquals(array(), expand_acl($text));
-       }
-
-       public function testExpandAclNoMatching2() {
-               $text="<1>2><3>";
-               $this->assertEquals(array(), expand_acl($text));
-       }
-
-       /**
-        * test attribute contains
-        */
-       public function testAttributeContains1() {
-               $testAttr="class1 notclass2 class3";
-               $this->assertTrue(attribute_contains($testAttr, "class3"));
-               $this->assertFalse(attribute_contains($testAttr, "class2"));
-       }
-
-       /**
-        * test attribute contains
-        */
-       public function testAttributeContains2() {
-               $testAttr="class1 not-class2 class3";
-               $this->assertTrue(attribute_contains($testAttr, "class3"));
-               $this->assertFalse(attribute_contains($testAttr, "class2"));
-       }
-
-       public function testAttributeContainsEmpty() {
-               $testAttr="";
-               $this->assertFalse(attribute_contains($testAttr, "class2"));
-       }
-
-       public function testAttributeContainsSpecialChars() {
-               $testAttr="--... %\$ä() /(=?}";
-               $this->assertFalse(attribute_contains($testAttr, "class2"));
-       }
-
        //function qp, quick and dirty??
        //get_mentions
        //get_contact_block, bis Zeile 538