]> git.mxchange.org Git - friendica.git/commitdiff
added some tests
authorAlexander Kampmann <programmer@nurfuerspam.de>
Fri, 9 Mar 2012 11:16:58 +0000 (12:16 +0100)
committerAlexander Kampmann <programmer@nurfuerspam.de>
Fri, 9 Mar 2012 11:16:58 +0000 (12:16 +0100)
build.xml
tests/xss_filter_test.php
util/db_update.php

index 0f574507260a2af6399a87b64d6d9d9dad56d330..a61a5123d7cef5d13bd060cefd4e3300f03add48 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1,16 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <project name="friendica" default="test">
-       <!-- set up include directories, this is necessary for the tests to work -->
-       <php>
-               set_include_path(
-                                       get_include_path() . PATH_SEPARATOR
-                                       . 'include' . PATH_SEPARATOR 
-                                       . 'library' . PATH_SEPARATOR 
-                                       . 'library/phpsec' . PATH_SEPARATOR 
-                                       . '.' );
-       </php>
-       
        <!-- ====================================================== -->
        <!-- Target: clean-test -->
        <!-- deletes directories with old test reports -->
        <!-- this target runs all test files -->
        <!-- =================================== -->
        <target name="test" depends="prepare-test">
-               <coverage-setup database="./report/coverage-database">
+               <!-- coverage-setup database="./report/coverage-database">
                        <fileset dir=".">
                                <include name="**/*.php" />
                                <exclude name="*test.php"/>
-                               <exclude name="./index.php"/>
-                               <exclude name="./library/**"/>
+                               <exclude name="index.php"/>
+                               <exclude name="library/**"/>
                                <exclude name="doc/**"/>
+                               <exclude name=".."/>
                        </fileset>
-               </coverage-setup>
-               <phpunit printsummary="true" >
+               </coverage-setup -->
+               <phpunit printsummary="true">
                        <batchtest>
                                <fileset dir="tests">
                                        <include name="*test.php" />
@@ -50,9 +41,9 @@
                        <formatter type="xml" todir="report" outfile="testlog.xml" />
                </phpunit>
                <phpunitreport infile="report/testlog.xml" todir="report" />
-               <coverage-report outfile="report/coverage-database">
+               <!-- coverage-report outfile="report/coverage-database">
                      <report todir="report" styledir="/home/phing/etc" />
-                   </coverage-report>
+                   </coverage-report -->
        </target>
 
        <!-- ===================================================== -->
@@ -75,6 +66,9 @@
                <docblox title="Friendica API" destdir="./doc/api">
                        <fileset dir=".">
                                <include name="**/*.php" />
+                               <include name="README"/>
+                               <include name="INSTALL.txt"/>
+                               <include name="LICENSE"/>
                        </fileset>
                </docblox>
        </target>
index e480ef7ec0e94df6e0200dda3c53b6d580be6638..00e97cf98e4861673922600c5cb9cdf196b59eab 100644 (file)
@@ -1,16 +1,26 @@
 <?php
 /**
-* Tests, without pHPUnit by now
-* @package test.util
-*/
+ * Tests, without pHPUnit by now
+ * @package test.util
+ */
 
-require_once('include/text.php'); 
+require_once("include/template_processor.php");
+require_once('include/text.php');
 
 class AntiXSSTest extends PHPUnit_Framework_TestCase {
 
-/**
-* test no tags
-*/
+       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
+        */
        public function testEscapeTags() {
                $invalidstring='<submit type="button" onclick="alert(\'failed!\');" />';
 
@@ -53,12 +63,12 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $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 testAutonameMaxLength() {
+       //              $autoname2=autoname(PHP_INT_MAX);
+       //              $this->assertEquals(PHP_INT_MAX, count($autoname2));
+       //      }
+
        public function testAutonameLength1() {
                $autoname3=autoname(1);
                $this->assertEquals(1, count($autoname3));
@@ -68,7 +78,7 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
         *xmlify and unxmlify
         */
        public function testXmlify() {
-               $text="<tag>I want to break\n this!11!<?hard?></tag>"; 
+               $text="<tag>I want to break\n this!11!<?hard?></tag>";
                $xml=xmlify($text); //test whether it actually may be part of a xml document
                $retext=unxmlify($text);
 
@@ -85,7 +95,7 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals(12, hex2bin(bin2hex(12)));
                $this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX)));
        }
-       
+
        /**
         * test expand_acl
         */
@@ -93,7 +103,7 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $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));
@@ -133,19 +143,19 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $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>"; 
+               $text="<1>2><3>";
                $this->assertEquals(array(), expand_acl($text));
        }
 
@@ -166,7 +176,7 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $this->assertTrue(attribute_contains($testAttr, "class3"));
                $this->assertFalse(attribute_contains($testAttr, "class2"));
        }
-       
+
        public function testAttributeContainsEmpty() {
                $testAttr="";
                $this->assertFalse(attribute_contains($testAttr, "class2"));
@@ -176,17 +186,71 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $testAttr="--... %\$รค() /(=?}";
                $this->assertFalse(attribute_contains($testAttr, "class2"));
        }
-       
+
        /**
         * test get_tags
         */
+       public function testGetTagsShortPerson() {
+               $text="hi @Mike"; 
+               
+               $tags=get_tags($text);
+               
+               $this->assertEquals("@Mike", $tags[0]);
+       }
+       
+       public function testGetTagsShortTag() {\r
+               $text="This is a #test_case";\r
+       \r
+               $tags=get_tags($text);\r
+       \r
+               $this->assertEquals("#test_case", $tags[0]);\r
+       }
+       
+       public function testGetTagsShortTagAndPerson() {\r
+               $text="hi @Mike This is a #test_case";\r
+       \r
+               $tags=get_tags($text);\r
+       
+               $this->assertEquals("@Mike", $tags[0]);\r
+               $this->assertEquals("#test_case", $tags[1]);\r
+       }
+       
+       public function testGetTagsShortTagAndPersonSpecialChars() {\r
+               $text="hi @Mike, This is a #test_case.";\r
+       \r
+               $tags=get_tags($text);\r
+       \r
+               $this->assertEquals("@Mike", $tags[0]);\r
+               $this->assertEquals("#test_case", $tags[1]);\r
+       }
+       
+       public function testGetTagsPersonOnly() {
+               $text="@Mike I saw the Theme Dev group was created."; 
+               
+               $tags=get_tags($text);\r
+               \r
+               $this->assertEquals("@Mike", $tags[0]);
+       }
+       
+       public function testGetTags2Persons1TagSpecialChars() {\r
+               $text="hi @Mike, I'm just writing #test_cases, so"
+               ." so @somebody@friendica.com may change #things.";\r
+       \r
+               $tags=get_tags($text);\r
+       \r
+               $this->assertEquals("@Mike", $tags[0]);\r
+               $this->assertEquals("#test_cases", $tags[1]);
+               $this->assertEquals("@somebody@friendica.com", $tags[2]);
+               $this->assertEquals("#things", $tags[3]);\r
+       }
+       
        public function testGetTags() {
                $text="hi @Mike, I'm just writing #test_cases, "
                ." so @somebody@friendica.com may change #things. Of course I "
                ."look for a lot of #pitfalls, like #tags at the end of a sentence "
                ."@comment. I hope noone forgets about @fullstops.because that might"
                ." break #things. @Mike@campino@friendica.eu is also #nice, isn't it? "
-               ."Now, add a @first_last tag. "; 
+               ."Now, add a @first_last tag. ";
                //check whether this are all variants (no, auto-stuff is missing).
 
                $tags=get_tags($text);
@@ -210,8 +274,8 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
                $tags=get_tags("");
                $this->assertEquals(0, count($tags));
        }
-//function qp, quick and dirty??
-//get_mentions
-//get_contact_block, bis Zeile 538
+       //function qp, quick and dirty??
+       //get_mentions
+       //get_contact_block, bis Zeile 538
 }
 ?>
index a6177324aced4fc9cd19a3f2237d6b23f18c4d14..35620e80b756dda2e84594a9304a540896a9f9a6 100755 (executable)
@@ -26,7 +26,7 @@ echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n";
 
 if($build != DB_UPDATE_VERSION) {
        echo "Updating database...";
-       check_config();
+       check_config($a);
        echo "Done\n";
 }