6 namespace Friendica\Test;
8 use PHPUnit\Framework\TestCase;
11 * Tests for text functions.
13 class TextTest extends TestCase
16 * test attribute contains
18 public function testAttributeContains1()
20 $testAttr="class1 notclass2 class3";
21 $this->assertTrue(attribute_contains($testAttr, "class3"));
22 $this->assertFalse(attribute_contains($testAttr, "class2"));
26 * test attribute contains
28 public function testAttributeContains2()
30 $testAttr="class1 not-class2 class3";
31 $this->assertTrue(attribute_contains($testAttr, "class3"));
32 $this->assertFalse(attribute_contains($testAttr, "class2"));
36 * test with empty input
38 public function testAttributeContainsEmpty()
41 $this->assertFalse(attribute_contains($testAttr, "class2"));
45 * test input with special chars
47 public function testAttributeContainsSpecialChars()
49 $testAttr="--... %\$รค() /(=?}";
50 $this->assertFalse(attribute_contains($testAttr, "class2"));
54 * test expand_acl, perfect input
56 public function testExpandAclNormal()
59 $this->assertEquals(array(1, 2, 3), expand_acl($text));
63 * test with a big number
65 public function testExpandAclBigNumber()
67 $text='<1><'.PHP_INT_MAX.'><15>';
68 $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
72 * test with a string in it.
74 * @todo is this valid input? Otherwise: should there be an exception?
76 public function testExpandAclString()
78 $text="<1><279012><tt>";
79 $this->assertEquals(array(1, 279012), expand_acl($text));
83 * test with a ' ' in it.
85 * @todo is this valid input? Otherwise: should there be an exception?
87 public function testExpandAclSpace()
89 $text="<1><279 012><32>";
90 $this->assertEquals(array(1, "279", "32"), expand_acl($text));
96 public function testExpandAclEmpty()
99 $this->assertEquals(array(), expand_acl($text));
103 * test invalid input, no < at all
105 * @todo should there be an exception?
107 public function testExpandAclNoBrackets()
109 $text="According to documentation, that's invalid. "; //should be invalid
110 $this->assertEquals(array(), expand_acl($text));
114 * test invalid input, just open <
116 * @todo should there be an exception?
118 public function testExpandAclJustOneBracket1()
120 $text="<Another invalid string"; //should be invalid
121 $this->assertEquals(array(), expand_acl($text));
125 * test invalid input, just close >
127 * @todo should there be an exception?
129 public function testExpandAclJustOneBracket2()
131 $text="Another invalid> string"; //should be invalid
132 $this->assertEquals(array(), expand_acl($text));
136 * test invalid input, just close >
138 * @todo should there be an exception?
140 public function testExpandAclCloseOnly()
142 $text="Another> invalid> string>"; //should be invalid
143 $this->assertEquals(array(), expand_acl($text));
147 * test invalid input, just open <
149 * @todo should there be an exception?
151 public function testExpandAclOpenOnly()
153 $text="<Another< invalid string<"; //should be invalid
154 $this->assertEquals(array(), expand_acl($text));
158 * test invalid input, open and close do not match
160 * @todo should there be an exception?
162 public function testExpandAclNoMatching1()
164 $text="<Another<> invalid <string>"; //should be invalid
165 $this->assertEquals(array(), expand_acl($text));
169 * test invalid input, empty <>
171 * @todo should there be an exception? Or array(1, 3)
172 * (This should be array(1,3) - mike)
174 public function testExpandAclEmptyMatch()
177 $this->assertEquals(array(1,3), expand_acl($text));
181 * test hex2bin and reverse
183 public function testHex2Bin()
185 $this->assertEquals(-3, hex2bin(bin2hex(-3)));
186 $this->assertEquals(0, hex2bin(bin2hex(0)));
187 $this->assertEquals(12, hex2bin(bin2hex(12)));
188 $this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX)));