From: Pierre Rudloff Date: Tue, 10 Apr 2018 00:20:20 +0000 (+0200) Subject: Regroup old tests in the TextTest class X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e695e1060f2d0302e9353b42700622a44449a1ff;p=friendica.git Regroup old tests in the TextTest class --- diff --git a/tests/TextTest.php b/tests/TextTest.php new file mode 100644 index 0000000000..3a15b97665 --- /dev/null +++ b/tests/TextTest.php @@ -0,0 +1,301 @@ +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)); + } + + /** + * 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)); + } + + /** + * 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")); + } + + /** + * 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")); + } + + /** + * test expand_acl, perfect input + */ + public function testExpandAclNormal() + { + $text='<1><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, 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)); + } + + /** + * test, that tags are escaped + */ + public function testEscapeTags() + { + $invalidstring=''; + + $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))); + } +}