From b92e3ca3ee3f8bed1ff52311d29b4ce1e4297a83 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Wed, 12 Oct 2016 21:50:49 +0200 Subject: [TASK] Restructure tests/ folder. Move unit tests to tests/unit/. Get the old still working UnitTests into a working state again. Updated composer.json with required-dev packages. Create a new folder tests/acceptance for Behat functional/acceptance testing. Add a first Feature draft of a Behat functional test for local login. --- tests/README.md | 25 ++ tests/acceptance/behat.yml | 27 ++ .../acceptance/features/bootstrap/AdminContext.php | 23 ++ tests/acceptance/features/bootstrap/ApiContext.php | 23 ++ .../features/bootstrap/FeatureContext.php | 23 ++ tests/acceptance/features/login_local.feature | 18 ++ tests/autoname_test.php | 76 ----- tests/contains_attribute_test.php | 51 ---- tests/expand_acl_test.php | 148 ---------- tests/get_tags_test.php | 326 --------------------- tests/template_test.php | 224 -------------- tests/text_test.php | 31 -- tests/unit/AntiXSSTest.php | 73 +++++ tests/unit/AutonameTest.php | 78 +++++ tests/unit/ContainsAttributeTest.php | 53 ++++ tests/unit/TextTest.php | 33 +++ tests/unit/UnitTestCase.php | 38 +++ tests/unit/UploadTest.php | 31 ++ tests/unit/expand_acl_test.php | 148 ++++++++++ tests/unit/get_tags_test.php | 326 +++++++++++++++++++++ tests/unit/template_test.php | 224 ++++++++++++++ tests/upload_test.php | 29 -- tests/xss_filter_test.php | 71 ----- 23 files changed, 1143 insertions(+), 956 deletions(-) create mode 100644 tests/README.md create mode 100644 tests/acceptance/behat.yml create mode 100644 tests/acceptance/features/bootstrap/AdminContext.php create mode 100644 tests/acceptance/features/bootstrap/ApiContext.php create mode 100644 tests/acceptance/features/bootstrap/FeatureContext.php create mode 100644 tests/acceptance/features/login_local.feature delete mode 100644 tests/autoname_test.php delete mode 100644 tests/contains_attribute_test.php delete mode 100644 tests/expand_acl_test.php delete mode 100644 tests/get_tags_test.php delete mode 100644 tests/template_test.php delete mode 100644 tests/text_test.php create mode 100644 tests/unit/AntiXSSTest.php create mode 100644 tests/unit/AutonameTest.php create mode 100644 tests/unit/ContainsAttributeTest.php create mode 100644 tests/unit/TextTest.php create mode 100644 tests/unit/UnitTestCase.php create mode 100644 tests/unit/UploadTest.php create mode 100644 tests/unit/expand_acl_test.php create mode 100644 tests/unit/get_tags_test.php create mode 100644 tests/unit/template_test.php delete mode 100644 tests/upload_test.php delete mode 100644 tests/xss_filter_test.php (limited to 'tests') diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 000000000..395333159 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,25 @@ +The folder tests/ contains resources for automated testing tools. + +Here you will find PHPUnit, Behat, etc. files to test the functionaly +of Hubzilla. Right now it only contains some basic tests to see if feasable +this can help improve the project. + +# Contents + +* unit/ PHPUnit tests +These are unit tests to check the smallest parts, like single functions. +It uses the tool PHPUnit https://phpunit.de/ + +* acceptance/ functional/acceptance testing +These are behavioral or so called functional/acceptance testing. They +are used to test business logic. They are written in Gherkin and use +the tool Behat http://behat.org/ + +# How to use? +You need the dev tools which are defined in the composer.json in the +require-dev configuration. +Run ```composer install``` without --no-dev to install these tools. + +To run unit tests run ```vendor/bin/phpunit tests/unit/``` + +To run acceptance tests run ```vendor/bin/behat --config tests/acceptance/behat.yml``` diff --git a/tests/acceptance/behat.yml b/tests/acceptance/behat.yml new file mode 100644 index 000000000..933571e5e --- /dev/null +++ b/tests/acceptance/behat.yml @@ -0,0 +1,27 @@ +default: + suites: + default: + paths: + - %paths.base%/features + contexts: + - Behat\MinkExtension\Context\MinkContext + admin_features: + filters: { role: admin } + contexts: + - AdminContext + api_features: + paths: + - %paths.base%/features/api + filters: + tags: "@api" + contexts: + - ApiContext + gherkin: + filters: + tags: ~@wip + extensions: + Behat\MinkExtension: + base_url: 'http://localhost' + sessions: + default: + goutte: ~ diff --git a/tests/acceptance/features/bootstrap/AdminContext.php b/tests/acceptance/features/bootstrap/AdminContext.php new file mode 100644 index 000000000..aa4dced67 --- /dev/null +++ b/tests/acceptance/features/bootstrap/AdminContext.php @@ -0,0 +1,23 @@ +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, strlen($autoname1)); - } - - /** - * try to fail it with invalid input - * - * TODO: What's corect behaviour here? An exception? - */ - public function testAutonameNegativeLength() { - $autoname1=autoname(-23); - $this->assertEquals(0, strlen($autoname1)); - } - - // public function testAutonameMaxLength() { - // $autoname2=autoname(PHP_INT_MAX); - // $this->assertEquals(PHP_INT_MAX, count($autoname2)); - // } - - /** - * test with a length, that may be too short - */ - public function testAutonameLength1() { - $autoname1=autoname(1); - $this->assertEquals(1, count($autoname1)); - - $autoname2=autoname(1); - $this->assertEquals(1, count($autoname2)); - - // The following test is problematic, with only 26 possibilities - // generating the same thing twice happens often aka - // birthday paradox -// $this->assertFalse($autoname1==$autoname2); - } -} \ No newline at end of file diff --git a/tests/contains_attribute_test.php b/tests/contains_attribute_test.php deleted file mode 100644 index b0bb06acf..000000000 --- a/tests/contains_attribute_test.php +++ /dev/null @@ -1,51 +0,0 @@ -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")); - } - - /** - * test with empty input - */ - public function testAttributeContainsEmpty() { - $testAttr=""; - $this->assertFalse(attribute_contains($testAttr, "class2")); - } - - /** - * test input with special chars - */ - public function testAttributeContainsSpecialChars() { - $testAttr="--... %\$ä() /(=?}"; - $this->assertFalse(attribute_contains($testAttr, "class2")); - } -} \ No newline at end of file diff --git a/tests/expand_acl_test.php b/tests/expand_acl_test.php deleted file mode 100644 index 154bc921d..000000000 --- a/tests/expand_acl_test.php +++ /dev/null @@ -1,148 +0,0 @@ -<2><3>'; - $this->assertEquals(array(1, 2, 3), expand_acl($text)); - } - - /** - * test with a big number - */ - public function testExpandAclBigNumber() { - $text='<1><'.PHP_INT_MAX.'><15>'; - $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text)); - } - - /** - * test with a string in it. - * - * TODO: is this valid input? Otherwise: should there be an exception? - */ - public function testExpandAclString() { - $text="<1><279012>"; - $this->assertEquals(array(1, 279012), expand_acl($text)); - } - - /** - * test with a ' ' in it. - * - * TODO: is this valid input? Otherwise: should there be an exception? - */ - public function testExpandAclSpace() { - $text="<1><279 012><32>"; - $this->assertEquals(array(1, "279", "32"), expand_acl($text)); - } - - /** - * test empty input - */ - public function testExpandAclEmpty() { - $text=""; - $this->assertEquals(array(), expand_acl($text)); - } - - /** - * test invalid input, no < at all - * - * TODO: should there be an exception? - */ - public function testExpandAclNoBrackets() { - $text="According to documentation, that's invalid. "; //should be invalid - $this->assertEquals(array(), expand_acl($text)); - } - - /** - * test invalid input, just open < - * - * TODO: should there be an exception? - */ - public function testExpandAclJustOneBracket1() { - $text="assertEquals(array(), expand_acl($text)); - } - - /** - * test invalid input, just close > - * - * TODO: should there be an exception? - */ - public function testExpandAclJustOneBracket2() { - $text="Another invalid> string"; //should be invalid - $this->assertEquals(array(), expand_acl($text)); - } - - /** - * test invalid input, just close > - * - * TODO: should there be an exception? - */ - public function testExpandAclCloseOnly() { - $text="Another> invalid> string>"; //should be invalid - $this->assertEquals(array(), expand_acl($text)); - } - - /** - * test invalid input, just open < - * - * TODO: should there be an exception? - */ - public function testExpandAclOpenOnly() { - $text="assertEquals(array(), expand_acl($text)); - } - - /** - * test invalid input, open and close do not match - * - * TODO: should there be an exception? - */ - public function testExpandAclNoMatching1() { - $text=" invalid "; //should be invalid - $this->assertEquals(array(), expand_acl($text)); - } - - /** - * test invalid input, open and close do not match - * - * TODO: should there be an exception? - */ - public function testExpandAclNoMatching2() { - $text="<1>2><3>"; -// The angles are delimiters which aren't important -// the important thing is the numeric content, this returns array(1,2,3) currently -// we may wish to eliminate 2 from the results, though it isn't harmful -// It would be a better test to figure out if there is any ACL input which can -// produce this $text and fix that instead. -// $this->assertEquals(array(), expand_acl($text)); - } - - /** - * test invalid input, empty <> - * - * TODO: should there be an exception? Or array(1, 3) - * (This should be array(1,3) - mike) - */ - public function testExpandAclEmptyMatch() { - $text="<1><><3>"; - $this->assertEquals(array(1,3), expand_acl($text)); - } -} \ No newline at end of file diff --git a/tests/get_tags_test.php b/tests/get_tags_test.php deleted file mode 100644 index 40f016747..000000000 --- a/tests/get_tags_test.php +++ /dev/null @@ -1,326 +0,0 @@ -15, - 'attag'=>'', 'network'=>'dfrn', - 'name'=>'Mike Lastname', 'alias'=>'Mike', - 'nick'=>'Mike', 'url'=>"http://justatest.de")); - - $args=func_get_args(); - - //last parameter is always (in this test) uid, so, it should be 11 - if($args[count($args)-1]!=11) { - return; - } - - - if(3==count($args)) { - //first call in handle_body, id only - if($result[0]['id']==$args[1]) { - return $result; - } - //second call in handle_body, name - if($result[0]['name']===$args[1]) { - return $result; - } - } - //third call in handle_body, nick or attag - if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) { - return $result; - } -} - -/** - * replacement for dbesc. - * I don't want to test dbesc here, so - * I just return the input. It won't be a problem, because - * the test does not use a real database. - * - * DON'T USE HAT FUNCTION OUTSIDE A TEST! - * - * @param string $str - * @return input - */ -function dbesc($str) { - return $str; -} - -/** - * TestCase for tag handling. - * - * @author alexander - * @package test.util - */ -class GetTagsTest extends PHPUnit_Framework_TestCase { - /** the mock to use as app */ - private $a; - - /** - * initialize the test. That's a phpUnit function, - * don't change its name. - */ - public function setUp() { - $this->a=new MockApp(); - } - - /** - * test with one Person tag - */ - public function testGetTagsShortPerson() { - $text="hi @Mike"; - - $tags=get_tags($text); - - $inform=''; - $str_tags=''; - foreach($tags as $tag) { - handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); - } - - //correct tags found? - $this->assertEquals(1, count($tags)); - $this->assertTrue(in_array("@Mike", $tags)); - - //correct output from handle_tag? - $this->assertEquals("cid:15", $inform); - $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); - $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url]", $text); - } - - /** - * test with one Person tag. - * There's a minor spelling mistake... - */ - public function testGetTagsShortPersonSpelling() { - $text="hi @Mike.because"; - - $tags=get_tags($text); - - //correct tags found? - $this->assertEquals(1, count($tags)); - $this->assertTrue(in_array("@Mike.because", $tags)); - - $inform=''; - $str_tags=''; - handle_tag($this->a, $text, $inform, $str_tags, 11, $tags[0]); - - // (mike) - This is a tricky case. - // we support mentions as in @mike@example.com - which contains a period. - // This shouldn't match anything unless you have a contact named "Mike.because". - // We may need another test for "@Mike. because" - which should return the contact - // as we ignore trailing periods in tags. - -// $this->assertEquals("cid:15", $inform); -// $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); -// $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url].because", $text); - - $this->assertEquals("", $inform); - $this->assertEquals("", $str_tags); - - } - - /** - * test with two Person tags. - * There's a minor spelling mistake... - */ - - public function testGetTagsPerson2Spelling() { - $text="hi @Mike@campino@friendica.eu"; - - $tags=get_tags($text); - -// This construct is not supported. Results are indeterminate -// $this->assertEquals(2, count($tags)); -// $this->assertTrue(in_array("@Mike", $tags)); -// $this->assertTrue(in_array("@campino@friendica.eu", $tags)); - } - - /** - * Test with one hash tag. - */ - public function testGetTagsShortTag() { - $text="This is a #test_case"; - - $tags=get_tags($text); - - $this->assertEquals(1, count($tags)); - $this->assertTrue(in_array("#test_case", $tags)); - } - - /** - * test with a person and a hash tag - */ - public function testGetTagsShortTagAndPerson() { - $text="hi @Mike This is a #test_case"; - - $tags=get_tags($text); - - $this->assertEquals(3, count($tags)); - $this->assertTrue(in_array("@Mike", $tags)); - $this->assertTrue(in_array("@Mike This", $tags)); - $this->assertTrue(in_array("#test_case", $tags)); - - $inform=''; - $str_tags=''; - foreach($tags as $tag) { - handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); - } - - $this->assertEquals("cid:15", $inform); - $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url],#[url=baseurl/search?tag=test%20case]test case[/url]", $str_tags); - $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url] This is a #[url=baseurl/search?tag=test%20case]test case[/url]", $text); - - } - - /** - * test with a person, a hash tag and some special chars. - */ - public function testGetTagsShortTagAndPersonSpecialChars() { - $text="hi @Mike, This is a #test_case."; - - $tags=get_tags($text); - - $this->assertEquals(2, count($tags)); - $this->assertTrue(in_array("@Mike", $tags)); - $this->assertTrue(in_array("#test_case", $tags)); - } - - /** - * Test with a person tag and text behind it. - */ - public function testGetTagsPersonOnly() { - $text="@Test I saw the Theme Dev group was created."; - - $tags=get_tags($text); - - $this->assertEquals(2, count($tags)); - $this->assertTrue(in_array("@Test I", $tags)); - $this->assertTrue(in_array("@Test", $tags)); - } - - /** - * this test demonstrates strange behaviour by intval. - * It makes the next test fail. - */ - public function testIntval() { - $this->assertEquals(15, intval("15 it")); - } - - /** - * test a tag with an id in it - */ - public function testIdTag() { - $text="Test with @mike+15 id tag"; - - $tags=get_tags($text); - - $this->assertEquals(2, count($tags)); - $this->assertTrue(in_array("@mike+15", $tags)); - - //happens right now, but it shouldn't be necessary - $this->assertTrue(in_array("@mike+15 id", $tags)); - - $inform=''; - $str_tags=''; - foreach($tags as $tag) { - handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); - } - - $this->assertEquals("Test with @[url=http://justatest.de]Mike Lastname[/url] id tag", $text); - $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); - // this test may produce two cid:15 entries - which is OK because duplicates are pruned before delivery - $this->assertContains("cid:15",$inform); - } - - /** - * test with two persons and one special tag. - */ - public function testGetTags2Persons1TagSpecialChars() { - $text="hi @Mike, I'm just writing #test_cases, so" - ." so @somebody@friendica.com may change #things."; - - $tags=get_tags($text); - - $this->assertEquals(5, count($tags)); - $this->assertTrue(in_array("@Mike", $tags)); - $this->assertTrue(in_array("#test_cases", $tags)); - $this->assertTrue(in_array("@somebody@friendica.com", $tags)); - $this->assertTrue(in_array("@somebody@friendica.com may", $tags)); - $this->assertTrue(in_array("#things", $tags)); - } - - /** - * test with a long text. - */ - 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. "; - - $tags=get_tags($text); - - $this->assertTrue(in_array("@Mike", $tags)); - $this->assertTrue(in_array("#test_cases", $tags)); - $this->assertTrue(in_array("@somebody@friendica.com", $tags)); - $this->assertTrue(in_array("#things", $tags)); - $this->assertTrue(in_array("#pitfalls", $tags)); - $this->assertTrue(in_array("#tags", $tags)); - $this->assertTrue(in_array("@comment", $tags)); - $this->assertTrue(in_array("@fullstops.because", $tags)); - $this->assertTrue(in_array("#things", $tags)); - $this->assertTrue(in_array("@Mike", $tags)); - $this->assertTrue(in_array("#nice", $tags)); - $this->assertTrue(in_array("@first_last", $tags)); - - //right now, none of the is matched (unsupported) -// $this->assertFalse(in_array("@Mike@campino@friendica.eu", $tags)); -// $this->assertTrue(in_array("@campino@friendica.eu", $tags)); -// $this->assertTrue(in_array("@campino@friendica.eu is", $tags)); - } - - /** - * test with an empty string - */ - public function testGetTagsEmpty() { - $tags=get_tags(""); - $this->assertEquals(0, count($tags)); - } -} \ No newline at end of file diff --git a/tests/template_test.php b/tests/template_test.php deleted file mode 100644 index 1f9f80531..000000000 --- a/tests/template_test.php +++ /dev/null @@ -1,224 +0,0 @@ -assertTrue(is_null($second)); - } - - public function testSimpleVariableString() { - $tpl='Hello $name!'; - - $text=replace_macros($tpl, array('$name'=>'Anna')); - - $this->assertEquals('Hello Anna!', $text); - } - - public function testSimpleVariableInt() { - $tpl='There are $num new messages!'; - - $text=replace_macros($tpl, array('$num'=>172)); - - $this->assertEquals('There are 172 new messages!', $text); - } - - public function testConditionalElse() { - $tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!'; - - $text1=replace_macros($tpl, array('$num'=>1)); - $text22=replace_macros($tpl, array('$num'=>22)); - - $this->assertEquals('There is 1 new message!', $text1); - $this->assertEquals('There are 22 new messages!', $text22); - } - - public function testConditionalNoElse() { - $tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}'; - - $text0=replace_macros($tpl, array('$num'=>0)); - $text22=replace_macros($tpl, array('$num'=>22)); - - $this->assertEquals('', $text0); - $this->assertEquals('There are 22 new messages!', $text22); - } - - public function testConditionalFail() { - $tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!'; - - $text1=replace_macros($tpl, array()); - - //$this->assertEquals('There is 1 new message!', $text1); - } - - public function testSimpleFor() { - $tpl='{{ for $messages as $message }} $message {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2'))); - - $this->assertEquals(' message 1 message 2 ', $text); - } - - public function testFor() { - $tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike')))); - - $this->assertEquals(' from: Mike to Alex from: Alex to Mike ', $text); - } - - public function testKeyedFor() { - $tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike'))); - - $this->assertEquals(' from: Mike to Alex from: Sven to Mike ', $text); - } - - public function testForEmpty() { - $tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array())); - - $this->assertEquals('messages: ', $text); - } - - public function testForWrongType() { - $tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>11)); - - $this->assertEquals('messages: ', $text); - } - - public function testForConditional() { - $tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array( - array('new'=>true, 'text'=>'new message'), - array('new'=>false, 'text'=>'old message')))); - - $this->assertEquals('new messages: new message', $text); - } - - public function testConditionalFor() { - $tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}'; - - $text=replace_macros($tpl, array('$enabled'=>true, - '$messages'=>array( - array('new'=>true, 'text'=>'new message'), - array('new'=>false, 'text'=>'old message')))); - - $this->assertEquals('new messages: new message old message', $text); - } - - public function testFantasy() { - $tpl='Fantasy: {{fantasy $messages}}'; - - $text=replace_macros($tpl, array('$messages'=>'no no')); - - $this->assertEquals('Fantasy: {{fantasy no no}}', $text); - } - - public function testInc() { - $tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}'; - - $text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help'))); - - $this->assertEquals(" \n" - ."
\n" - ." \n" - ." \n" - ." help\n" - ."
\n", $text); - } - - public function testIncNoVar() { - $tpl='{{inc field_input.tpl }}{{ endinc }}'; - - $text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help'))); - - $this->assertEquals(" \n
\n \n" - ." \n" - ." help\n" - ."
\n", $text); - } - - public function testDoubleUse() { - $tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}'; - - $text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false)); - - $this->assertEquals('Hello Anna! ', $text); - - $tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}'; - - $text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true)); - - $this->assertEquals('Hey Max! I hate you! ', $text); - } - - public function testIncDouble() { - $tpl='{{inc field_input.tpl with $field=$var1}}{{ endinc }}' - .'{{inc field_input.tpl with $field=$var2}}{{ endinc }}'; - - $text=replace_macros($tpl, array('$var1'=>array('myfield', 'label', 'value', 'help'), - '$var2'=>array('myfield2', 'label2', 'value2', 'help2'))); - - $this->assertEquals(" \n" - ."
\n" - ." \n" - ." \n" - ." help\n" - ."
\n" - ." \n" - ."
\n" - ." \n" - ." \n" - ." help2\n" - ."
\n", $text); - } -} \ No newline at end of file diff --git a/tests/text_test.php b/tests/text_test.php deleted file mode 100644 index d1e210b68..000000000 --- a/tests/text_test.php +++ /dev/null @@ -1,31 +0,0 @@ -assertTrue(valid_email_regex('ken@spaz.org')); - } - public function testGoodEmail2() { - $this->assertTrue(valid_email_regex('ken@restivo.org')); - } - public function testGoodEmail3() { - $this->assertTrue(valid_email_regex('nobody@hubzilla.com')); - } - public function testBadEmail() { - $this->assertFalse(valid_email_regex('nobody!uses!these!any.more')); - } - -} \ No newline at end of file diff --git a/tests/unit/AntiXSSTest.php b/tests/unit/AntiXSSTest.php new file mode 100644 index 000000000..b45042a1e --- /dev/null +++ b/tests/unit/AntiXSSTest.php @@ -0,0 +1,73 @@ +'; + + $validstring=notags($invalidstring); + $escapedString=escape_tags($invalidstring); + + $this->assertEquals('[submit type="button" onclick="alert(\'failed!\');" /]', $validstring); + $this->assertEquals("<submit type="button" onclick="alert('failed!');" />", $escapedString); + } + + /** + *xmlify and unxmlify + */ + public function testXmlify() { + $text="I want to break\n this!11!"; + $xml=xmlify($text); + $retext=unxmlify($text); + + $this->assertEquals($text, $retext); + } + + /** + * xmlify and put in a document + */ + public function testXmlifyDocument() { + $tag="I want to break"; + $xml=xmlify($tag); + $text=''.$xml.''; + + $xml_parser=xml_parser_create(); + //should be possible to parse it + $values=array(); $index=array(); + $this->assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index)); + + $this->assertEquals(array('TEXT'=>array(0)), + $index); + $this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)), + $values); + + xml_parser_free($xml_parser); + } + + /** + * test hex2bin and reverse + */ + public function testHex2Bin() { + $this->assertEquals(-3, hex2bin(bin2hex(-3))); + $this->assertEquals(0, hex2bin(bin2hex(0))); + $this->assertEquals(12, hex2bin(bin2hex(12))); + $this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX))); + } + + //function qp, quick and dirty?? + //get_mentions + //get_contact_block, bis Zeile 538 +} +?> diff --git a/tests/unit/AutonameTest.php b/tests/unit/AutonameTest.php new file mode 100644 index 000000000..9f92f736f --- /dev/null +++ b/tests/unit/AutonameTest.php @@ -0,0 +1,78 @@ +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, strlen($autoname1)); + } + + /** + * try to fail it with invalid input + * + * TODO: What's corect behaviour here? An exception? + */ + public function testAutonameNegativeLength() { + $autoname1=autoname(-23); + $this->assertEquals(0, strlen($autoname1)); + } + + // public function testAutonameMaxLength() { + // $autoname2=autoname(PHP_INT_MAX); + // $this->assertEquals(PHP_INT_MAX, count($autoname2)); + // } + + /** + * test with a length, that may be too short + */ + public function testAutonameLength1() { + $autoname1=autoname(1); + $this->assertEquals(1, count($autoname1)); + + $autoname2=autoname(1); + $this->assertEquals(1, count($autoname2)); + + // The following test is problematic, with only 26 possibilities + // generating the same thing twice happens often aka + // birthday paradox +// $this->assertFalse($autoname1==$autoname2); + } +} \ No newline at end of file diff --git a/tests/unit/ContainsAttributeTest.php b/tests/unit/ContainsAttributeTest.php new file mode 100644 index 000000000..0930d9837 --- /dev/null +++ b/tests/unit/ContainsAttributeTest.php @@ -0,0 +1,53 @@ +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")); + } + + /** + * test with empty input + */ + public function testAttributeContainsEmpty() { + $testAttr=""; + $this->assertFalse(attribute_contains($testAttr, "class2")); + } + + /** + * test input with special chars + */ + public function testAttributeContainsSpecialChars() { + $testAttr="--... %\$ä() /(=?}"; + $this->assertFalse(attribute_contains($testAttr, "class2")); + } +} \ No newline at end of file diff --git a/tests/unit/TextTest.php b/tests/unit/TextTest.php new file mode 100644 index 000000000..48c04bc54 --- /dev/null +++ b/tests/unit/TextTest.php @@ -0,0 +1,33 @@ +assertTrue(valid_email_regex('ken@spaz.org')); + } + public function testGoodEmail2() { + $this->assertTrue(valid_email_regex('ken@restivo.org')); + } + public function testGoodEmail3() { + $this->assertTrue(valid_email_regex('nobody@hubzilla.com')); + } + public function testBadEmail() { + $this->assertFalse(valid_email_regex('nobody!uses!these!any.more')); + } + +} \ No newline at end of file diff --git a/tests/unit/UnitTestCase.php b/tests/unit/UnitTestCase.php new file mode 100644 index 000000000..7d706d5be --- /dev/null +++ b/tests/unit/UnitTestCase.php @@ -0,0 +1,38 @@ +assertEquals("audio/ogg", z_mime_content_type($multidots)); + $this->assertNotEquals("application/octet-stream", z_mime_content_type($multidots)); + } + + public function testFileNameOneDot() { + $multidots = "foo.ogg"; + $this->assertEquals("audio/ogg", z_mime_content_type($multidots)); + $this->assertNotEquals("application/octet-stream", z_mime_content_type($multidots)); + } +} \ No newline at end of file diff --git a/tests/unit/expand_acl_test.php b/tests/unit/expand_acl_test.php new file mode 100644 index 000000000..154bc921d --- /dev/null +++ b/tests/unit/expand_acl_test.php @@ -0,0 +1,148 @@ +<2><3>'; + $this->assertEquals(array(1, 2, 3), expand_acl($text)); + } + + /** + * test with a big number + */ + public function testExpandAclBigNumber() { + $text='<1><'.PHP_INT_MAX.'><15>'; + $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text)); + } + + /** + * test with a string in it. + * + * TODO: is this valid input? Otherwise: should there be an exception? + */ + public function testExpandAclString() { + $text="<1><279012>"; + $this->assertEquals(array(1, 279012), expand_acl($text)); + } + + /** + * test with a ' ' in it. + * + * TODO: is this valid input? Otherwise: should there be an exception? + */ + public function testExpandAclSpace() { + $text="<1><279 012><32>"; + $this->assertEquals(array(1, "279", "32"), expand_acl($text)); + } + + /** + * test empty input + */ + public function testExpandAclEmpty() { + $text=""; + $this->assertEquals(array(), expand_acl($text)); + } + + /** + * test invalid input, no < at all + * + * TODO: should there be an exception? + */ + public function testExpandAclNoBrackets() { + $text="According to documentation, that's invalid. "; //should be invalid + $this->assertEquals(array(), expand_acl($text)); + } + + /** + * test invalid input, just open < + * + * TODO: should there be an exception? + */ + public function testExpandAclJustOneBracket1() { + $text="assertEquals(array(), expand_acl($text)); + } + + /** + * test invalid input, just close > + * + * TODO: should there be an exception? + */ + public function testExpandAclJustOneBracket2() { + $text="Another invalid> string"; //should be invalid + $this->assertEquals(array(), expand_acl($text)); + } + + /** + * test invalid input, just close > + * + * TODO: should there be an exception? + */ + public function testExpandAclCloseOnly() { + $text="Another> invalid> string>"; //should be invalid + $this->assertEquals(array(), expand_acl($text)); + } + + /** + * test invalid input, just open < + * + * TODO: should there be an exception? + */ + public function testExpandAclOpenOnly() { + $text="assertEquals(array(), expand_acl($text)); + } + + /** + * test invalid input, open and close do not match + * + * TODO: should there be an exception? + */ + public function testExpandAclNoMatching1() { + $text=" invalid "; //should be invalid + $this->assertEquals(array(), expand_acl($text)); + } + + /** + * test invalid input, open and close do not match + * + * TODO: should there be an exception? + */ + public function testExpandAclNoMatching2() { + $text="<1>2><3>"; +// The angles are delimiters which aren't important +// the important thing is the numeric content, this returns array(1,2,3) currently +// we may wish to eliminate 2 from the results, though it isn't harmful +// It would be a better test to figure out if there is any ACL input which can +// produce this $text and fix that instead. +// $this->assertEquals(array(), expand_acl($text)); + } + + /** + * test invalid input, empty <> + * + * TODO: should there be an exception? Or array(1, 3) + * (This should be array(1,3) - mike) + */ + public function testExpandAclEmptyMatch() { + $text="<1><><3>"; + $this->assertEquals(array(1,3), expand_acl($text)); + } +} \ No newline at end of file diff --git a/tests/unit/get_tags_test.php b/tests/unit/get_tags_test.php new file mode 100644 index 000000000..40f016747 --- /dev/null +++ b/tests/unit/get_tags_test.php @@ -0,0 +1,326 @@ +15, + 'attag'=>'', 'network'=>'dfrn', + 'name'=>'Mike Lastname', 'alias'=>'Mike', + 'nick'=>'Mike', 'url'=>"http://justatest.de")); + + $args=func_get_args(); + + //last parameter is always (in this test) uid, so, it should be 11 + if($args[count($args)-1]!=11) { + return; + } + + + if(3==count($args)) { + //first call in handle_body, id only + if($result[0]['id']==$args[1]) { + return $result; + } + //second call in handle_body, name + if($result[0]['name']===$args[1]) { + return $result; + } + } + //third call in handle_body, nick or attag + if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) { + return $result; + } +} + +/** + * replacement for dbesc. + * I don't want to test dbesc here, so + * I just return the input. It won't be a problem, because + * the test does not use a real database. + * + * DON'T USE HAT FUNCTION OUTSIDE A TEST! + * + * @param string $str + * @return input + */ +function dbesc($str) { + return $str; +} + +/** + * TestCase for tag handling. + * + * @author alexander + * @package test.util + */ +class GetTagsTest extends PHPUnit_Framework_TestCase { + /** the mock to use as app */ + private $a; + + /** + * initialize the test. That's a phpUnit function, + * don't change its name. + */ + public function setUp() { + $this->a=new MockApp(); + } + + /** + * test with one Person tag + */ + public function testGetTagsShortPerson() { + $text="hi @Mike"; + + $tags=get_tags($text); + + $inform=''; + $str_tags=''; + foreach($tags as $tag) { + handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); + } + + //correct tags found? + $this->assertEquals(1, count($tags)); + $this->assertTrue(in_array("@Mike", $tags)); + + //correct output from handle_tag? + $this->assertEquals("cid:15", $inform); + $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); + $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url]", $text); + } + + /** + * test with one Person tag. + * There's a minor spelling mistake... + */ + public function testGetTagsShortPersonSpelling() { + $text="hi @Mike.because"; + + $tags=get_tags($text); + + //correct tags found? + $this->assertEquals(1, count($tags)); + $this->assertTrue(in_array("@Mike.because", $tags)); + + $inform=''; + $str_tags=''; + handle_tag($this->a, $text, $inform, $str_tags, 11, $tags[0]); + + // (mike) - This is a tricky case. + // we support mentions as in @mike@example.com - which contains a period. + // This shouldn't match anything unless you have a contact named "Mike.because". + // We may need another test for "@Mike. because" - which should return the contact + // as we ignore trailing periods in tags. + +// $this->assertEquals("cid:15", $inform); +// $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); +// $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url].because", $text); + + $this->assertEquals("", $inform); + $this->assertEquals("", $str_tags); + + } + + /** + * test with two Person tags. + * There's a minor spelling mistake... + */ + + public function testGetTagsPerson2Spelling() { + $text="hi @Mike@campino@friendica.eu"; + + $tags=get_tags($text); + +// This construct is not supported. Results are indeterminate +// $this->assertEquals(2, count($tags)); +// $this->assertTrue(in_array("@Mike", $tags)); +// $this->assertTrue(in_array("@campino@friendica.eu", $tags)); + } + + /** + * Test with one hash tag. + */ + public function testGetTagsShortTag() { + $text="This is a #test_case"; + + $tags=get_tags($text); + + $this->assertEquals(1, count($tags)); + $this->assertTrue(in_array("#test_case", $tags)); + } + + /** + * test with a person and a hash tag + */ + public function testGetTagsShortTagAndPerson() { + $text="hi @Mike This is a #test_case"; + + $tags=get_tags($text); + + $this->assertEquals(3, count($tags)); + $this->assertTrue(in_array("@Mike", $tags)); + $this->assertTrue(in_array("@Mike This", $tags)); + $this->assertTrue(in_array("#test_case", $tags)); + + $inform=''; + $str_tags=''; + foreach($tags as $tag) { + handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); + } + + $this->assertEquals("cid:15", $inform); + $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url],#[url=baseurl/search?tag=test%20case]test case[/url]", $str_tags); + $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url] This is a #[url=baseurl/search?tag=test%20case]test case[/url]", $text); + + } + + /** + * test with a person, a hash tag and some special chars. + */ + public function testGetTagsShortTagAndPersonSpecialChars() { + $text="hi @Mike, This is a #test_case."; + + $tags=get_tags($text); + + $this->assertEquals(2, count($tags)); + $this->assertTrue(in_array("@Mike", $tags)); + $this->assertTrue(in_array("#test_case", $tags)); + } + + /** + * Test with a person tag and text behind it. + */ + public function testGetTagsPersonOnly() { + $text="@Test I saw the Theme Dev group was created."; + + $tags=get_tags($text); + + $this->assertEquals(2, count($tags)); + $this->assertTrue(in_array("@Test I", $tags)); + $this->assertTrue(in_array("@Test", $tags)); + } + + /** + * this test demonstrates strange behaviour by intval. + * It makes the next test fail. + */ + public function testIntval() { + $this->assertEquals(15, intval("15 it")); + } + + /** + * test a tag with an id in it + */ + public function testIdTag() { + $text="Test with @mike+15 id tag"; + + $tags=get_tags($text); + + $this->assertEquals(2, count($tags)); + $this->assertTrue(in_array("@mike+15", $tags)); + + //happens right now, but it shouldn't be necessary + $this->assertTrue(in_array("@mike+15 id", $tags)); + + $inform=''; + $str_tags=''; + foreach($tags as $tag) { + handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); + } + + $this->assertEquals("Test with @[url=http://justatest.de]Mike Lastname[/url] id tag", $text); + $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); + // this test may produce two cid:15 entries - which is OK because duplicates are pruned before delivery + $this->assertContains("cid:15",$inform); + } + + /** + * test with two persons and one special tag. + */ + public function testGetTags2Persons1TagSpecialChars() { + $text="hi @Mike, I'm just writing #test_cases, so" + ." so @somebody@friendica.com may change #things."; + + $tags=get_tags($text); + + $this->assertEquals(5, count($tags)); + $this->assertTrue(in_array("@Mike", $tags)); + $this->assertTrue(in_array("#test_cases", $tags)); + $this->assertTrue(in_array("@somebody@friendica.com", $tags)); + $this->assertTrue(in_array("@somebody@friendica.com may", $tags)); + $this->assertTrue(in_array("#things", $tags)); + } + + /** + * test with a long text. + */ + 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. "; + + $tags=get_tags($text); + + $this->assertTrue(in_array("@Mike", $tags)); + $this->assertTrue(in_array("#test_cases", $tags)); + $this->assertTrue(in_array("@somebody@friendica.com", $tags)); + $this->assertTrue(in_array("#things", $tags)); + $this->assertTrue(in_array("#pitfalls", $tags)); + $this->assertTrue(in_array("#tags", $tags)); + $this->assertTrue(in_array("@comment", $tags)); + $this->assertTrue(in_array("@fullstops.because", $tags)); + $this->assertTrue(in_array("#things", $tags)); + $this->assertTrue(in_array("@Mike", $tags)); + $this->assertTrue(in_array("#nice", $tags)); + $this->assertTrue(in_array("@first_last", $tags)); + + //right now, none of the is matched (unsupported) +// $this->assertFalse(in_array("@Mike@campino@friendica.eu", $tags)); +// $this->assertTrue(in_array("@campino@friendica.eu", $tags)); +// $this->assertTrue(in_array("@campino@friendica.eu is", $tags)); + } + + /** + * test with an empty string + */ + public function testGetTagsEmpty() { + $tags=get_tags(""); + $this->assertEquals(0, count($tags)); + } +} \ No newline at end of file diff --git a/tests/unit/template_test.php b/tests/unit/template_test.php new file mode 100644 index 000000000..1f9f80531 --- /dev/null +++ b/tests/unit/template_test.php @@ -0,0 +1,224 @@ +assertTrue(is_null($second)); + } + + public function testSimpleVariableString() { + $tpl='Hello $name!'; + + $text=replace_macros($tpl, array('$name'=>'Anna')); + + $this->assertEquals('Hello Anna!', $text); + } + + public function testSimpleVariableInt() { + $tpl='There are $num new messages!'; + + $text=replace_macros($tpl, array('$num'=>172)); + + $this->assertEquals('There are 172 new messages!', $text); + } + + public function testConditionalElse() { + $tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!'; + + $text1=replace_macros($tpl, array('$num'=>1)); + $text22=replace_macros($tpl, array('$num'=>22)); + + $this->assertEquals('There is 1 new message!', $text1); + $this->assertEquals('There are 22 new messages!', $text22); + } + + public function testConditionalNoElse() { + $tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}'; + + $text0=replace_macros($tpl, array('$num'=>0)); + $text22=replace_macros($tpl, array('$num'=>22)); + + $this->assertEquals('', $text0); + $this->assertEquals('There are 22 new messages!', $text22); + } + + public function testConditionalFail() { + $tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!'; + + $text1=replace_macros($tpl, array()); + + //$this->assertEquals('There is 1 new message!', $text1); + } + + public function testSimpleFor() { + $tpl='{{ for $messages as $message }} $message {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2'))); + + $this->assertEquals(' message 1 message 2 ', $text); + } + + public function testFor() { + $tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike')))); + + $this->assertEquals(' from: Mike to Alex from: Alex to Mike ', $text); + } + + public function testKeyedFor() { + $tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike'))); + + $this->assertEquals(' from: Mike to Alex from: Sven to Mike ', $text); + } + + public function testForEmpty() { + $tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array())); + + $this->assertEquals('messages: ', $text); + } + + public function testForWrongType() { + $tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>11)); + + $this->assertEquals('messages: ', $text); + } + + public function testForConditional() { + $tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array( + array('new'=>true, 'text'=>'new message'), + array('new'=>false, 'text'=>'old message')))); + + $this->assertEquals('new messages: new message', $text); + } + + public function testConditionalFor() { + $tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}'; + + $text=replace_macros($tpl, array('$enabled'=>true, + '$messages'=>array( + array('new'=>true, 'text'=>'new message'), + array('new'=>false, 'text'=>'old message')))); + + $this->assertEquals('new messages: new message old message', $text); + } + + public function testFantasy() { + $tpl='Fantasy: {{fantasy $messages}}'; + + $text=replace_macros($tpl, array('$messages'=>'no no')); + + $this->assertEquals('Fantasy: {{fantasy no no}}', $text); + } + + public function testInc() { + $tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}'; + + $text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help'))); + + $this->assertEquals(" \n" + ."
\n" + ." \n" + ." \n" + ." help\n" + ."
\n", $text); + } + + public function testIncNoVar() { + $tpl='{{inc field_input.tpl }}{{ endinc }}'; + + $text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help'))); + + $this->assertEquals(" \n
\n \n" + ." \n" + ." help\n" + ."
\n", $text); + } + + public function testDoubleUse() { + $tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}'; + + $text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false)); + + $this->assertEquals('Hello Anna! ', $text); + + $tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}'; + + $text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true)); + + $this->assertEquals('Hey Max! I hate you! ', $text); + } + + public function testIncDouble() { + $tpl='{{inc field_input.tpl with $field=$var1}}{{ endinc }}' + .'{{inc field_input.tpl with $field=$var2}}{{ endinc }}'; + + $text=replace_macros($tpl, array('$var1'=>array('myfield', 'label', 'value', 'help'), + '$var2'=>array('myfield2', 'label2', 'value2', 'help2'))); + + $this->assertEquals(" \n" + ."
\n" + ." \n" + ." \n" + ." help\n" + ."
\n" + ." \n" + ."
\n" + ." \n" + ." \n" + ." help2\n" + ."
\n", $text); + } +} \ No newline at end of file diff --git a/tests/upload_test.php b/tests/upload_test.php deleted file mode 100644 index 031315fba..000000000 --- a/tests/upload_test.php +++ /dev/null @@ -1,29 +0,0 @@ -assertEquals("audio/ogg", z_mime_content_type($multidots)); - $this->assertNotEquals("application/octet-stream", z_mime_content_type($multidots)); - } - - public function testFileNameOneDot() { - $multidots = "foo.ogg"; - $this->assertEquals("audio/ogg", z_mime_content_type($multidots)); - $this->assertNotEquals("application/octet-stream", z_mime_content_type($multidots)); - } -} \ No newline at end of file diff --git a/tests/xss_filter_test.php b/tests/xss_filter_test.php deleted file mode 100644 index 3fb6ac310..000000000 --- a/tests/xss_filter_test.php +++ /dev/null @@ -1,71 +0,0 @@ -'; - - $validstring=notags($invalidstring); - $escapedString=escape_tags($invalidstring); - - $this->assertEquals('[submit type="button" onclick="alert(\'failed!\');" /]', $validstring); - $this->assertEquals("<submit type="button" onclick="alert('failed!');" />", $escapedString); - } - - /** - *xmlify and unxmlify - */ - public function testXmlify() { - $text="I want to break\n this!11!"; - $xml=xmlify($text); - $retext=unxmlify($text); - - $this->assertEquals($text, $retext); - } - - /** - * xmlify and put in a document - */ - public function testXmlifyDocument() { - $tag="I want to break"; - $xml=xmlify($tag); - $text=''.$xml.''; - - $xml_parser=xml_parser_create(); - //should be possible to parse it - $values=array(); $index=array(); - $this->assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index)); - - $this->assertEquals(array('TEXT'=>array(0)), - $index); - $this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)), - $values); - - xml_parser_free($xml_parser); - } - - /** - * test hex2bin and reverse - */ - public function testHex2Bin() { - $this->assertEquals(-3, hex2bin(bin2hex(-3))); - $this->assertEquals(0, hex2bin(bin2hex(0))); - $this->assertEquals(12, hex2bin(bin2hex(12))); - $this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX))); - } - - //function qp, quick and dirty?? - //get_mentions - //get_contact_block, bis Zeile 538 -} -?> -- cgit v1.2.3