Index: simpletest.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/simpletest.install,v
retrieving revision 1.4.2.3.2.12
diff -u -r1.4.2.3.2.12 simpletest.install
--- simpletest.install	23 Sep 2008 04:53:40 -0000	1.4.2.3.2.12
+++ simpletest.install	22 Nov 2008 21:07:46 -0000
@@ -97,6 +97,19 @@
   variable_del('simpletest_httpauth_pass');
   variable_del('simpletest_devel');
   drupal_uninstall_schema('simpletest');
+
+  // Remove binary and text test files.
+  $path = file_directory_path() .'/simpletest';
+  if ($dir = @opendir($path)) {
+    while (($file = readdir($dir)) !== FALSE) {
+      if ($file != '.' && $file != '..') {
+        unlink("$path/$file");
+      }
+    }
+    closedir($dir);
+    rmdir($path);
+  }
+
 }
 
 /**
@@ -140,10 +153,11 @@
       'title' => $t('SimpleTest code addition'),
       'value' => t('Not-found'),
       'severity' => REQUIREMENT_ERROR,
-      'description' => $t('SimpleTest could not be installed. Must add code to the %settings file please see
-                           <a href="@install">INSTALL.txt</a>.',
-                           array('%settings' => realpath(conf_path() . '/settings.php'),
-                                 '@install' => url(drupal_get_path('module', 'simpletest') . '/INSTALL.txt')))
+      'description' => $t('SimpleTest could not be installed. Must add code to the %settings file please see <a href="@install">INSTALL.txt</a>.', array(
+          '%settings' => realpath(conf_path() . '/settings.php'),
+          '@install' => url(drupal_get_path('module', 'simpletest') . '/INSTALL.txt')
+        )
+      )
     );
   }
 
@@ -223,8 +237,7 @@
       'test_id'  => array(
         'type' => 'serial',
         'not null' => TRUE,
-        'description' => t('Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
-                            are run a new test ID is used.'),
+        'description' => t('Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests are run a new test ID is used.'),
       ),
     ),
     'primary key' => array('test_id'),
@@ -233,30 +246,134 @@
 }
 
 /**
- * Correct column name.
+ * Upgrade simpletest 5.x-1.x and 6.x-1.x to 6.x-2.1 release.
+ * 
+ * Note: This does not fix the update_7000 bug introduced in 6.x-2.1 release.
  */
 function simpletest_update_6000() {
   $ret = array();
   $schema = array();
 
+  // Check for files 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.
+    $files = file_scan_directory($path, '(html|image|javascript|php|sql)-.*');
+    if (count($files) == 0) {
+      $original = drupal_get_path('module', 'simpletest') . '/files';
+      $files = file_scan_directory($original, '(html|image|javascript|php|sql)-.*');
+      foreach ($files as $file) {
+        file_copy($file->filename, $path . '/' . $file->basename);
+      }
+      $generated = TRUE;
+    }
+
+    if ($generated) {
+      $ret[] = array('success' => TRUE, 'query' => 'Extra test files generated.');
+    }
+  }
+
+  // Install 6.x-2.1 schema.
+  $schema['simpletest'] = array(
+    'description' => t('Stores simpletest messages'),
+    'fields' => array(
+      'message_id'  => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+        'description' => t('Primary Key: Unique simpletest message ID.'),
+      ),
+      'test_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('Test ID, messages belonging to the same ID are reported together'),
+      ),
+      'test_class' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('The name of the class that created this message.'),
+      ),
+      'status' => array(
+        'type' => 'varchar',
+        'length' => 9,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('Message status. Core understands pass, fail, exception.'),
+      ),
+      'message' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('The message itself.'),
+      ),
+      'message_group' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('The message group this message belongs to. For example: warning, browser, user.'),
+      ),
+      'caller' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('Name of the caller function or method that created this message.'),
+      ),
+      'line' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('Line number on which the function is called.'),
+      ),
+      'file' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('Name of the file where the function is called.'),
+      ),
+    ),
+    'primary key' => array('message_id'),
+    'indexes' => array(
+      'reporter' => array('test_class', 'message_id'),
+    ),
+  );
   $schema['simpletest_test_id'] = array(
     'description' => t('Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.'),
     'fields' => array(
       'test_id'  => array(
         'type' => 'serial',
         'not null' => TRUE,
-        'description' => t('Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
-                            are run a new test ID is used.')
+        'description' => t('Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests are run a new test ID is used.')
       )
     ),
     'primary key' => array('test_id')
   );
 
-  // Clear test results to prevent conflict.
-  db_query('DELETE FROM {simpletest}');
-
-  // Replace old table with new to make sure primary keys and such are fixed.
-  db_drop_table($ret, 'simpletest_test_id');
+  // Install non-existent tables.
+  db_create_table($ret, 'simpletest', $schema['simpletest']);
   db_create_table($ret, 'simpletest_test_id', $schema['simpletest_test_id']);
 
   return $ret;
@@ -300,7 +417,6 @@
   // Clear test results to prevent odd results.
   db_query('DELETE FROM {simpletest}');
 
-
   db_drop_field($ret, 'simpletest', 'caller');
   db_add_field($ret, 'simpletest', 'function', $schema);
 
