]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/ArraysTest.php
Merge pull request #7010 from nupplaphil/task/basepath_hardening
[friendica.git] / tests / src / Util / ArraysTest.php
1 <?php
2 /**
3  * @file tests/src/Util/Arrays.php
4  * @author Roland Haeder<https://f.haeder.net/profile/roland>
5  */
6 namespace Friendica\Test\src\Util;
7
8 use Friendica\Util\Arrays;
9 use PHPUnit\Framework\TestCase;
10
11 /**
12  * @brief Array utility testing class
13  */
14 class ArraysTest extends TestCase
15 {
16         /**
17          * @brief Tests if an empty array and an empty delimiter returns an empty string.
18          */
19         public function testEmptyArrayEmptyDelimiter()
20         {
21                 $str = Arrays::recursiveImplode([], '');
22                 $this->assertEmpty($str);
23         }
24
25         /**
26          * @brief Tests if an empty array and a non-empty delimiter returns an empty string.
27          */
28         public function testEmptyArrayNonEmptyDelimiter()
29         {
30                 $str = Arrays::recursiveImplode([], ',');
31                 $this->assertEmpty($str);
32         }
33
34         /**
35          * @brief Tests if a non-empty array and an empty delimiter returns the value (1).
36          */
37         public function testNonEmptyArrayEmptyDelimiter()
38         {
39                 $str = Arrays::recursiveImplode([1], '');
40                 $this->assertSame($str, '1');
41         }
42
43         /**
44          * @brief Tests if a non-empty array and an empty delimiter returns the value (12).
45          */
46         public function testNonEmptyArray2EmptyDelimiter()
47         {
48                 $str = Arrays::recursiveImplode([1, 2], '');
49                 $this->assertSame($str, '12');
50         }
51
52         /**
53          * @brief Tests if a non-empty array and a non-empty delimiter returns the value (1).
54          */
55         public function testNonEmptyArrayNonEmptyDelimiter()
56         {
57                 $str = Arrays::recursiveImplode([1], ',');
58                 $this->assertSame($str, '1');
59         }
60
61         /**
62          * @brief Tests if a non-empty array and a non-empty delimiter returns the value (1,2).
63          */
64         public function testNonEmptyArray2NonEmptyDelimiter()
65         {
66                 $str = Arrays::recursiveImplode([1, 2], ',');
67                 $this->assertSame($str, '1,2');
68         }
69
70         /**
71          * @brief Tests if a 2-dim array and an empty delimiter returns the expected string.
72          */
73         public function testEmptyMultiArray2EmptyDelimiter()
74         {
75                 $str = Arrays::recursiveImplode([[1], []], '');
76                 $this->assertSame($str, '{1}{}');
77         }
78
79         /**
80          * @brief Tests if a 2-dim array and an empty delimiter returns the expected string.
81          */
82         public function testEmptyMulti2Array2EmptyDelimiter()
83         {
84                 $str = Arrays::recursiveImplode([[1], [2]], '');
85                 $this->assertSame($str, '{1}{2}');
86         }
87
88         /**
89          * @brief Tests if a 2-dim array and a non-empty delimiter returns the expected string.
90          */
91         public function testEmptyMultiArray2NonEmptyDelimiter()
92         {
93                 $str = Arrays::recursiveImplode([[1], []], ',');
94                 $this->assertSame($str, '{1},{}');
95         }
96
97         /**
98          * @brief Tests if a 2-dim array and a non-empty delimiter returns the expected string.
99          */
100         public function testEmptyMulti2Array2NonEmptyDelimiter()
101         {
102                 $str = Arrays::recursiveImplode([[1], [2]], ',');
103                 $this->assertSame($str, '{1},{2}');
104         }
105
106         /**
107          * @brief Tests if a 3-dim array and a non-empty delimiter returns the expected string.
108          */
109         public function testEmptyMulti3Array2NonEmptyDelimiter()
110         {
111                 $str = Arrays::recursiveImplode([[1], [2, [3]]], ',');
112                 $this->assertSame($str, '{1},{2,{3}}');
113         }
114 }