ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

unit_tests.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class unit_tests{
27
38 function test_no_macro()
39 {
40 $String = get_package_object( 'string' , 'last' , __FILE__ );
41 $Script = 'some prefix some postfix';
42 $Result = $String->get_macro_parameters( $Script , 'macro' );
43
44 if( $Result == false )
45 {
46 return( 'TEST PASSED' );
47 }
48 else
49 {
50 return( 'ERROR' );
51 }
52 }
53
64 function test_simple()
65 {
66 $String = get_package_object( 'string' , 'last' , __FILE__ );
67 $Script = 'some prefix {macro:a=1;b=2} some postfix';
68 $Result = $String->get_macro_parameters( $Script , 'macro' );
69
70 if( $Result == "a=1;b=2" )
71 {
72 return( 'TEST PASSED' );
73 }
74 else
75 {
76 return( 'ERROR' );
77 }
78 }
79
90 function test_simple_2()
91 {
92 $String = get_package_object( 'string' , 'last' , __FILE__ );
93 $Script = 'some prefix {macro:a=1;b=2} middle {macro:a=3;b=4} some postfix';
94 $Result = $String->get_macro_parameters( $Script , 'macro' );
95
96 if( $Result == "a=1;b=2" )
97 {
98 return( 'TEST PASSED' );
99 }
100 else
101 {
102 return( 'ERROR' );
103 }
104 }
105
116 function test_nested()
117 {
118 $String = get_package_object( 'string' , 'last' , __FILE__ );
119 $Script = 'some prefix {macro:a={lang:space};b=2} some postfix';
120 $Result = $String->get_macro_parameters( $Script , 'macro' );
121
122 if( $Result == "a={lang:space};b=2" )
123 {
124 return( 'TEST PASSED' );
125 }
126 else
127 {
128 return( 'ERROR' );
129 }
130 }
131
142 function test_regexp_terminal()
143 {
144 $String = get_package_object( 'string' , 'last' , __FILE__ );
145 $Script = 'some prefix {macro:a=1;b=2} some postfix';
146 $Result = $String->get_macro_parameters(
147 $Script , 'macro' , array( 'a' => TERMINAL_VALUE , 'b' => TERMINAL_VALUE )
148 );
149
150 if( $Result == "a=1;b=2" )
151 {
152 return( 'TEST PASSED' );
153 }
154 else
155 {
156 return( 'ERROR' );
157 }
158 }
159
170 function test_regexp_terminal_not_found()
171 {
172 $String = get_package_object( 'string' , 'last' , __FILE__ );
173 $Script = 'some prefix {macro:a={lang:space};b=2} some postfix';
174 $Result = $String->get_macro_parameters(
175 $Script , 'macro' , array( 'a' => TERMINAL_VALUE , 'b' => TERMINAL_VALUE )
176 );
177
178 if( $Result == false )
179 {
180 return( 'TEST PASSED' );
181 }
182 else
183 {
184 return( 'ERROR' );
185 }
186 }
187
200 function test_regexp_second_found()
201 {
202 $String = get_package_object( 'string' , 'last' , __FILE__ );
203 $Script = 'some prefix {macro:a={lang:space};b=2} middle {macro:a=3;b=4} some postfix';
204 $Result = $String->get_macro_parameters(
205 $Script , 'macro' , array( 'a' => TERMINAL_VALUE , 'b' => TERMINAL_VALUE )
206 );
207
208 if( $Result == 'a=3;b=4' )
209 {
210 return( 'TEST PASSED' );
211 }
212 else
213 {
214 return( 'ERROR' );
215 }
216 }
217
228 function test_recursive()
229 {
230 $String = get_package_object( 'string' , 'last' , __FILE__ );
231 $Script = 'some prefix {macro:a={macro:a=3;b=4};b=2} some postfix';
232 $Result = $String->get_macro_parameters(
233 $Script , 'macro' , array( 'a' => TERMINAL_VALUE , 'b' => TERMINAL_VALUE )
234 );
235
236 if( $Result == 'a=3;b=4' )
237 {
238 return( 'TEST PASSED' );
239 }
240 else
241 {
242 return( 'ERROR' );
243 }
244 }
245
256 function test_invalid_macro()
257 {
258 $String = get_package_object( 'string' , 'last' , __FILE__ );
259 $Script = 'some prefix '.chr( 123 ).'macro:a='.chr( 123 ).'lang:space'.
260 chr( 125 ).';b=2 middle '.chr( 123 ).'macro:a=3;b=4'.chr( 125 ).' some postfix';
261 $Result = $String->get_macro_parameters(
262 $Script , 'macro' , array( 'a' => TERMINAL_VALUE , 'b' => TERMINAL_VALUE )
263 );
264
265 if( $Result == 'a=3;b=4' )
266 {
267 return( 'TEST PASSED' );
268 }
269 else
270 {
271 return( 'ERROR' );
272 }
273 }
274
285 function test_top_complexity()
286 {
287 $String = get_package_object( 'string' , 'last' , __FILE__ );
288 $Script = 'some prefix {macro:a={{}}{}{{}}:space};b=2 middle {{}}}{}{ '.
289 '{macro:a=3;b=4} some {{}}{}}{}{}{}{} postfix';
290 $Result = $String->get_macro_parameters(
291 $Script , 'macro' , array( 'a' => TERMINAL_VALUE , 'b' => TERMINAL_VALUE )
292 );
293
294 if( $Result == 'a=3;b=4' )
295 {
296 return( 'TEST PASSED' );
297 }
298 else
299 {
300 return( 'ERROR' );
301 }
302 }
303 }
304
305 ?>