? patches
Index: BACKPORT.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/Attic/BACKPORT.txt,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 BACKPORT.txt
--- BACKPORT.txt	14 Sep 2009 23:03:27 -0000	1.1.2.7
+++ BACKPORT.txt	1 Dec 2010 05:35:24 -0000
@@ -30,7 +30,7 @@ SimpleTest module (simpletest.module)
   * _simpletest_batch_finished()
   * simpletest_clean_database
     - Added simpletest_get_like_tables()
-  * simpletest_clean_temporary_directory()
+  * simpletest_file_unmanaged_delete_recursive()
   * simpletest_test_form()
   * _drupal_decode_exception()
   * Added hook_form_system_modules_alter()
Index: drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/Attic/drupal_web_test_case.php,v
retrieving revision 1.2.2.3.2.57
diff -u -p -r1.2.2.3.2.57 drupal_web_test_case.php
--- drupal_web_test_case.php	1 Dec 2010 04:59:54 -0000	1.2.2.3.2.57
+++ drupal_web_test_case.php	1 Dec 2010 05:35:25 -0000
@@ -1268,7 +1268,7 @@ class DrupalWebTestCase extends DrupalTe
     if (preg_match('/simpletest\d+/', $db_prefix)) {
       // Delete temporary files directory.
 //      file_unmanaged_delete_recursive(file_directory_path());
-      simpletest_clean_temporary_directory(file_directory_path());
+      simpletest_file_unmanaged_delete_recursive(file_directory_path());
 
       // Remove all prefixed tables (all the tables in the schema).
       $schema = drupal_get_schema(NULL, TRUE);
Index: simpletest.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/Attic/simpletest.install,v
retrieving revision 1.4.2.3.2.25
diff -u -p -r1.4.2.3.2.25 simpletest.install
--- simpletest.install	13 Nov 2010 01:03:47 -0000	1.4.2.3.2.25
+++ simpletest.install	1 Dec 2010 05:35:25 -0000
@@ -7,130 +7,6 @@
  */
 
 /**
- * Implements hook_install().
- */
-function simpletest_install() {
-  // Install schema.
-  drupal_install_schema('simpletest');
-
-  // Check for files directory.
-//  $path = 'public://simpletest';
-//  if (file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
-  $path = file_directory_path() . '/simpletest';
-  if (file_check_directory($path, FILE_CREATE_DIRECTORY)) {
-    // Generate binary and text test files.
-    $generated = FALSE;
-    if (simpletest_get_file_count($path, 'binary') == 0) {
-      $lines = array(64, 1024);
-      foreach ($lines as $line) {
-        simpletest_generate_file('binary', 64, $line, 'binary');
-      }
-      $generated = TRUE;
-    }
-
-    if (simpletest_get_file_count($path, 'text') == 0) {
-      $lines = array(16, 256, 1024, 2048, 20480);
-      foreach ($lines as $line) {
-        simpletest_generate_file('text', 64, $line);
-      }
-      $generated = TRUE;
-    }
-
-    // Copy other test files for consistency.
-    $original = drupal_get_path('module', 'simpletest') . '/files';
-//    $files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/');
-    $files = file_scan_directory($original, '(html|image|javascript|php|sql)-.*');
-
-    // If there are more files in SimpleTest's files directory than the site's
-    // files directory, restore all the files. This situation might occur when
-    // an errant test deletes one or more files from the site's files
-    // directory. It serves a convenience to developers so that they can get
-    // the test files back easily.
-//    if (count($files) > count(file_scan_directory($path, '/(html|image|javascript|php|sql)-.*/'))) {
-    if (count($files) > count(file_scan_directory($path, '(html|image|javascript|php|sql)-.*'))) {
-      foreach ($files as $file) {
-//        file_unmanaged_copy($file->uri, $path, FILE_EXISTS_REPLACE);
-        copy($file->filename, $path . '/' . $file->basename);
-      }
-      $generated = TRUE;
-    }
-
-    if ($generated) {
-      drupal_set_message('Extra test files generated/copied.');
-    }
-  }
-}
-
-/**
- * Generate test file.
- */
-function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {
-  $size = $width * $lines - $lines;
-
-  // Generate random text
-  $text = '';
-  for ($i = 0; $i < $size; $i++) {
-    switch ($type) {
-      case 'text':
-        $text .= chr(rand(32, 126));
-        break;
-      case 'binary':
-        $text .= chr(rand(0, 31));
-        break;
-      case 'binary-text':
-      default:
-        $text .= rand(0, 1);
-        break;
-    }
-  }
-  $text = wordwrap($text, $width - 1, "\n", TRUE) . "\n"; // Add \n for symetrical file.
-
-  // Create filename.
-  $path = file_directory_path() . '/simpletest/';
-  $count = simpletest_get_file_count($path, $filename);
-  file_put_contents($path . $filename . '-' . ($count + 1) . '.txt', $text);
-}
-
-/**
- * Get the number of files that have the specified filename base.
- */
-function simpletest_get_file_count($directory, $filename) {
-  $files = scandir($directory);
-  $count = 0;
-  foreach ($files as $file) {
-    if (preg_match('/' . $filename . '.*?/', $file)) {
-      $count++;
-    }
-  }
-  return $count;
-}
-
-/**
- * Implements hook_uninstall().
- */
-function simpletest_uninstall() {
-  simpletest_clean_environment();
-
-  // Remove settings variables.
-  variable_del('simpletest_httpauth_method');
-  variable_del('simpletest_httpauth_username');
-  variable_del('simpletest_httpauth_password');
-  variable_del('simpletest_clear_results');
-  variable_del('simpletest_verbose');
-
-  // Uninstall schema.
-  drupal_uninstall_schema('simpletest');
-
-  // Remove generated files.
-  $path = file_directory_path() . '/simpletest';
-  $files = file_scan_directory($path, '.*');
-  foreach ($files as $file) {
-    unlink($file->filename);
-  }
-  rmdir($path);
-}
-
-/**
  * Implements hook_requirements().
  *
  * Check that the cURL extension exists for PHP.
@@ -290,6 +166,40 @@ function simpletest_schema() {
 }
 
 /**
+ * Implements hook_install().
+ */
+function simpletest_install() {
+  // Install schema.
+  drupal_install_schema('simpletest');
+
+  // Create the SimpleTest directory.
+  $path = file_directory_path() . '/simpletest';
+  file_check_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
+
+  simpletest_install_generate_files();
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function simpletest_uninstall() {
+  simpletest_clean_environment();
+
+  // Remove settings variables.
+  variable_del('simpletest_httpauth_method');
+  variable_del('simpletest_httpauth_username');
+  variable_del('simpletest_httpauth_password');
+  variable_del('simpletest_clear_results');
+  variable_del('simpletest_verbose');
+
+  // Uninstall schema.
+  drupal_uninstall_schema('simpletest');
+
+  // Remove generated files.
+  simpletest_file_unmanaged_delete_recursive(file_directory_path() . '/simpletest');
+}
+
+/**
  * Upgrade simpletest 5.x-1.x and 6.x-1.x to 6.x-2.1 release.
  *
  * Provides a basic upgrade path for initial switch to 2.x branch. The update
@@ -326,3 +236,89 @@ function simpletest_update_6201() {
   variable_del('simpletest_password', '');
   return array();
 }
+
+function simpletest_install_generate_files() {
+  $path = file_directory_path() . '/simpletest';
+
+  // Generate binary and text test files.
+  $generated = FALSE;
+  if (simpletest_get_file_count($path, 'binary') == 0) {
+    $lines = array(64, 1024);
+    foreach ($lines as $line) {
+      simpletest_generate_file('binary', 64, $line, 'binary');
+    }
+    $generated = TRUE;
+  }
+
+  if (simpletest_get_file_count($path, 'text') == 0) {
+   $lines = array(16, 256, 1024, 2048, 20480);
+   foreach ($lines as $line) {
+     simpletest_generate_file('text', 64, $line);
+   }
+   $generated = TRUE;
+  }
+
+  // Copy other test files for consistency.
+  $original = drupal_get_path('module', 'simpletest') . '/files';
+  $files = file_scan_directory($original, '(html|image|javascript|php|sql)-.*');
+
+  // If there are more files in SimpleTest's files directory than the site's
+  // files directory, restore all the files. This situation might occur when
+  // an errant test deletes one or more files from the site's files
+  // directory. It serves a convenience to developers so that they can get
+  // the test files back easily.
+  if (count($files) > count(file_scan_directory($path, '(html|image|javascript|php|sql)-.*'))) {
+    foreach ($files as $file) {
+      copy($file->filename, $path . '/' . $file->basename);
+    }
+    $generated = TRUE;
+  }
+
+  if ($generated) {
+    drupal_set_message('Extra test files generated/copied.');
+  }
+}
+
+/**
+ * Generate test file.
+ */
+function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {
+  $size = $width * $lines - $lines;
+
+  // Generate random text
+  $text = '';
+  for ($i = 0; $i < $size; $i++) {
+    switch ($type) {
+      case 'text':
+        $text .= chr(rand(32, 126));
+        break;
+      case 'binary':
+        $text .= chr(rand(0, 31));
+        break;
+      case 'binary-text':
+      default:
+        $text .= rand(0, 1);
+        break;
+    }
+  }
+  $text = wordwrap($text, $width - 1, "\n", TRUE) . "\n"; // Add \n for symetrical file.
+
+  // Create filename.
+  $path = file_directory_path() . '/simpletest/';
+  $count = simpletest_get_file_count($path, $filename);
+  file_put_contents($path . $filename . '-' . ($count + 1) . '.txt', $text);
+}
+
+/**
+ * Get the number of files that have the specified filename base.
+ */
+function simpletest_get_file_count($directory, $filename) {
+  $files = scandir($directory);
+  $count = 0;
+  foreach ($files as $file) {
+    if (preg_match('/' . $filename . '.*?/', $file)) {
+      $count++;
+    }
+  }
+  return $count;
+}
Index: simpletest.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/Attic/simpletest.module,v
retrieving revision 1.33.2.4.2.27
diff -u -p -r1.33.2.4.2.27 simpletest.module
--- simpletest.module	1 Dec 2010 04:35:44 -0000	1.33.2.4.2.27
+++ simpletest.module	1 Dec 2010 05:35:25 -0000
@@ -117,7 +117,7 @@ function simpletest_run_tests($test_list
   $test_id = db_last_insert_id('simpletest_test_id', 'test_id');
 
   // Clear out the previous verbose files.
-  simpletest_clean_temporary_directory(file_directory_path() . '/simpletest/verbose');
+  simpletest_file_unmanaged_delete_recursive(file_directory_path() . '/simpletest/verbose');
 
   // Get the info for the first test being run.
   $first_test = array_shift($test_list);
@@ -172,8 +172,8 @@ function _simpletest_batch_operation($te
 
   require_once drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php';
   $classes = simpletest_test_get_all_classes();
-  if (!empty($classes[$test_class]['file'])) {
-    require_once $classes[$test_class]['file'];
+  if (!empty($classes[$test_class]->file)) {
+    require_once $classes[$test_class]->file;
   }
 
   $test = new $test_class($test_id);
@@ -261,10 +261,10 @@ function simpletest_last_test_get($test_
  *   Found any entries in log.
  */
 function simpletest_log_read($test_id, $prefix, $test_class, $during_test = FALSE) {
-  require_once drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php';
   $log = file_directory_path() . ($during_test ? '' : '/simpletest/' . substr($prefix, 10)) . '/error.log';
   $found = FALSE;
   if (file_exists($log)) {
+    require_once drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php';
     foreach (file($log) as $line) {
       if (preg_match('/\[.*?\] (.*?): (.*?) in (.*) on line (\d+)/', $line, $match)) {
         // Parse PHP fatal errors for example: PHP Fatal error: Call to
@@ -320,14 +320,12 @@ function simpletest_test_get_all() {
     }
     else {
       // Select all clases in files ending with .test.
-      $classes = simpletest_test_get_all_classes();
-
+      $classes = array_keys(simpletest_test_get_all_classes());
 
       // Check that each class has a getInfo() method and store the information
       // in an array keyed with the group specified in the test information.
       $groups = array();
       foreach ($classes as $class) {
-        $class = $class['class'];
         // Test classes need to implement getInfo() to be valid.
         if (class_exists($class) && method_exists($class, 'getInfo')) {
           $info = call_user_func(array($class, 'getInfo'));
@@ -359,33 +357,6 @@ function simpletest_test_get_all() {
   return $groups;
 }
 
-function simpletest_test_get_all_classes() {
-  // Must load DrupalWebTestCase before loading any other test classes which
-  // will extend it.
-  require_once 'drupal_web_test_case.php';
-
-  $classes = array();
-  $files = module_rebuild_cache();
-  foreach ($files as $file) {
-    $directory = dirname($file->filename);
-    $test_files = file_scan_directory($directory, '\.test$', array('.', '..', 'CVS'), FALSE, FALSE);
-    $test_files += file_scan_directory($directory . '/tests', '\.test$');
-
-    foreach ($test_files as $test_file) {
-      $pre = get_declared_classes();
-      require_once $test_file->filename;
-      $post = get_declared_classes();
-
-      $classes_new = array_values(array_diff($post, $pre));
-      foreach ($classes_new as $class) {
-        $classes[$class] = array('file' => $test_file->filename, 'class' => $class);
-      }
-    }
-  }
-
-  return $classes;
-}
-
 /**
  * Remove all temporary database tables and directories.
  */
@@ -408,10 +379,10 @@ function simpletest_clean_environment() 
  * Removed prefixed tables from the database that are left over from crashed tests.
  */
 function simpletest_clean_database() {
-//  $tables = db_find_tables(Database::getConnection()->prefixTables('{simpletest}') . '%');
-  $tables = simpletest_get_like_tables();
+  $tables = simpletest_db_find_tables(db_prefix_tables('{simpletest}') . '%%');
   $schema = drupal_get_schema_unprocessed('simpletest');
   $count = 0;
+  $ret = array();
   foreach (array_diff_key($tables, $schema) as $table) {
     // Strip the prefix and skip tables without digits following "simpletest",
     // e.g. {simpletest_test_id}.
@@ -430,29 +401,6 @@ function simpletest_clean_database() {
 }
 
 /**
- * Find all tables that are like the specified base table name. (Drupal 6)
- *
- * @param string $base_table Base table name.
- * @param boolean $count Return the table count instead of list of tables.
- * @return mixed Array of matching tables or count of tables.
- */
-function simpletest_get_like_tables($base_table = 'simpletest', $count = FALSE) {
-  global $db_url, $db_prefix;
-  $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
-  $database = substr($url['path'], 1);
-  $result = db_query("SELECT table_name FROM information_schema.tables WHERE (table_schema = '$database' OR table_catalog = '$database') AND table_name LIKE '$db_prefix$base_table%'");
-  $schema = drupal_get_schema_unprocessed('simpletest');
-
-  $tables = array();
-  while ($table = db_result($result)) {
-    if (!isset($schema[$table])) {
-      $tables[] = $table;
-    }
-  }
-  return ($count) ? count($tables) : $tables;
-}
-
-/**
  * Find all leftover temporary directories and remove them.
  */
 function simpletest_clean_temporary_directories() {
@@ -461,7 +409,7 @@ function simpletest_clean_temporary_dire
   foreach ($files as $file) {
     $path = file_directory_path() . '/' . $file;
     if (is_dir($path) && preg_match('/^simpletest\d+/', $file)) {
-      simpletest_clean_temporary_directory($path);
+      simpletest_file_unmanaged_delete_recursive($path);
       $count++;
     }
   }
@@ -475,33 +423,6 @@ function simpletest_clean_temporary_dire
 }
 
 /**
- * Remove all files from specified directory and then remove directory. (Drupal 6)
- *
- * @param string $path Directory path.
- */
-function simpletest_clean_temporary_directory($path) {
-  // Drupal 6.
-  if (!is_dir($path)) {
-    return;
-  }
-
-  $files = scandir($path);
-  foreach ($files as $file) {
-    if ($file != '.' && $file != '..') {
-      $file_path = "$path/$file";
-      if (is_dir($file_path)) {
-        simpletest_clean_temporary_directory($file_path);
-      }
-      else {
-//        file_unmanaged_delete($file_path);
-        unlink($file_path);
-      }
-    }
-  }
-  rmdir($path);
-}
-
-/**
  * Clear the test result tables.
  *
  * @param $test_id
@@ -529,3 +450,105 @@ function simpletest_clean_results_table(
   }
   return 0;
 }
+
+function simpletest_test_get_all_classes() {
+  // Must load DrupalWebTestCase before loading any other test classes which
+  // will extend it.
+  require_once drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php';
+
+  $classes = array();
+  $files = module_rebuild_cache();
+  foreach ($files as $file) {
+    $directory = dirname($file->filename);
+    $test_files = file_scan_directory($directory, '\.test$', array('.', '..', 'CVS'), FALSE, FALSE);
+    $test_files += file_scan_directory($directory . '/tests', '\.test$');
+
+    foreach ($test_files as $test_file) {
+      $pre = get_declared_classes();
+      require_once $test_file->filename;
+      $post = get_declared_classes();
+
+      $classes_new = array_values(array_diff($post, $pre));
+      foreach ($classes_new as $class) {
+        $classes[$class] = (object) array('file' => $test_file->filename, 'class' => $class);
+      }
+    }
+  }
+
+  return $classes;
+}
+
+/**
+ * Finds all tables that are like the specified base table name.
+ *
+ * @param $table_expression
+ *   An SQL expression, for example "simpletest%%" (without the quotes).
+ *   BEWARE: this is not prefixed, the caller should take care of that.
+ *
+ * @return
+ *   Array, both the keys and the values are the matching tables.
+ */
+function simpletest_db_find_tables($table_expression) {
+  global $db_url;
+
+  // Get the database name.
+  $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
+  $database = substr($url['path'], 1);
+
+  switch ($GLOBALS['db_type']) {
+    default:
+      $query = db_query("SELECT table_name FROM information_schema.tables WHERE (table_schema = '%s' OR table_catalog = '%s') AND table_name LIKE '%s'", array(
+        ':table_schema' => $database,
+        ':table_catalog' => $database,
+        ':table_name' => $table_expression,
+      ));
+      break;
+  }
+
+  $tables = array();
+  if (isset($query)) {
+    while ($table = db_result($query)) {
+      $tables[] = $table;
+    }
+  }
+  return $tables;
+}
+
+/**
+ * Recursively delete all files and directories in the specified filepath.
+ *
+ * If the specified path is a directory then the function will call itself
+ * recursively to process the contents. Once the contents have been removed the
+ * directory will also be removed.
+ *
+ * If the specified path is a file then it will be passed to
+ * file_unmanaged_delete().
+ *
+ * Note that this only deletes visible files with write permission.
+ *
+ * @param $path
+ *   A string containing either an URI or a file or directory path.
+ *
+ * @return
+ *   TRUE for success or if path does not exist, FALSE in the event of an
+ *   error.
+ *
+ * @see file_unmanaged_delete()
+ */
+function simpletest_file_unmanaged_delete_recursive($path) {
+  if (is_dir($path)) {
+    $dir = dir($path);
+    while (($entry = $dir->read()) !== FALSE) {
+      if ($entry == '.' || $entry == '..') {
+        continue;
+      }
+      $entry_path = $path . '/' . $entry;
+      simpletest_file_unmanaged_delete_recursive($entry_path);
+    }
+    $dir->close();
+    return rmdir($path);
+  }
+  elseif (is_file($path)) {
+    return unlink($path);
+  }
+}
Index: simpletest.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/Attic/simpletest.pages.inc,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 simpletest.pages.inc
--- simpletest.pages.inc	13 Nov 2010 01:03:48 -0000	1.1.2.4
+++ simpletest.pages.inc	1 Dec 2010 05:35:25 -0000
@@ -194,8 +194,8 @@ function simpletest_test_form_submit($fo
   $tests_list = array();
   $classes = simpletest_test_get_all_classes();
   foreach ($form_state['values'] as $class_name => $value) {
-    if (isset($classes[$class_name]['file'])) {
-      require_once $classes[$class_name]['file'];
+    if (isset($classes[$class_name]->file)) {
+      require_once $classes[$class_name]->file;
     }
 
     // Since class_exists() will likely trigger an autoload lookup,
@@ -255,7 +255,7 @@ function simpletest_result_form(&$form_s
   $classes = simpletest_test_get_all_classes();
 
   foreach ($results as $group => $assertions) {
-    require_once $classes[$group]['file'];
+    require_once $classes[$group]->file;
 
     // Create group fieldset with summary information.
     $info = call_user_func(array($group, 'getInfo'));
Index: simpletest.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/Attic/simpletest.test,v
retrieving revision 1.1.2.21
diff -u -p -r1.1.2.21 simpletest.test
--- simpletest.test	13 Nov 2010 01:03:48 -0000	1.1.2.21
+++ simpletest.test	1 Dec 2010 05:35:26 -0000
@@ -421,6 +421,28 @@ class SimpleTestMailCaptureTestCase exte
 }
 
 /**
+ * Test Folder creation
+ */
+class SimpleTestFolderTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Testing SimpleTest setUp',
+      'description' => "This test will check SimpleTest's treatment of hook_install during setUp.",
+      'group' => 'SimpleTest',
+    );
+  }
+
+  function setUp() {
+    parent::setUp(array('simpletest'));
+  }
+
+  function testFolderSetup() {
+    $path = file_directory_path() . '/simpletest';
+    $this->assertTrue(file_check_directory($path, FALSE), "Directory $path created.");
+  }
+}
+
+/**
  * Test required modules for tests.
  */
 class SimpleTestMissingDependentModuleUnitTest extends DrupalUnitTestCase {
