Advertisement
jlb

Elgg plugin simpletest suite

jlb
Dec 2nd, 2011
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Runs unit tests.
  4.  *
  5.  * @package Elgg
  6.  * @subpackage Test
  7.  */
  8.  
  9. $thisDirectory = dirname(__FILE__) . '/';
  10. require_once($thisDirectory . '../../../engine/start.php');
  11.  
  12. $vendor_path = "$CONFIG->path/vendors/simpletest";
  13. $test_path = "$CONFIG->path/engine/tests";
  14.  
  15. require_once("$vendor_path/unit_tester.php");
  16. require_once("$vendor_path/mock_objects.php");
  17. require_once("$vendor_path/reporter.php");
  18. require_once("$vendor_path/browser.php");
  19. require_once("$test_path/elgg_unit_test.php");
  20.  
  21. // turn off system log
  22. elgg_unregister_event_handler('all', 'all', 'system_log_listener');
  23. elgg_unregister_event_handler('log', 'systemlog', 'system_log_default_logger');
  24.  
  25. // Disable maximum execution time.
  26. // Tests take a while...
  27. set_time_limit(0);
  28.  
  29. // EDIT THE FOLLOWING
  30. $suite = new TestSuite('YOUR TEST SUITE NAME HERE');
  31. $suite->addFile('/path/to/test/class.php');
  32. $suite->addFile('/path/to/test/class2.php');
  33. $suite->addFile('/path/to/test/class3.php');
  34.  
  35. // Only run tests in debug mode.
  36. if (!isset($CONFIG->debug))
  37. {
  38.     exit ("The site must be in debug mode to run unit tests.\n");
  39. }
  40.  
  41. if (TextReporter::inCli()) {
  42.    
  43.     if (empty($argv[1]))
  44.     {
  45.         exit ("You must specify an output file for the XML report.\n");
  46.     }
  47.    
  48.     elgg_set_ignore_access(TRUE);
  49.    
  50.     if ($argv[1] == 'OUT')
  51.     {
  52.         $response = $suite->Run(new TextReporter());
  53.     }
  54.     else
  55.     {
  56.        
  57.         ini_set('implicit_flush', FALSE);
  58.         ob_start();
  59.        
  60.         require_once("$thisDirectory/xmltime.php");
  61.         $response = $suite->Run(new XmlTimeReporter());
  62.        
  63.         file_put_contents($argv[1], ob_get_contents());
  64.        
  65.         ob_end_clean();
  66.         ini_set('implicit_flush', TRUE);
  67.     }
  68.    
  69.     // In CLI error codes are returned: 0 is success
  70.     exit ($response ? 0 : 1 );
  71. } else {
  72.    
  73.     // Admin access only
  74.     admin_gatekeeper();
  75.    
  76.     $suite->Run(new HtmlReporter());
  77.    
  78.     exit;
  79. }
  80.  
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement