3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Util;
24 use Friendica\Util\Arrays;
25 use PHPUnit\Framework\TestCase;
28 * Array utility testing class
30 class ArraysTest extends TestCase
33 * Tests if an empty array and an empty delimiter returns an empty string.
35 public function testEmptyArrayEmptyDelimiter()
37 $str = Arrays::recursiveImplode([], '');
38 self::assertEmpty($str);
42 * Tests if an empty array and a non-empty delimiter returns an empty string.
44 public function testEmptyArrayNonEmptyDelimiter()
46 $str = Arrays::recursiveImplode([], ',');
47 self::assertEmpty($str);
51 * Tests if a non-empty array and an empty delimiter returns the value (1).
53 public function testNonEmptyArrayEmptyDelimiter()
55 $str = Arrays::recursiveImplode([1], '');
56 self::assertSame($str, '1');
60 * Tests if a non-empty array and an empty delimiter returns the value (12).
62 public function testNonEmptyArray2EmptyDelimiter()
64 $str = Arrays::recursiveImplode([1, 2], '');
65 self::assertSame($str, '12');
69 * Tests if a non-empty array and a non-empty delimiter returns the value (1).
71 public function testNonEmptyArrayNonEmptyDelimiter()
73 $str = Arrays::recursiveImplode([1], ',');
74 self::assertSame($str, '1');
78 * Tests if a non-empty array and a non-empty delimiter returns the value (1,2).
80 public function testNonEmptyArray2NonEmptyDelimiter()
82 $str = Arrays::recursiveImplode([1, 2], ',');
83 self::assertSame($str, '1,2');
87 * Tests if a 2-dim array and an empty delimiter returns the expected string.
89 public function testEmptyMultiArray2EmptyDelimiter()
91 $str = Arrays::recursiveImplode([[1], []], '');
92 self::assertSame($str, '{1}{}');
96 * Tests if a 2-dim array and an empty delimiter returns the expected string.
98 public function testEmptyMulti2Array2EmptyDelimiter()
100 $str = Arrays::recursiveImplode([[1], [2]], '');
101 self::assertSame($str, '{1}{2}');
105 * Tests if a 2-dim array and a non-empty delimiter returns the expected string.
107 public function testEmptyMultiArray2NonEmptyDelimiter()
109 $str = Arrays::recursiveImplode([[1], []], ',');
110 self::assertSame($str, '{1},{}');
114 * Tests if a 2-dim array and a non-empty delimiter returns the expected string.
116 public function testEmptyMulti2Array2NonEmptyDelimiter()
118 $str = Arrays::recursiveImplode([[1], [2]], ',');
119 self::assertSame($str, '{1},{2}');
123 * Tests if a 3-dim array and a non-empty delimiter returns the expected string.
125 public function testEmptyMulti3Array2NonEmptyDelimiter()
127 $str = Arrays::recursiveImplode([[1], [2, [3]]], ',');
128 self::assertSame($str, '{1},{2,{3}}');
132 * Test the Arrays::walkRecursive() function.
134 public function testApiWalkRecursive()
139 Arrays::walkRecursive(
142 // Should we test this with a callback that actually does something?
150 * Test the Arrays::walkRecursive() function with an array.
154 public function testApiWalkRecursiveWithArray()
156 $array = [['item1'], ['item2']];
159 Arrays::walkRecursive(
162 // Should we test this with a callback that actually does something?