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
16 require_once( dirname( __FILE__ ).'/unit_tests_utilities.php' );
17
28 class unit_tests{
29
40 var $Utilities = false;
41
52 function set_up()
53 {
54 $this->Utilities = get_package( 'utilities' , 'last' , __FILE__ );
55 }
56
67 function tear_down()
68 {
69 }
70
81 function test_load_package()
82 {
83 get_package( 'page::page_composer' , 'last' , __FILE__ );
84
85 return( 'TEST PASSED' );
86 }
87
98 function test_line_length_php()
99 {
100 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
101 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
102 {
103 $Content = file( $Files[ $i ] );
104 if( skip_file( $Files[ $i ] ) === false )
105 {
106 for( $j = 0 ; $j < count( $Content ) ; $j++ )
107 {
108 $Line = str_replace(
109 array( "\t" , "\r" , "\n" ) , array( ' ' , '' , '' ) , $Content[ $j ]
110 );
111 if( mb_strlen( $Line , 'UTF-8' ) > 120 )
112 {
113 $Errors++;
114 $Line = htmlspecialchars( $Line , ENT_QUOTES );
115 print( "<nobr>".$Files[ $i ]."(".( $j + 1 ).")</nobr><br>" );
116 }
117 }
118 }
119 }
120 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
121 }
122
133 function test_line_count_php()
134 {
135 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
136
137 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 100 ; $i++ )
138 {
139 $Content = file( $Files[ $i ] );
140
141 if( count( $Content ) > 1000 && strpos( $Files[ $i ] , 'excel' ) === false &&
142 strpos( $Files[ $i ] , 'nusoap' ) === false )
143 {
144 $Errors++;
145 print( "<nobr>{$Files[ $i ]}</nobr><br>" );
146 }
147 }
148
149 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
150 }
151
162 function test_file_size_php()
163 {
164 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
165
166 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 100 ; $i++ )
167 {
168 $Content = file_get_contents( $Files[ $i ] );
169
170 if( strlen( $Content ) > 24 * 1024 && skip_file( $Files[ $i ] ) === false )
171 {
172 $Errors++;
173 print( "<nobr>{$Files[ $i ]}</nobr><br>" );
174 }
175 }
176
177 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
178 }
179
190 function test_file_html_code_php()
191 {
192 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
193
194 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 1000 ; $i++ )
195 {
196 if( skip_file( $Files[ $i ] ) === false && strpos( $Files[ $i ] , 'tags.php' ) === false &&
197 strpos( $Files[ $i ] , 'page_composer/include/php/unit_tests_utilities.php' ) === false &&
198 strpos( $Files[ $i ] , 'page_composer/include/php/unit_tests.php' ) === false )
199 {
200 $Errors += find_html_content_in_file( $Files[ $i ] );
201 }
202 }
203
204 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
205 }
206
217 function test_tpl_files()
218 {
219 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.tpl/' , true );
220
221 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 1000 ; $i++ )
222 {
223 $Content = file_get_contents( $Files[ $i ] );
224
225 if( strpos( $Content , 'style=' ) !== false )
226 {
227 $Errors++;
228 print( "<nobr>{$Files[ $i ]}</nobr><br>" );
229 }
230 }
231
232 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
233 }
234
245 function test_function_lines_php()
246 {
247 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
248 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 1000 ; $i++ )
249 {
250 if( skip_file( $Files[ $i ] ) )
251 {
252 continue;
253 }
254 $Content = file_get_contents( $Files[ $i ] );
255 $Bodies = get_function_bodies( $Content );
256 foreach( $Bodies as $FunctionName => $Body )
257 {
258 if( ( $LinesCount = count_lines( $Body ) ) > 30 )
259 {
260 $Errors++;
261 print( "<nobr>{$Files[ $i ]}($FunctionName:$LinesCount)</nobr><br>" );
262 }
263 }
264 }
265 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
266 }
267
278 function test_function_size_php()
279 {
280 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
281 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 1000 ; $i++ )
282 {
283 if( skip_file( $Files[ $i ] ) )
284 {
285 continue;
286 }
287 $Content = file_get_contents( $Files[ $i ] );
288 $Bodies = get_function_bodies( $Content );
289 foreach( $Bodies as $FunctionName => $Body )
290 {
291 /* 800 bytes max */
292 if( ( $BytesCount = strlen( $Body ) ) > 800 )
293 {
294 $Errors++;
295 print( "<nobr>{$Files[ $i ]}($FunctionName:$BytesCount)</nobr><br>" );
296 }
297 }
298 }
299 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
300 }
301
312 function test_get_package_object_for_settings()
313 {
314 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
315 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 1000 ; $i++ )
316 {
317 if( skip_file( $Files[ $i ] ) ||
318 strpos( $Files[ $i ] , '/page_composer/include/php/unit_tests.php' ) !== false )
319 {
320 continue;
321 }
322
323 $Content = file_get_contents( $Files[ $i ] );
324 if( strpos( $Content , "get_package( 'settings::settings'" ) !== false )
325 {
326 $Errors++;
327 print( "<nobr>{$Files[ $i ]}</nobr><br>" );
328 }
329 }
330 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
331 }
332
333 // JS
334
345 function test_line_length_js()
346 {
347 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.js/' , true );
348 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
349 {
350 $Content = file( $Files[ $i ] );
351 if( skip_file( $Files[ $i ] ) === false )
352 {
353 for( $j = 0 ; $j < count( $Content ) ; $j++ )
354 {
355 $Line = str_replace(
356 array( "\t" , "\r" , "\n" ) , array( ' ' , '' , '' ) , $Content[ $j ]
357 );
358 if( mb_strlen( $Line , 'UTF-8' ) > 120 )
359 {
360 $Errors++;
361 $Line = htmlspecialchars( $Line , ENT_QUOTES );
362 print( "<nobr>".$Files[ $i ]."(".( $j + 1 ).")</nobr><br>" );
363 }
364 }
365 }
366 }
367 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
368 }
369
380 function test_line_count_js()
381 {
382 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.js/' , true );
383
384 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 100 ; $i++ )
385 {
386 $Content = file( $Files[ $i ] );
387
388 if( count( $Content ) > 1000 && skip_file( $Files[ $i ] ) === false )
389 {
390 $Errors++;
391 print( "<nobr>{$Files[ $i ]}</nobr><br>" );
392 }
393 }
394
395 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
396 }
397
408 function test_file_size_js()
409 {
410 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.js/' , true );
411
412 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 100 ; $i++ )
413 {
414 $Content = file_get_contents( $Files[ $i ] );
415
416 if( strlen( $Content ) > 24 * 1024 && skip_file( $Files[ $i ] ) === false )
417 {
418 $Errors++;
419 print( "<nobr>{$Files[ $i ]}</nobr><br>" );
420 }
421 }
422
423 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
424 }
425
436 function test_function_lines_js()
437 {
438 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.js/' , true );
439 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 1000 ; $i++ )
440 {
441 if( skip_file( $Files[ $i ] ) )
442 {
443 continue;
444 }
445 $Content = file_get_contents( $Files[ $i ] );
446 $Bodies = get_function_bodies( $Content );
447 foreach( $Bodies as $FunctionName => $Body )
448 {
449 if( ( $LinesCount = count_lines( $Body ) ) > 20 )
450 {
451 $Errors++;
452 print( "<nobr>{$Files[ $i ]} $Body : Lines count: $LinesCount</nobr><br>" );
453 }
454 }
455 }
456 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
457 }
458
469 function test_function_size_js()
470 {
471 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.js/' , true );
472 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) && $Errors < 1000 ; $i++ )
473 {
474 if( skip_file( $Files[ $i ] ) )
475 {
476 continue;
477 }
478 $Content = file_get_contents( $Files[ $i ] );
479 $Bodies = get_function_bodies( $Content );
480 foreach( $Bodies as $FunctionName => $Body )
481 {
482 /* 800 bytes max */
483 if( ( $BytesCount = strlen( $Body ) ) > 680 )
484 {
485 $Errors++;
486 print( "<nobr>{$Files[ $i ]}($FunctionName:$BytesCount)</nobr><br>" );
487 }
488 }
489 }
490 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
491 }
492
503 function test_process()
504 {
505 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
506 /* all process_* functions of the template engine must be moved to the auto_markup */
507 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
508 {
509 $Bodies = get_function_bodies( file_get_contents( $Files[ $i ] ) );
510 foreach( $Bodies as $FunctionName => $Body )
511 {
512 if( strpos( $FunctionName , 'process_' ) !== false &&
513 strpos( $FunctionName , 'process_string' ) === false )
514 {
515 $Errors++;
516 print( "<nobr>".$Files[ $i ]."</nobr><br>" );
517 }
518 }
519 }
520 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
521 }
522
533 function test_todo_tag()
534 {
535 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.(php|js)/' , true );
536
537 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
538 {
539 if( skip_file( $Files[ $i ] ) === false )
540 {
541 $Content = file( $Files[ $i ] );
542 for( $j = 0 ; $j < count( $Content ) ; $j++ )
543 {
544 $Line = $Content[ $j ];
545 if( ( $Start = strpos( $Line , 'TO'.'DO' ) ) !== false )
546 {
547 $Errors++;
548 $Message = trim( mb_substr( $Line , $Start + 5 ) );
549 print( "<nobr>".$Files[ $i ]." : $Message</nobr><br>" );
550 }
551 }
552 }
553 }
554 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
555 }
556
567 function test_smth_view_js()
568 {
569 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
570 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
571 {
572 $FileName = basename( $Files[ $i ] , '.php' );
573 if( strpos( $Files[ $i ] , '_view.php' ) !== false && $FileName !== 'lang_view' &&
574 $FileName !== 'graph_view' && $FileName !== 'json_view' )
575 {
576 $Path = dirname( $Files[ $i ] )."/include/js/$FileName.js";
577 if( file_exists( $Path ) === false )
578 {
579 $Errors++;
580 print( "<nobr>".$Files[ $i ]."</nobr><br>" );
581 }
582 }
583 }
584 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
585 }
586
597 function test_get_list_form_js()
598 {
599 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
600 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
601 {
602 if( strpos( $Files[ $i ] , '_view.php' ) !== false )
603 {
604 $Path = dirname( $Files[ $i ] ).'/include/js/'.basename( $Files[ $i ] , '.php' ).'.js';
605 if( file_exists( $Path ) )
606 {
607 $Content = file_get_contents( $Path );
608 if( strpos( $Content , '.get_list_form = function(' ) === false )
609 {
610 $Errors++;
611 print( "<nobr>".$Path." : no get_list_form found</nobr><br>" );
612 }
613 }
614 }
615 }
616 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
617 }
618
629 function test_delete_js()
630 {
631 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
632 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
633 {
634 if( strpos( $Files[ $i ] , '_view.php' ) !== false )
635 {
636 $Path = dirname( $Files[ $i ] ).'/include/js/'.basename( $Files[ $i ] , '.php' ).'.js';
637 if( file_exists( $Path ) )
638 {
639 $Content = file_get_contents( $Path );
640 if( strpos( $Content , '.delete = function(' ) === false )
641 {
642 $Errors++;
643 print( "<nobr>".$Path." : no delete found</nobr><br>" );
644 }
645 }
646 }
647 }
648 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
649 }
650
661 function test_get_custom_list_form_js()
662 {
663 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
664 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
665 {
666 if( strpos( $Files[ $i ] , '_view.php' ) !== false )
667 {
668 $Path = dirname( $Files[ $i ] ).'/include/js/'.basename( $Files[ $i ] , '.php' ).'.js';
669 if( file_exists( $Path ) )
670 {
671 $Content = file_get_contents( $Path );
672 if( strpos( $Content , '.get_custom_list_form = function(' ) === false )
673 {
674 $Errors++;
675 print( "<nobr>".$Path." : no get_custom_list_form found</nobr><br>" );
676 }
677 }
678 }
679 }
680 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
681 }
682
693 function test_record_view_form_js()
694 {
695 $Errors = 0;
696
697 $Packages = _get_packages_list();
698
699 for( $i = 0 ; $i < count( $Packages ) ; $i++ )
700 {
701 $Path = _get_package_relative_path_ex(
702 $Packages[ $i ][ 'package_name' ] , $Packages[ $i ][ 'package_version' ]
703 );
704 if( file_exists( $Path.'/include/php/unit_tests.php' ) === false )
705 {
706 $Errors++;
707 print( "<nobr>".$Path." : no unit tests were found</nobr><br>" );
708 }
709 }
710
711 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
712 }
713
724 function test_smth_display_list()
725 {
726 $Files = $this->Utilities->get_files_from_directory( '.' , '/.+\.php/' , true );
727
728 for( $i = 0 , $Errors = 0 ; $i < count( $Files ) ; $i++ )
729 {
730 if( strpos( $Files[ $i ] , '_manager.php' ) !== false &&
731 strpos( $Files[ $i ] , 'event_manager.php' ) === false )
732 {
733 $Content = file_get_contents( dirname( $Files[ $i ] )."/include/php/unit_tests.php" );
734 if( strpos( $Content , 'test_display_list' ) === false )
735 {
736 $Errors++;
737 print( "<nobr>".$Files[ $i ]."</nobr><br>" );
738 }
739 }
740 }
741
742 return( $Errors == 0 ? 'TEST PASSED' : "ERROR( $Errors )" );
743 }
744 }
745
746 ?>