]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Util/ArraysTest.php
spelling: cached
[friendica.git] / tests / src / Util / ArraysTest.php
index 1b82c0b8ff825d018529894117cabbc6c13cd8dd..0c992ef254b8f58c4aef07f1bda592f8d8f6e1cc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -35,7 +35,7 @@ class ArraysTest extends TestCase
        public function testEmptyArrayEmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([], '');
-               $this->assertEmpty($str);
+               self::assertEmpty($str);
        }
 
        /**
@@ -44,7 +44,7 @@ class ArraysTest extends TestCase
        public function testEmptyArrayNonEmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([], ',');
-               $this->assertEmpty($str);
+               self::assertEmpty($str);
        }
 
        /**
@@ -53,7 +53,7 @@ class ArraysTest extends TestCase
        public function testNonEmptyArrayEmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([1], '');
-               $this->assertSame($str, '1');
+               self::assertSame($str, '1');
        }
 
        /**
@@ -62,7 +62,7 @@ class ArraysTest extends TestCase
        public function testNonEmptyArray2EmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([1, 2], '');
-               $this->assertSame($str, '12');
+               self::assertSame($str, '12');
        }
 
        /**
@@ -71,7 +71,7 @@ class ArraysTest extends TestCase
        public function testNonEmptyArrayNonEmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([1], ',');
-               $this->assertSame($str, '1');
+               self::assertSame($str, '1');
        }
 
        /**
@@ -80,7 +80,7 @@ class ArraysTest extends TestCase
        public function testNonEmptyArray2NonEmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([1, 2], ',');
-               $this->assertSame($str, '1,2');
+               self::assertSame($str, '1,2');
        }
 
        /**
@@ -89,7 +89,7 @@ class ArraysTest extends TestCase
        public function testEmptyMultiArray2EmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([[1], []], '');
-               $this->assertSame($str, '{1}{}');
+               self::assertSame($str, '{1}{}');
        }
 
        /**
@@ -98,7 +98,7 @@ class ArraysTest extends TestCase
        public function testEmptyMulti2Array2EmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([[1], [2]], '');
-               $this->assertSame($str, '{1}{2}');
+               self::assertSame($str, '{1}{2}');
        }
 
        /**
@@ -107,7 +107,7 @@ class ArraysTest extends TestCase
        public function testEmptyMultiArray2NonEmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([[1], []], ',');
-               $this->assertSame($str, '{1},{}');
+               self::assertSame($str, '{1},{}');
        }
 
        /**
@@ -116,7 +116,7 @@ class ArraysTest extends TestCase
        public function testEmptyMulti2Array2NonEmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([[1], [2]], ',');
-               $this->assertSame($str, '{1},{2}');
+               self::assertSame($str, '{1},{2}');
        }
 
        /**
@@ -125,6 +125,44 @@ class ArraysTest extends TestCase
        public function testEmptyMulti3Array2NonEmptyDelimiter()
        {
                $str = Arrays::recursiveImplode([[1], [2, [3]]], ',');
-               $this->assertSame($str, '{1},{2,{3}}');
+               self::assertSame($str, '{1},{2,{3}}');
+       }
+
+       /**
+        * Test the Arrays::walkRecursive() function.
+        */
+       public function testApiWalkRecursive()
+       {
+               $array = ['item1'];
+               self::assertEquals(
+                       $array,
+                       Arrays::walkRecursive(
+                               $array,
+                               function () {
+                                       // Should we test this with a callback that actually does something?
+                                       return true;
+                               }
+                       )
+               );
+       }
+
+       /**
+        * Test the Arrays::walkRecursive() function with an array.
+        *
+        * @return void
+        */
+       public function testApiWalkRecursiveWithArray()
+       {
+               $array = [['item1'], ['item2']];
+               self::assertEquals(
+                       $array,
+                       Arrays::walkRecursive(
+                               $array,
+                               function () {
+                                       // Should we test this with a callback that actually does something?
+                                       return true;
+                               }
+                       )
+               );
        }
 }