]> git.mxchange.org Git - friendica.git/blob - tests/expand_acl_test.php
Merge pull request #3112 from Quix0r/rewrites/coding-convention
[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 /**
12  * TestCase for the expand_acl function
13  *
14  * @author Alexander Kampmann
15  * @package test.util
16  */
17 class ExpandAclTest extends PHPUnit_Framework_TestCase {
18         
19         /**
20          * test expand_acl, perfect input
21          */
22         public function testExpandAclNormal() {
23                 $text='<1><2><3>';
24                 $this->assertEquals(array(1, 2, 3), expand_acl($text));
25         }
26         
27         /**
28          * test with a big number
29          */
30         public function testExpandAclBigNumber() {
31                 $text='<1><'.PHP_INT_MAX.'><15>';
32                 $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
33         }
34         
35         /**
36          * test with a string in it. 
37          * 
38          * TODO: is this valid input? Otherwise: should there be an exception?
39          */
40         public function testExpandAclString() {
41                 $text="<1><279012><tt>"; 
42                 $this->assertEquals(array(1, 279012), expand_acl($text));
43         }
44         
45         /**
46          * test with a ' ' in it. 
47          * 
48          * TODO: is this valid input? Otherwise: should there be an exception?
49          */
50         public function testExpandAclSpace() {
51                 $text="<1><279 012><32>"; 
52                 $this->assertEquals(array(1, "279", "32"), expand_acl($text));
53         }
54         
55         /**
56          * test empty input
57          */
58         public function testExpandAclEmpty() {
59                 $text=""; 
60                 $this->assertEquals(array(), expand_acl($text));
61         }
62         
63         /**
64          * test invalid input, no < at all
65          * 
66          * TODO: should there be an exception?
67          */
68         public function testExpandAclNoBrackets() {
69                 $text="According to documentation, that's invalid. "; //should be invalid
70                 $this->assertEquals(array(), expand_acl($text));
71         }
72         
73         /**
74          * test invalid input, just open <
75          *
76          * TODO: should there be an exception?
77          */
78         public function testExpandAclJustOneBracket1() {
79                 $text="<Another invalid string"; //should be invalid
80                 $this->assertEquals(array(), expand_acl($text));
81         }
82         
83         /**
84          * test invalid input, just close >
85          *
86          * TODO: should there be an exception?
87          */
88         public function testExpandAclJustOneBracket2() {
89                 $text="Another invalid> string"; //should be invalid
90                 $this->assertEquals(array(), expand_acl($text));
91         }
92         
93         /**
94          * test invalid input, just close >
95          *
96          * TODO: should there be an exception?
97          */
98         public function testExpandAclCloseOnly() {
99                 $text="Another> invalid> string>"; //should be invalid
100                 $this->assertEquals(array(), expand_acl($text));
101         }
102         
103         /**
104          * test invalid input, just open <
105          *
106          * TODO: should there be an exception?
107          */
108         public function testExpandAclOpenOnly() {
109                 $text="<Another< invalid string<"; //should be invalid
110                 $this->assertEquals(array(), expand_acl($text));
111         }
112         
113         /**
114          * test invalid input, open and close do not match
115          *
116          * TODO: should there be an exception?
117          */
118         public function testExpandAclNoMatching1() {
119                 $text="<Another<> invalid <string>"; //should be invalid
120                 $this->assertEquals(array(), expand_acl($text));
121         }
122         
123         /**
124          * test invalid input, open and close do not match
125          *
126          * TODO: should there be an exception?
127          */
128         public function testExpandAclNoMatching2() {
129                 $text="<1>2><3>";
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));
136         }
137         
138         /**
139          * test invalid input, empty <>
140          *
141          * TODO: should there be an exception? Or array(1, 3)
142          * (This should be array(1,3) - mike)
143          */
144         public function testExpandAclEmptyMatch() {
145                 $text="<1><><3>";
146                 $this->assertEquals(array(1,3), expand_acl($text));
147         }
148 }