]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Util/StringsTest.php
Add checks & realpath() usage
[friendica.git] / tests / src / Util / StringsTest.php
index 352fe3089b52f97e71102e756bc1f5ae7112e60f..d090b1c5dd3a088f9dad89a5323616c3f0cce2e5 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * @file tests/src/Util/StringsTest.php
  */
-namespace Friendica\Test\Util;
+namespace Friendica\Test\src\Util;
 
 use Friendica\Util\Strings;
 use PHPUnit\Framework\TestCase;
@@ -12,7 +12,7 @@ use PHPUnit\Framework\TestCase;
  */
 class StringsTest extends TestCase
 {
-    /**
+       /**
         * randomnames should be random, even length
         */
        public function testRandomEven()
@@ -64,16 +64,16 @@ class StringsTest extends TestCase
 
                $randomname2 = Strings::getRandomName(1);
                $this->assertEquals(1, strlen($randomname2));
-    }
-    
-    /**
+       }
+
+       /**
         * test, that tags are escaped
         */
        public function testEscapeHtml()
        {
                $invalidstring='<submit type="button" onclick="alert(\'failed!\');" />';
 
-               $validstring = Strings::removeTags($invalidstring);
+               $validstring = Strings::escapeTags($invalidstring);
                $escapedString = Strings::escapeHtml($invalidstring);
 
                $this->assertEquals('[submit type="button" onclick="alert(\'failed!\');" /]', $validstring);
@@ -82,4 +82,39 @@ class StringsTest extends TestCase
                        $escapedString
                );
        }
+
+       public function dataIsHex()
+       {
+               return [
+                       'validHex' => [
+                               'input' => '90913473615bf00c122ac78338492980',
+                               'valid' => true,
+                       ],
+                       'invalidHex' => [
+                               'input' => '90913473615bf00c122ac7833849293',
+                               'valid' => false,
+                       ],
+                       'emptyHex' => [
+                               'input' => '',
+                               'valid' => false,
+                       ],
+                       'nullHex' => [
+                               'input' => null,
+                               'valid' => false,
+                       ],
+               ];
+       }
+
+       /**
+        * Tests if the string is a valid hexadecimal value
+        *
+        * @param string $input
+        * @param bool $valid
+        *
+        * @dataProvider dataIsHex
+        */
+       public function testIsHex($input, $valid)
+       {
+               $this->assertEquals($valid, Strings::isHex($input));
+       }
 }