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