]> git.mxchange.org Git - friendica.git/blob - tests/include/TextTest.php
Merge pull request #6601 from annando/false-notifications
[friendica.git] / tests / include / TextTest.php
1 <?php
2 /**
3  * TextTest class.
4  */
5
6 namespace Friendica\Test;
7
8 use PHPUnit\Framework\TestCase;
9
10 /**
11  * Tests for text functions.
12  */
13 class TextTest extends TestCase
14 {
15         /**
16          * test attribute contains
17          */
18         public function testAttributeContains1()
19         {
20                 $testAttr="class1 notclass2 class3";
21                 $this->assertTrue(attribute_contains($testAttr, "class3"));
22                 $this->assertFalse(attribute_contains($testAttr, "class2"));
23         }
24
25         /**
26          * test attribute contains
27          */
28         public function testAttributeContains2()
29         {
30                 $testAttr="class1 not-class2 class3";
31                 $this->assertTrue(attribute_contains($testAttr, "class3"));
32                 $this->assertFalse(attribute_contains($testAttr, "class2"));
33         }
34
35         /**
36          * test with empty input
37          */
38         public function testAttributeContainsEmpty()
39         {
40                 $testAttr="";
41                 $this->assertFalse(attribute_contains($testAttr, "class2"));
42         }
43
44         /**
45          * test input with special chars
46          */
47         public function testAttributeContainsSpecialChars()
48         {
49                 $testAttr="--... %\$รค() /(=?}";
50                 $this->assertFalse(attribute_contains($testAttr, "class2"));
51         }
52
53         /**
54          * test expand_acl, perfect input
55          */
56         public function testExpandAclNormal()
57         {
58                 $text='<1><2><3>';
59                 $this->assertEquals(array(1, 2, 3), expand_acl($text));
60         }
61
62         /**
63          * test with a big number
64          */
65         public function testExpandAclBigNumber()
66         {
67                 $text='<1><'.PHP_INT_MAX.'><15>';
68                 $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
69         }
70
71         /**
72          * test with a string in it.
73          *
74          * @todo is this valid input? Otherwise: should there be an exception?
75          */
76         public function testExpandAclString()
77         {
78                 $text="<1><279012><tt>";
79                 $this->assertEquals(array(1, 279012), expand_acl($text));
80         }
81
82         /**
83          * test with a ' ' in it.
84          *
85          * @todo is this valid input? Otherwise: should there be an exception?
86          */
87         public function testExpandAclSpace()
88         {
89                 $text="<1><279 012><32>";
90                 $this->assertEquals(array(1, "279", "32"), expand_acl($text));
91         }
92
93         /**
94          * test empty input
95          */
96         public function testExpandAclEmpty()
97         {
98                 $text="";
99                 $this->assertEquals(array(), expand_acl($text));
100         }
101
102         /**
103          * test invalid input, no < at all
104          *
105          * @todo should there be an exception?
106          */
107         public function testExpandAclNoBrackets()
108         {
109                 $text="According to documentation, that's invalid. "; //should be invalid
110                 $this->assertEquals(array(), expand_acl($text));
111         }
112
113         /**
114          * test invalid input, just open <
115          *
116          * @todo should there be an exception?
117          */
118         public function testExpandAclJustOneBracket1()
119         {
120                 $text="<Another invalid string"; //should be invalid
121                 $this->assertEquals(array(), expand_acl($text));
122         }
123
124         /**
125          * test invalid input, just close >
126          *
127          * @todo should there be an exception?
128          */
129         public function testExpandAclJustOneBracket2()
130         {
131                 $text="Another invalid> string"; //should be invalid
132                 $this->assertEquals(array(), expand_acl($text));
133         }
134
135         /**
136          * test invalid input, just close >
137          *
138          * @todo should there be an exception?
139          */
140         public function testExpandAclCloseOnly()
141         {
142                 $text="Another> invalid> string>"; //should be invalid
143                 $this->assertEquals(array(), expand_acl($text));
144         }
145
146         /**
147          * test invalid input, just open <
148          *
149          * @todo should there be an exception?
150          */
151         public function testExpandAclOpenOnly()
152         {
153                 $text="<Another< invalid string<"; //should be invalid
154                 $this->assertEquals(array(), expand_acl($text));
155         }
156
157         /**
158          * test invalid input, open and close do not match
159          *
160          * @todo should there be an exception?
161          */
162         public function testExpandAclNoMatching1()
163         {
164                 $text="<Another<> invalid <string>"; //should be invalid
165                 $this->assertEquals(array(), expand_acl($text));
166         }
167
168         /**
169          * test invalid input, empty <>
170          *
171          * @todo should there be an exception? Or array(1, 3)
172          * (This should be array(1,3) - mike)
173          */
174         public function testExpandAclEmptyMatch()
175         {
176                 $text="<1><><3>";
177                 $this->assertEquals(array(1,3), expand_acl($text));
178         }
179
180         /**
181          * test hex2bin and reverse
182          */
183         public function testHex2Bin()
184         {
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)));
189         }
190 }