6 namespace Friendica\Test;
8 use Friendica\Model\Group;
9 use PHPUnit\Framework\TestCase;
12 * Tests for text functions.
14 class TextTest extends TestCase
17 * test attribute contains
19 public function testAttributeContains1()
21 $testAttr="class1 notclass2 class3";
22 $this->assertTrue(attribute_contains($testAttr, "class3"));
23 $this->assertFalse(attribute_contains($testAttr, "class2"));
27 * test attribute contains
29 public function testAttributeContains2()
31 $testAttr="class1 not-class2 class3";
32 $this->assertTrue(attribute_contains($testAttr, "class3"));
33 $this->assertFalse(attribute_contains($testAttr, "class2"));
37 * test with empty input
39 public function testAttributeContainsEmpty()
42 $this->assertFalse(attribute_contains($testAttr, "class2"));
46 * test input with special chars
48 public function testAttributeContainsSpecialChars()
50 $testAttr="--... %\$รค() /(=?}";
51 $this->assertFalse(attribute_contains($testAttr, "class2"));
55 * test expand_acl, perfect input
57 public function testExpandAclNormal()
59 $text='<1><2><3><' . Group::FOLLOWERS . '><' . Group::MUTUALS . '>';
60 $this->assertEquals(array('1', '2', '3', Group::FOLLOWERS, Group::MUTUALS), expand_acl($text));
64 * test with a big number
66 public function testExpandAclBigNumber()
68 $text='<1><' . PHP_INT_MAX . '><15>';
69 $this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), expand_acl($text));
73 * test with a string in it.
75 * @todo is this valid input? Otherwise: should there be an exception?
77 public function testExpandAclString()
79 $text="<1><279012><tt>";
80 $this->assertEquals(array('1', '279012'), expand_acl($text));
84 * test with a ' ' in it.
86 * @todo is this valid input? Otherwise: should there be an exception?
88 public function testExpandAclSpace()
90 $text="<1><279 012><32>";
91 $this->assertEquals(array('1', '32'), expand_acl($text));
97 public function testExpandAclEmpty()
100 $this->assertEquals(array(), expand_acl($text));
104 * test invalid input, no < at all
106 * @todo should there be an exception?
108 public function testExpandAclNoBrackets()
110 $text="According to documentation, that's invalid. "; //should be invalid
111 $this->assertEquals(array(), expand_acl($text));
115 * test invalid input, just open <
117 * @todo should there be an exception?
119 public function testExpandAclJustOneBracket1()
121 $text="<Another invalid string"; //should be invalid
122 $this->assertEquals(array(), expand_acl($text));
126 * test invalid input, just close >
128 * @todo should there be an exception?
130 public function testExpandAclJustOneBracket2()
132 $text="Another invalid> string"; //should be invalid
133 $this->assertEquals(array(), expand_acl($text));
137 * test invalid input, just close >
139 * @todo should there be an exception?
141 public function testExpandAclCloseOnly()
143 $text="Another> invalid> string>"; //should be invalid
144 $this->assertEquals(array(), expand_acl($text));
148 * test invalid input, just open <
150 * @todo should there be an exception?
152 public function testExpandAclOpenOnly()
154 $text="<Another< invalid string<"; //should be invalid
155 $this->assertEquals(array(), expand_acl($text));
159 * test invalid input, open and close do not match
161 * @todo should there be an exception?
163 public function testExpandAclNoMatching1()
165 $text="<Another<> invalid <string>"; //should be invalid
166 $this->assertEquals(array(), expand_acl($text));
170 * test invalid input, empty <>
172 * @todo should there be an exception? Or array(1, 3)
173 * (This should be array(1,3) - mike)
175 public function testExpandAclEmptyMatch()
178 $this->assertEquals(array('1', '3'), expand_acl($text));
182 * test hex2bin and reverse
184 public function testHex2Bin()
186 $this->assertEquals(-3, hex2bin(bin2hex(-3)));
187 $this->assertEquals(0, hex2bin(bin2hex(0)));
188 $this->assertEquals(12, hex2bin(bin2hex(12)));
189 $this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX)));