]> git.mxchange.org Git - friendica.git/blob - tests/expand_acl_test.php
fix directory search
[friendica.git] / tests / expand_acl_test.php
1 <?php
2 /**
3  * this test tests the expand_acl function
4  *
5  * @package test.util
6  */
7
8 /** required, it is the file under test */
9 require_once('include/text.php');
10
11 /**\r
12  * TestCase for the expand_acl function\r
13  *\r
14  * @author Alexander Kampmann\r
15  * @package test.util\r
16  */\r
17 class ExpandAclTest extends PHPUnit_Framework_TestCase {
18         
19         /**\r
20          * test expand_acl, perfect input\r
21          */\r
22         public function testExpandAclNormal() {\r
23                 $text='<1><2><3>';\r
24                 $this->assertEquals(array(1, 2, 3), expand_acl($text));\r
25         }\r
26         
27         /**
28          * test with a big number
29          */\r
30         public function testExpandAclBigNumber() {\r
31                 $text='<1><'.PHP_INT_MAX.'><15>';\r
32                 $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));\r
33         }\r
34         
35         /**
36          * test with a string in it. 
37          * 
38          * TODO: is this valid input? Otherwise: should there be an exception?
39          */\r
40         public function testExpandAclString() {\r
41                 $text="<1><279012><tt>"; \r
42                 $this->assertEquals(array(1, 279012), expand_acl($text));\r
43         }\r
44         
45         /**
46          * test with a ' ' in it. 
47          * 
48          * TODO: is this valid input? Otherwise: should there be an exception?
49          */\r
50         public function testExpandAclSpace() {\r
51                 $text="<1><279 012><32>"; \r
52                 $this->assertEquals(array(1, "279", "32"), expand_acl($text));\r
53         }\r
54         
55         /**
56          * test empty input
57          */\r
58         public function testExpandAclEmpty() {\r
59                 $text=""; \r
60                 $this->assertEquals(array(), expand_acl($text));\r
61         }\r
62         
63         /**
64          * test invalid input, no < at all
65          * 
66          * TODO: should there be an exception?
67          */\r
68         public function testExpandAclNoBrackets() {\r
69                 $text="According to documentation, that's invalid. "; //should be invalid\r
70                 $this->assertEquals(array(), expand_acl($text));\r
71         }\r
72         
73         /**\r
74          * test invalid input, just open <\r
75          *\r
76          * TODO: should there be an exception?\r
77          */\r
78         public function testExpandAclJustOneBracket1() {\r
79                 $text="<Another invalid string"; //should be invalid\r
80                 $this->assertEquals(array(), expand_acl($text));\r
81         }\r
82         
83         /**\r
84          * test invalid input, just close >\r
85          *\r
86          * TODO: should there be an exception?\r
87          */\r
88         public function testExpandAclJustOneBracket2() {\r
89                 $text="Another invalid> string"; //should be invalid\r
90                 $this->assertEquals(array(), expand_acl($text));\r
91         }\r
92         
93         /**\r
94          * test invalid input, just close >\r
95          *\r
96          * TODO: should there be an exception?\r
97          */\r
98         public function testExpandAclCloseOnly() {\r
99                 $text="Another> invalid> string>"; //should be invalid\r
100                 $this->assertEquals(array(), expand_acl($text));\r
101         }\r
102         
103         /**\r
104          * test invalid input, just open <\r
105          *\r
106          * TODO: should there be an exception?\r
107          */\r
108         public function testExpandAclOpenOnly() {\r
109                 $text="<Another< invalid string<"; //should be invalid\r
110                 $this->assertEquals(array(), expand_acl($text));\r
111         }\r
112         
113         /**\r
114          * test invalid input, open and close do not match\r
115          *\r
116          * TODO: should there be an exception?\r
117          */\r
118         public function testExpandAclNoMatching1() {\r
119                 $text="<Another<> invalid <string>"; //should be invalid\r
120                 $this->assertEquals(array(), expand_acl($text));\r
121         }\r
122         
123         /**\r
124          * test invalid input, open and close do not match\r
125          *\r
126          * TODO: should there be an exception?\r
127          */\r
128         public function testExpandAclNoMatching2() {\r
129                 $text="<1>2><3>";\r
130 // The angles are delimiters which aren't important
131 // the important thing is the numeric content, this returns array(1,2,3) currently
132 // we may wish to eliminate 2 from the results, though it isn't harmful
133 // It would be a better test to figure out if there is any ACL input which can
134 // produce this $text and fix that instead.
135 //              $this->assertEquals(array(), expand_acl($text));\r
136         }
137         
138         /**\r
139          * test invalid input, empty <>\r
140          *\r
141          * TODO: should there be an exception? Or array(1, 3)\r
142          * (This should be array(1,3) - mike)
143          */\r
144         public function testExpandAclEmptyMatch() {\r
145                 $text="<1><><3>";\r
146                 $this->assertEquals(array(1,3), expand_acl($text));\r
147         }
148 }