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
90 /// @todo should there be an exception? Or array(1, 3)
91 // (This should be array(1,3) - mike)
93 'input' => '<1><><3>', //should be invalid
94 'assert' => ['1', '3'],
100 * @dataProvider dataExpand
102 public function testExpand($input, array $assert)
104 $this->assertAcl($input, $assert);
108 * Test nullable expand (=> no ACL set)
110 public function testExpandNull()
112 $aclFormatter = new ACLFormatter();
114 $allow_people = $aclFormatter->expand();
115 $allow_groups = $aclFormatter->expand();
117 $this->assertEmpty($aclFormatter->expand(null));
118 $this->assertEmpty($aclFormatter->expand());
120 $recipients = array_unique(array_merge($allow_people, $allow_groups));
121 $this->assertEmpty($recipients);
124 public function dataAclToString()
132 'input' => '1,2,3,4',
133 'assert' => '<1><2><3><4>',
136 'input' => [1, 2, 3, 4],
137 'assert' => '<1><2><3><4>',
140 'input' => [1, 'a', 3, 4],
141 'assert' => '<1><3><4>',
144 'input' => 'a,bsd23,4',
147 /** @see https://github.com/friendica/friendica/pull/7787 */
148 'bug-7778-angle-brackets' => [
149 'input' => ["<40195>"],
150 'assert' => "<40195>",
152 Group::FOLLOWERS => [
153 'input' => [Group::FOLLOWERS, 1],
154 'assert' => '<' . Group::FOLLOWERS . '><1>',
157 'input' => [Group::MUTUALS, 1],
158 'assert' => '<' . Group::MUTUALS . '><1>',
160 'wrong-angle-brackets' => [
161 'input' => ["<asd>","<123>"],
168 * @dataProvider dataAclToString
170 public function testAclToString($input, string $assert)
172 $aclFormatter = new ACLFormatter();
174 $this->assertEquals($assert, $aclFormatter->toString($input));