suite.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Runs unit tests.
  4. *
  5. * @package Elgg
  6. * @subpackage Test
  7. */
  8. require_once(dirname( __FILE__ ) . '/../start.php');
  9. require_once(dirname( __FILE__ ) . '/../../vendor/autoload.php');
  10. $test_path = "$CONFIG->path/engine/tests";
  11. require_once("$test_path/ElggCoreUnitTest.php");
  12. require_once("$test_path/ElggCoreGetEntitiesBaseTest.php");
  13. // plugins that contain unit tests
  14. $plugins = array(
  15. 'groups',
  16. 'htmlawed',
  17. 'thewire',
  18. 'web_services'
  19. );
  20. // don't expect admin session for CLI
  21. if (!TextReporter::inCli()) {
  22. elgg_admin_gatekeeper();
  23. } else {
  24. $admin = array_shift(elgg_get_admins(array('limit' => 1)));
  25. if (!login($admin)) {
  26. echo "Failed to login as administrator.";
  27. exit(1);
  28. }
  29. // activate plugins that are not activated on install
  30. foreach ($plugins as $key => $id) {
  31. $plugin = elgg_get_plugin_from_id($id);
  32. if (!$plugin || $plugin->isActive()) {
  33. unset($plugins[$key]);
  34. continue;
  35. }
  36. $plugin->activate();
  37. }
  38. $CONFIG->debug = 'NOTICE';
  39. }
  40. // turn off system log
  41. elgg_unregister_event_handler('all', 'all', 'system_log_listener');
  42. elgg_unregister_event_handler('log', 'systemlog', 'system_log_default_logger');
  43. // turn off notifications
  44. $notifications = _elgg_services()->notifications;
  45. $events = $notifications->getEvents();
  46. foreach ($events as $type => $subtypes) {
  47. foreach ($subtypes as $subtype => $actions) {
  48. $notifications->unregisterEvent($type, $subtype);
  49. }
  50. }
  51. // Disable maximum execution time.
  52. // Tests take a while...
  53. set_time_limit(0);
  54. $suite = new TestSuite('Elgg Core Unit Tests');
  55. // emit a hook to pull in all tests
  56. $test_files = elgg_trigger_plugin_hook('unit_test', 'system', null, array());
  57. foreach ($test_files as $file) {
  58. $suite->addFile($file);
  59. }
  60. if (TextReporter::inCli()) {
  61. // In CLI error codes are returned: 0 is success
  62. $start_time = microtime(true);
  63. $reporter = new TextReporter();
  64. $result = $suite->Run($reporter) ? 0 : 1 ;
  65. echo sprintf("Time: %.2f seconds, Memory: %.2fMb\n",
  66. microtime(true) - $start_time,
  67. memory_get_peak_usage() / 1048576.0 // in megabytes
  68. );
  69. // deactivate plugins that were activated for test suite
  70. foreach ($plugins as $key => $id) {
  71. $plugin = elgg_get_plugin_from_id($id);
  72. $plugin->deactivate();
  73. }
  74. exit($result);
  75. }
  76. $old = elgg_set_ignore_access(true);
  77. $suite->Run(new HtmlReporter('utf-8'));
  78. elgg_set_ignore_access($old);