? simpletest-hook_requirements-212415-8.patch
? simpletest0xr
? simpletest_1.0.1.tar.gz
Index: simpletest.install
===================================================================
RCS file: simpletest.install
diff -N simpletest.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ simpletest.install	18 May 2008 19:57:20 -0000
@@ -0,0 +1,51 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * SimpleTest installation file; ensures presence of SimpleTest library.
+ */
+
+/**
+ * Mininum required SimpleTest library version.
+ * 
+ * 1.0.1beta2 is required for the upload tests to work.
+ */
+define('SIMPLETEST_MINIMUM_VERSION', '1.0.1beta2');
+
+/**
+ * Implementation of hook_requirements().
+ */
+function simpletest_requirements($phase) {
+  $requirements = array();
+  $module_path = drupal_get_path('module', 'simpletest');
+  $simpletest_path = $module_path .'/simpletest/simpletest.php';
+
+  // Ensure translations don't break at install time.
+  $t = get_t();
+
+  // Check installed SimpleTest library version.
+  $simpletest_version = 0;
+  if (is_file($simpletest_path)) {
+    include_once $simpletest_path;
+    $simpletest_version = SimpleTest::getVersion();
+   }
+   
+  // Check for presence of required version of SimpleTest library.
+  $requirements['simpletest'] = array(
+    'title' => $t('SimpleTest library'),
+    'value' => $simpletest_version > 0 ? $simpletest_version : $t('Not found'),
+  );
+  $install_link = base_path() . $module_path .'/INSTALL.txt';
+  $download_link = 'http://sourceforge.net/project/showfiles.php?group_id=76550&package_id=77275';
+  if ($simpletest_version == 0) {
+    $requirements['simpletest']['description'] = $t('The SimpleTest library is not installed. You must <a href="@download">download the SimpleTest library</a> and place it your SimpleTest module folder. For more detailed instructions, see <a href="@install">INSTALL.txt</a>.', array('@download' => $download_link, '@install' => $install_link));
+    $requirements['simpletest']['severity'] = REQUIREMENT_ERROR;
+  }
+  elseif (version_compare($simpletest_version, SIMPLETEST_MINIMUM_VERSION) < 0) {
+    $requirements['simpletest']['description'] = $t('The SimpleTest module requires at least version %minimum-version of the SimpleTest library. Please <a href="@download">download a more recent SimpleTest library</a>. For more detailed instructions, see <a href="@install">INSTALL.txt</a>.', array('%minimum-version' => SIMPLETEST_MINIMUM_VERSION, '@download' => $download_link, '@install' => $install_link));
+    $requirements['simpletest']['severity'] = REQUIREMENT_ERROR;
+   }
+
+  return $requirements;
+}
Index: simpletest.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/simpletest/simpletest.module,v
retrieving revision 1.33.2.1
diff -u -p -r1.33.2.1 simpletest.module
--- simpletest.module	26 Feb 2008 19:16:21 -0000	1.33.2.1
+++ simpletest.module	18 May 2008 19:57:25 -0000
@@ -2,6 +2,16 @@
 // $Id: simpletest.module,v 1.33.2.1 2008/02/26 19:16:21 rokZlender Exp $
 
 /**
+ * Path to the SimpleTest module.
+ */
+define('SIMPLETEST_MODULE_PATH', drupal_get_path('module', 'simpletest'));
+
+/**
+ * Path to the SimpleTest library.
+ */
+define('SIMPLETEST_LIBRARY_PATH', SIMPLETEST_MODULE_PATH .'/simpletest');
+
+/**
  * Implementation of hook_help().
  */
 function simpletest_help($path, $arg) {
@@ -44,51 +54,23 @@ function simpletest_perm() {
 }
 
 /**
- * Try to load the simepletest
- * @return boolean TRUE if the load succeeded
+ * Load required SimepleTest files.
  */
 function simpletest_load() {
-  static $loaded;
-  if ($loaded) {
-    return true; 
-  }
-  global $user;
-  if ($user->uid != 1) {
-    drupal_set_message(t('It is strongly suggested to run the tests with the first user!'));
-  }
-  $loaded = true;
-  if (!defined('SIMPLE_TEST')) {
-    define('SIMPLE_TEST', drupal_get_path('module', 'simpletest') .'/simpletest'); 
-  }
-  if (!is_dir(SIMPLE_TEST)) {
-    return simpletest_trigger_error('not available');
-  }
-  
-  // We currently use only the web tester that DrupalTestCase is built upon
-  require_once(SIMPLE_TEST .'/web_tester.php');
-  require_once(SIMPLE_TEST .'/reporter.php');
-  require_once('drupal_reporter.php');
- 
-  if (version_compare(SimpleTest::getVersion(), '1.0.1beta2') < 0) {
-    return simpletest_trigger_error('stale version');
-  }
-  
-  $path = drupal_get_path('module', 'simpletest') .'/';
-  require_once($path .'drupal_test_case.php');
-  require_once($path .'drupal_unit_tests.php');
-  return true;
+  include_once SIMPLETEST_LIBRARY_PATH .'/web_tester.php';
+  include_once SIMPLETEST_LIBRARY_PATH .'/reporter.php';
+  include_once SIMPLETEST_MODULE_PATH  .'/drupal_reporter.php';
+  include_once SIMPLETEST_MODULE_PATH  .'/drupal_test_case.php';
+  include_once SIMPLETEST_MODULE_PATH  .'/drupal_unit_tests.php';
 }
 
 /**
  * Menu callback for both running tests and listing possible tests
  */
 function simpletest_entrypoint() {
-  if (!simpletest_load()) {
-     // @TODO - Find a better way for this return.  It is currently needed to show error,
-     // and returning true leads to page not found
-    return '&nbsp;';  
-  }
-  drupal_add_js(drupal_get_path('module', 'simpletest') .'/simpletest.js', 'module');
+  simpletest_load();
+
+  drupal_add_js(SIMPLETEST_MODULE_PATH .'/simpletest.js', 'module');
   $output = drupal_get_form('simpletest_overview_form');
 
   if (simpletest_running_output()) {
@@ -250,10 +232,8 @@ function simpletest_run_tests($testlist 
  */
 function &simpletest_get_total_test($classes = NULL) {
   static $total_test;
+
   if (!$total_test) {
-    if (!simpletest_load()) {
-      return FALSE; 
-    }
     $total_test = &new DrupalUnitTests();
   }
   if (!is_null($classes)) {
