]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/ACLFormaterTest.php
19332f4953239fdbbea8061b04282993238afb2a
[friendica.git] / tests / src / Util / ACLFormaterTest.php
1 <?php
2
3 namespace Friendica\Test\src\Util;
4
5 use Friendica\Model\Group;
6 use Friendica\Util\ACLFormatter;
7 use PHPUnit\Framework\TestCase;
8
9 /**
10  * @brief ACLFormater utility testing class
11  */
12 class ACLFormaterTest extends TestCase
13 {
14         /**
15          * test expand_acl, perfect input
16          */
17         public function testExpandAclNormal()
18         {
19                 $aclFormatter = new ACLFormatter();
20
21                 $text='<1><2><3><' . Group::FOLLOWERS . '><' . Group::MUTUALS . '>';
22                 $this->assertEquals(array('1', '2', '3', Group::FOLLOWERS, Group::MUTUALS), $aclFormatter->expand($text));
23         }
24
25         /**
26          * test with a big number
27          */
28         public function testExpandAclBigNumber()
29         {
30                 $aclFormatter = new ACLFormatter();
31
32                 $text='<1><' . PHP_INT_MAX . '><15>';
33                 $this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), $aclFormatter->expand($text));
34         }
35
36         /**
37          * test with a string in it.
38          *
39          * @todo is this valid input? Otherwise: should there be an exception?
40          */
41         public function testExpandAclString()
42         {
43                 $aclFormatter = new ACLFormatter();
44
45                 $text="<1><279012><tt>";
46                 $this->assertEquals(array('1', '279012'), $aclFormatter->expand($text));
47         }
48
49         /**
50          * test with a ' ' in it.
51          *
52          * @todo is this valid input? Otherwise: should there be an exception?
53          */
54         public function testExpandAclSpace()
55         {
56                 $aclFormatter = new ACLFormatter();
57
58                 $text="<1><279 012><32>";
59                 $this->assertEquals(array('1', '32'), $aclFormatter->expand($text));
60         }
61
62         /**
63          * test empty input
64          */
65         public function testExpandAclEmpty()
66         {
67                 $aclFormatter = new ACLFormatter();
68
69                 $text="";
70                 $this->assertEquals(array(), $aclFormatter->expand($text));
71         }
72
73         /**
74          * test invalid input, no < at all
75          *
76          * @todo should there be an exception?
77          */
78         public function testExpandAclNoBrackets()
79         {
80                 $aclFormatter = new ACLFormatter();
81
82                 $text="According to documentation, that's invalid. "; //should be invalid
83                 $this->assertEquals(array(), $aclFormatter->expand($text));
84         }
85
86         /**
87          * test invalid input, just open <
88          *
89          * @todo should there be an exception?
90          */
91         public function testExpandAclJustOneBracket1()
92         {
93                 $aclFormatter = new ACLFormatter();
94
95                 $text="<Another invalid string"; //should be invalid
96                 $this->assertEquals(array(), $aclFormatter->expand($text));
97         }
98
99         /**
100          * test invalid input, just close >
101          *
102          * @todo should there be an exception?
103          */
104         public function testExpandAclJustOneBracket2()
105         {
106                 $aclFormatter = new ACLFormatter();
107
108                 $text="Another invalid> string"; //should be invalid
109                 $this->assertEquals(array(), $aclFormatter->expand($text));
110         }
111
112         /**
113          * test invalid input, just close >
114          *
115          * @todo should there be an exception?
116          */
117         public function testExpandAclCloseOnly()
118         {
119                 $aclFormatter = new ACLFormatter();
120
121                 $text="Another> invalid> string>"; //should be invalid
122                 $this->assertEquals(array(), $aclFormatter->expand($text));
123         }
124
125         /**
126          * test invalid input, just open <
127          *
128          * @todo should there be an exception?
129          */
130         public function testExpandAclOpenOnly()
131         {
132                 $aclFormatter = new ACLFormatter();
133
134                 $text="<Another< invalid string<"; //should be invalid
135                 $this->assertEquals(array(), $aclFormatter->expand($text));
136         }
137
138         /**
139          * test invalid input, open and close do not match
140          *
141          * @todo should there be an exception?
142          */
143         public function testExpandAclNoMatching1()
144         {
145                 $aclFormatter = new ACLFormatter();
146
147                 $text="<Another<> invalid <string>"; //should be invalid
148                 $this->assertEquals(array(), $aclFormatter->expand($text));
149         }
150
151         /**
152          * test invalid input, empty <>
153          *
154          * @todo should there be an exception? Or array(1, 3)
155          * (This should be array(1,3) - mike)
156          */
157         public function testExpandAclEmptyMatch()
158         {
159                 $aclFormatter = new ACLFormatter();
160
161                 $text="<1><><3>";
162                 $this->assertEquals(array('1', '3'), $aclFormatter->expand($text));
163         }
164
165         public function dataAclToString()
166         {
167                 return [
168                         'empty'   => [
169                                 'input'  => '',
170                                 'assert' => '',
171                         ],
172                         'string'  => [
173                                 'input'  => '1,2,3,4',
174                                 'assert' => '<1><2><3><4>',
175                         ],
176                         'array'   => [
177                                 'input'  => [1, 2, 3, 4],
178                                 'assert' => '<1><2><3><4>',
179                         ],
180                         'invalid' => [
181                                 'input'  => [1, 'a', 3, 4],
182                                 'assert' => '<1><3><4>',
183                         ],
184                         'invalidString' => [
185                                 'input'  => 'a,bsd23,4',
186                                 'assert' => '<4>',
187                         ],
188                 ];
189         }
190
191         /**
192          * @dataProvider dataAclToString
193          */
194         public function testAclToString($input, string $assert)
195         {
196                 $aclFormatter = new ACLFormatter();
197
198                 $this->assertEquals($assert, $aclFormatter->aclToString($input));
199         }
200 }