ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

unit_tests_utilities.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
34 function find_html_content_in_file( $FilePath )
35 {
36 $Errors = 0;
37 $FileContent = file( $FilePath );
38 $Patterns = array(
39 '<table' , '<a' , '<div' , '<span' , '<td' , '<tr' , '<li' , '<ul' , '<select' , '</a>' , '</div>' ,
40 '</span>' , '</select>' , '<script' , '<link' , '</ul>' , '</li>' , '<br>' , '<p>' , '<p ' , '<option'
41 );
42
43 for( $k = 0 ; $k < count( $FileContent ) ; $k++ )
44 {
45 for( $j = 0 ; $j < count( $Patterns ) ; $j++ )
46 {
47 if( strpos( $FileContent[ $k ] , $Patterns[ $j ] ) !== false )
48 {
49 $Errors++;
50 print( "<nobr>$FilePath($k)</nobr><br>" );
51 break;
52 }
53 }
54 }
55
56 return( $Errors );
57 }
58
77 function get_function_entries( $Content )
78 {
79 $Start = 0;
80 $Entries = array();
81
82 for( ; $Start !== false ; )
83 {
84 $Start = strpos( $Content , 'function' , $Start );
85
86 if( $Start !== false )
87 {
88 $Entries [] = $Start;
89 $Start += 8;
90 }
91 }
92
93 return( $Entries );
94 }
95
114 function isalnum( $Letter )
115 {
116 if( ( $Letter >= 'a' && $Letter <= 'z' ) || ( $Letter >= 'A' && $Letter <= 'Z' ) ||
117 ( $Letter >= '0' && $Letter <= '9' ) || $Letter == '_' )
118 {
119 return( true );
120 }
121
122 return( false );
123 }
124
147 function get_func_name( $Content , $Entry )
148 {
149 $Length = strlen( $Content );
150 $FunctionName = false;
151 for( $i = $Entry + 8 ; $i < $Length ; $i++ )
152 {
153 if( $FunctionName === false && isalnum( $Content[ $i ] ) )
154 {
155 $FunctionName = $Content[ $i ];
156 continue;
157 }
158 elseif( $FunctionName !== false && isalnum( $Content[ $i ] ) )
159 {
160 $FunctionName .= $Content[ $i ];
161 continue;
162 }
163 elseif( $FunctionName !== false && isalnum( $Content[ $i ] ) === false )
164 {
165 return( $FunctionName );
166 }
167 }
168 return( false );
169 }
170
193 function get_func_start( $Content , $Entry )
194 {
195 return( strpos( $Content , chr( 123 ) , $Entry ) );
196 }
197
220 function get_func_end( $Content , $Entry )
221 {
222 if( $Entry === false )
223 {
224 return( false );
225 }
226
227 $Length = strlen( $Content );
228 $Counter = 1;
229
230 for( $i = $Entry + 1 ; $i < $Length ; $i++ )
231 {
232 $Counter = $Content[ $i ] == '{' ? $Counter + 1 : $Counter;
233 $Counter = $Content[ $i ] == '}' ? $Counter - 1 : $Counter;
234
235 if( $Counter === 0 )
236 {
237 return( $i );
238 }
239 }
240
241 return( false );
242 }
243
262 function get_function_bodies( $Content )
263 {
264 $Entries = get_function_entries( $Content );
265 $Bodies = array();
266
267 foreach( $Entries as $i => $Entry )
268 {
269 $FunctionName = get_func_name( $Content , $Entry );
270 $FunctionStart = get_func_start( $Content , $Entry );
271 $FunctionEnd = get_func_end( $Content , $FunctionStart );
272
273 if( $FunctionStart !== false && $FunctionEnd !== false )
274 {
275 $Bodies [ $FunctionName ] = substr( $Content , $FunctionStart , $FunctionEnd - $FunctionStart + 1 );
276 }
277 }
278
279 return( $Bodies );
280 }
281
300 function count_lines( $Content )
301 {
302 $Content = str_replace( "\r" , "\n" , $Content );
303
304 $Content = str_replace( "\n\n" , "\n" , $Content );
305
306 $Content = explode( "\n" , $Content );
307
308 return( count( $Content ) );
309 }
310
325 function get_skip_files()
326 {
327 return(
328 array(
329 'excel' , 'soap' , 'json.php' , 'xml_rpc' , 'jquery.layout.min.js' , 'jquery.jstree.js' ,
330 'jquery.media.js' , '.en.js' , '.ru.js' , 'jquery.tree.xml_nested.js' , 'jquery.tree.xml_flat.js' ,
331 'jquery.tree.themeroller.js' , 'jquery.tree.contextmenu.js' , 'sarissa.js' , 'jquery.jstree.js' ,
332 'jquery.corner.js' , '.min.js' , 'disable.text.select.js' , 'dropdown.block.js' , '/doc/en/html/' ,
333 'jquery.jqGrid.min.js' , 'grid.locale-' , 'jquery.colorbox' , 'swfupload.js' , 'jquery.cookie.js' ,
334 'packages/ckeditor/include/' , 'jquery.jstree.js' , 'jquery-1.7.1.min.js' , 'ui.datepicker-ru.js' ,
335 'file_input_view/include/plugins/' , 'jstree/include/js/' , 'paginator3000.js' , '/tmp/' )
336 );
337 }
338
357 function skip_file( $FilePath )
358 {
359 $Files = get_skip_files();
360
361 foreach( $Files as $k => $v )
362 {
363 if( strpos( $FilePath , $v ) !== false )
364 {
365 return( true );
366 }
367 }
368
369 return( false );
370 }
371
372 ?>