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
15 public function assertAcl($text, array $assert = [])
17 $aclFormatter = new ACLFormatter();
19 $acl = $aclFormatter->expand($text);
21 $this->assertEquals($assert, $acl);
23 $this->assertMergable($acl);
26 public function assertMergable(array $aclOne, array $aclTwo = [])
28 $this->assertTrue(is_array($aclOne));
29 $this->assertTrue(is_array($aclTwo));
31 $aclMerged = array_unique(array_merge($aclOne, $aclTwo));
32 $this->assertTrue(is_array($aclMerged));
37 public function dataExpand()
41 'input' => '<1><2><3><' . Group::FOLLOWERS . '><' . Group::MUTUALS . '>',
42 'assert' => ['1', '2', '3', Group::FOLLOWERS, Group::MUTUALS],
45 'input' => '<1><' . PHP_INT_MAX . '><15>',
46 'assert' => ['1', (string)PHP_INT_MAX, '15'],
49 'input' => '<1><279012><tt>',
50 'assert' => ['1', '279012'],
53 'input' => '<1><279 012><32>',
54 'assert' => ['1', '32'],
60 /// @todo should there be an exception?
62 'input' => 'According to documentation, that\'s invalid. ', //should be invalid
65 /// @todo should there be an exception?
67 'input' => '<Another invalid string', //should be invalid
70 /// @todo should there be an exception?
71 'justOneBracket2' => [
72 'input' => 'Another invalid> string', //should be invalid
75 /// @todo should there be an exception?
77 'input' => 'Another> invalid> string>', //should be invalid
80 /// @todo should there be an exception?
82 'input' => '<Another< invalid string<', //should be invalid
85 /// @todo should there be an exception?
87 'input' => '<Another<> invalid <string>', //should be invalid
91 'input' => '<1><><3>',
92 'assert' => ['1', '3'],
98 * @dataProvider dataExpand
100 public function testExpand($input, array $assert)
102 $this->assertAcl($input, $assert);
106 * Test nullable expand (=> no ACL set)
108 public function testExpandNull()
110 $aclFormatter = new ACLFormatter();
112 $allow_people = $aclFormatter->expand();
113 $allow_groups = $aclFormatter->expand();
115 $this->assertEmpty($aclFormatter->expand(null));
116 $this->assertEmpty($aclFormatter->expand());
118 $recipients = array_unique(array_merge($allow_people, $allow_groups));
119 $this->assertEmpty($recipients);
122 public function dataAclToString()
130 'input' => '1,2,3,4',
131 'assert' => '<1><2><3><4>',
134 'input' => [1, 2, 3, 4],
135 'assert' => '<1><2><3><4>',
138 'input' => [1, 'a', 3, 4],
139 'assert' => '<1><3><4>',
142 'input' => 'a,bsd23,4',
145 /** @see https://github.com/friendica/friendica/pull/7787 */
146 'bug-7778-angle-brackets' => [
147 'input' => ["<40195>"],
148 'assert' => "<40195>",
150 Group::FOLLOWERS => [
151 'input' => [Group::FOLLOWERS, 1],
152 'assert' => '<' . Group::FOLLOWERS . '><1>',
155 'input' => [Group::MUTUALS, 1],
156 'assert' => '<' . Group::MUTUALS . '><1>',
158 'wrong-angle-brackets' => [
159 'input' => ["<asd>","<123>"],
166 * @dataProvider dataAclToString
168 public function testAclToString($input, string $assert)
170 $aclFormatter = new ACLFormatter();
172 $this->assertEquals($assert, $aclFormatter->toString($input));