3 namespace Friendica\Test\src\Util;
6 use Friendica\Model\Group;
7 use Friendica\Util\ACLFormatter;
8 use PHPUnit\Framework\TestCase;
11 * @brief ACLFormater utility testing class
13 class ACLFormaterTest extends TestCase
16 * test expand_acl, perfect input
18 public function testExpandAclNormal()
20 $aclFormatter = new ACLFormatter();
22 $text='<1><2><3><' . Group::FOLLOWERS . '><' . Group::MUTUALS . '>';
23 $this->assertEquals(array('1', '2', '3', Group::FOLLOWERS, Group::MUTUALS), $aclFormatter->expand($text));
27 * test with a big number
29 public function testExpandAclBigNumber()
31 $aclFormatter = new ACLFormatter();
33 $text='<1><' . PHP_INT_MAX . '><15>';
34 $this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), $aclFormatter->expand($text));
38 * test with a string in it.
40 * @todo is this valid input? Otherwise: should there be an exception?
42 public function testExpandAclString()
44 $aclFormatter = new ACLFormatter();
46 $text="<1><279012><tt>";
47 $this->assertEquals(array('1', '279012'), $aclFormatter->expand($text));
51 * test with a ' ' in it.
53 * @todo is this valid input? Otherwise: should there be an exception?
55 public function testExpandAclSpace()
57 $aclFormatter = new ACLFormatter();
59 $text="<1><279 012><32>";
60 $this->assertEquals(array('1', '32'), $aclFormatter->expand($text));
66 public function testExpandAclEmpty()
68 $aclFormatter = new ACLFormatter();
71 $this->assertEquals(array(), $aclFormatter->expand($text));
75 * test invalid input, no < at all
77 * @todo should there be an exception?
79 public function testExpandAclNoBrackets()
81 $aclFormatter = new ACLFormatter();
83 $text="According to documentation, that's invalid. "; //should be invalid
84 $this->assertEquals(array(), $aclFormatter->expand($text));
88 * test invalid input, just open <
90 * @todo should there be an exception?
92 public function testExpandAclJustOneBracket1()
94 $aclFormatter = new ACLFormatter();
96 $text="<Another invalid string"; //should be invalid
97 $this->assertEquals(array(), $aclFormatter->expand($text));
101 * test invalid input, just close >
103 * @todo should there be an exception?
105 public function testExpandAclJustOneBracket2()
107 $aclFormatter = new ACLFormatter();
109 $text="Another invalid> string"; //should be invalid
110 $this->assertEquals(array(), $aclFormatter->expand($text));
114 * test invalid input, just close >
116 * @todo should there be an exception?
118 public function testExpandAclCloseOnly()
120 $aclFormatter = new ACLFormatter();
122 $text="Another> invalid> string>"; //should be invalid
123 $this->assertEquals(array(), $aclFormatter->expand($text));
127 * test invalid input, just open <
129 * @todo should there be an exception?
131 public function testExpandAclOpenOnly()
133 $aclFormatter = new ACLFormatter();
135 $text="<Another< invalid string<"; //should be invalid
136 $this->assertEquals(array(), $aclFormatter->expand($text));
140 * test invalid input, open and close do not match
142 * @todo should there be an exception?
144 public function testExpandAclNoMatching1()
146 $aclFormatter = new ACLFormatter();
148 $text="<Another<> invalid <string>"; //should be invalid
149 $this->assertEquals(array(), $aclFormatter->expand($text));
153 * test invalid input, empty <>
155 * @todo should there be an exception? Or array(1, 3)
156 * (This should be array(1,3) - mike)
158 public function testExpandAclEmptyMatch()
160 $aclFormatter = new ACLFormatter();
163 $this->assertEquals(array('1', '3'), $aclFormatter->expand($text));
167 * Test expected exception in case of wrong typehint
169 * @expectedException Error
171 public function testExpandNull()
173 $aclFormatter = new ACLFormatter();
175 $aclFormatter->expand(null);
178 public function dataAclToString()
186 'input' => '1,2,3,4',
187 'assert' => '<1><2><3><4>',
190 'input' => [1, 2, 3, 4],
191 'assert' => '<1><2><3><4>',
194 'input' => [1, 'a', 3, 4],
195 'assert' => '<1><3><4>',
198 'input' => 'a,bsd23,4',
205 * @dataProvider dataAclToString
207 public function testAclToString($input, string $assert)
209 $aclFormatter = new ACLFormatter();
211 $this->assertEquals($assert, $aclFormatter->toString($input));