3 namespace Friendica\Test\src\Util;
5 use Friendica\Model\Group;
6 use Friendica\Util\ACLFormatter;
7 use PHPUnit\Framework\TestCase;
10 * @brief ACLFormater utility testing class
12 class ACLFormaterTest extends TestCase
15 * test expand_acl, perfect input
17 public function testExpandAclNormal()
19 $aclFormatter = new ACLFormatter();
21 $text='<1><2><3><' . Group::FOLLOWERS . '><' . Group::MUTUALS . '>';
22 $this->assertEquals(array('1', '2', '3', Group::FOLLOWERS, Group::MUTUALS), $aclFormatter->expand($text));
26 * test with a big number
28 public function testExpandAclBigNumber()
30 $aclFormatter = new ACLFormatter();
32 $text='<1><' . PHP_INT_MAX . '><15>';
33 $this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), $aclFormatter->expand($text));
37 * test with a string in it.
39 * @todo is this valid input? Otherwise: should there be an exception?
41 public function testExpandAclString()
43 $aclFormatter = new ACLFormatter();
45 $text="<1><279012><tt>";
46 $this->assertEquals(array('1', '279012'), $aclFormatter->expand($text));
50 * test with a ' ' in it.
52 * @todo is this valid input? Otherwise: should there be an exception?
54 public function testExpandAclSpace()
56 $aclFormatter = new ACLFormatter();
58 $text="<1><279 012><32>";
59 $this->assertEquals(array('1', '32'), $aclFormatter->expand($text));
65 public function testExpandAclEmpty()
67 $aclFormatter = new ACLFormatter();
70 $this->assertEquals(array(), $aclFormatter->expand($text));
74 * test invalid input, no < at all
76 * @todo should there be an exception?
78 public function testExpandAclNoBrackets()
80 $aclFormatter = new ACLFormatter();
82 $text="According to documentation, that's invalid. "; //should be invalid
83 $this->assertEquals(array(), $aclFormatter->expand($text));
87 * test invalid input, just open <
89 * @todo should there be an exception?
91 public function testExpandAclJustOneBracket1()
93 $aclFormatter = new ACLFormatter();
95 $text="<Another invalid string"; //should be invalid
96 $this->assertEquals(array(), $aclFormatter->expand($text));
100 * test invalid input, just close >
102 * @todo should there be an exception?
104 public function testExpandAclJustOneBracket2()
106 $aclFormatter = new ACLFormatter();
108 $text="Another invalid> string"; //should be invalid
109 $this->assertEquals(array(), $aclFormatter->expand($text));
113 * test invalid input, just close >
115 * @todo should there be an exception?
117 public function testExpandAclCloseOnly()
119 $aclFormatter = new ACLFormatter();
121 $text="Another> invalid> string>"; //should be invalid
122 $this->assertEquals(array(), $aclFormatter->expand($text));
126 * test invalid input, just open <
128 * @todo should there be an exception?
130 public function testExpandAclOpenOnly()
132 $aclFormatter = new ACLFormatter();
134 $text="<Another< invalid string<"; //should be invalid
135 $this->assertEquals(array(), $aclFormatter->expand($text));
139 * test invalid input, open and close do not match
141 * @todo should there be an exception?
143 public function testExpandAclNoMatching1()
145 $aclFormatter = new ACLFormatter();
147 $text="<Another<> invalid <string>"; //should be invalid
148 $this->assertEquals(array(), $aclFormatter->expand($text));
152 * test invalid input, empty <>
154 * @todo should there be an exception? Or array(1, 3)
155 * (This should be array(1,3) - mike)
157 public function testExpandAclEmptyMatch()
159 $aclFormatter = new ACLFormatter();
162 $this->assertEquals(array('1', '3'), $aclFormatter->expand($text));
165 public function dataAclToString()
173 'input' => '1,2,3,4',
174 'assert' => '<1><2><3><4>',
177 'input' => [1, 2, 3, 4],
178 'assert' => '<1><2><3><4>',
181 'input' => [1, 'a', 3, 4],
182 'assert' => '<1><3><4>',
185 'input' => 'a,bsd23,4',
192 * @dataProvider dataAclToString
194 public function testAclToString($input, string $assert)
196 $aclFormatter = new ACLFormatter();
198 $this->assertEquals($assert, $aclFormatter->toString($input));