]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16486 Implemented test DB upgrade, needs further testing
authornicolasconnault <nicolasconnault>
Mon, 22 Sep 2008 08:54:33 +0000 (08:54 +0000)
committernicolasconnault <nicolasconnault>
Mon, 22 Sep 2008 08:54:33 +0000 (08:54 +0000)
admin/report/simpletest/index.php
lang/en_utf8/simpletest.php
lib/adminlib.php

index d989cb29bd0c9b19199396fecc033b98d8406de9..74bf98b9153ff2d2bf73c31d1a2d373d1790b022 100644 (file)
@@ -30,6 +30,7 @@ $rundbtests = optional_param('rundbtests', false, PARAM_BOOL);
 $thorough = optional_param('thorough', false, PARAM_BOOL);
 $addconfigprefix = optional_param('addconfigprefix', false, PARAM_RAW);
 $setuptesttables = optional_param('setuptesttables', false, PARAM_BOOL);
+$upgradetesttables = optional_param('upgradetesttables', false, PARAM_BOOL);
 $continuesetuptesttables = optional_param('continuesetuptesttables', false, PARAM_BOOL);
 $droptesttables = optional_param('droptesttables', false, PARAM_BOOL);
 $testtablesok = optional_param('testtablesok', false, PARAM_BOOL);
@@ -93,6 +94,8 @@ if (empty($CFG->unittestprefix)) {
 }
 
 // Temporarily override $DB and $CFG for a fresh install on the unit test prefix
+$real_version = $CFG->version;
+
 $real_db = clone($DB);
 $real_cfg = clone($CFG);
 $CFG = new stdClass();
@@ -124,17 +127,28 @@ if ($DB->get_manager()->table_exists(new xmldb_table('config')) && $config = $DB
     foreach ($config as $conf) {
         $CFG->{$conf->name} = $conf->value;
     }
+    $testtablesok = true;
 }
 
 $test_tables = $DB->get_tables();
 
-// Build test tables if requested and needed
-if ($setuptesttables || $continuesetuptesttables) {
+// Test DB upgrade
+if (!$upgradetesttables && $real_version != $CFG->version) {
+    notice_yesno(get_string('testtablesneedupgrade', 'simpletest'), $baseurl . '?upgradetesttables=1', $baseurl);
+    $DB->dispose();
+    $DB = $real_db;
+    admin_externalpage_print_footer();
+    exit();
+}
+
+// Build/upgrade test tables if requested and needed
+if ($setuptesttables || $continuesetuptesttables || $upgradetesttables) {
+
     $version = null;
     $release = null;
     include("$CFG->dirroot/version.php");       // defines $version and $release
 
-    if (!$continuesetuptesttables) {
+    if (!$continuesetuptesttables && !$upgradetesttables) {
         // Drop all tables first if they exist
         $manager = $DB->get_manager();
         foreach ($test_tables as $table) {
@@ -153,6 +167,7 @@ if ($droptesttables) {
         $manager->drop_table($xmldbtable);
     }
     $test_tables = $DB->get_tables();
+    $testtablesok = false;
 }
 
 if (empty($test_tables['config'])) {
@@ -163,6 +178,7 @@ if (empty($test_tables['config'])) {
     exit();
 }
 
+$DB->dispose();
 $DB = $real_db;
 $CFG = $real_cfg;
 
@@ -246,6 +262,23 @@ echo '<p>'; print_checkbox('rundbtests', 1, $rundbtests, get_string('rundbtests'
 echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
 echo '</fieldset>';
 echo '</form>';
+
+if ($testtablesok) {
+    echo '<form method="get" action="index.php">';
+    echo '<fieldset class="invisiblefieldset">';
+    echo '<input type="hidden" name="droptesttables" value="1" />';
+    echo '<input type="submit" value="' . get_string('droptesttables', 'simpletest') . '" />';
+    echo '</fieldset>';
+    echo '</form>';
+
+    echo '<form method="get" action="index.php">';
+    echo '<fieldset class="invisiblefieldset">';
+    echo '<input type="hidden" name="setuptesttables" value="1" />';
+    echo '<input type="submit" value="' . get_string('reinstalltesttables', 'simpletest') . '" />';
+    echo '</fieldset>';
+    echo '</form>';
+}
+
 print_box_end();
 
 // Footer.
index e0d2ccfbccf3e58a3bf782c7ecbeb9f0f961b16e..675349ad17b212c40942296a921db362c2438416 100644 (file)
@@ -6,10 +6,12 @@ $string['all'] = 'ALL';
 $string['addconfigprefix'] = 'Add prefix to config file';
 $string['deletingnoninsertedrecord'] = 'Trying to delete a record that was not inserted by these unit tests (id $a->id in table $a->table).';
 $string['deletingnoninsertedrecords'] = 'Trying to delete records that were not inserted by these unit tests (from table $a->table).';
+$string['droptesttables'] = 'Drop test tables';
 $string['exception'] = 'Exception';
 $string['fail'] = 'Fail';
 $string['ignorefile'] = 'Ignore tests in the file';
 $string['ignorethisfile'] = 'Re-run the tests ignoring this test file.';
+$string['installtesttables'] = 'Install test tables';
 $string['moodleunittests'] = 'Moodle unit tests: $a';
 $string['notice'] = 'Notice';
 $string['onlytest'] = 'Only run tests in';
@@ -17,6 +19,7 @@ $string['pass'] = 'Pass';
 $string['pathdoesnotexist'] = 'The path \'$a\' does not exist.';
 $string['prefix'] = 'Unit test tables prefix';
 $string['prefixnotset'] = 'The unit test database table prefix is not configured. Fill and submit this form to add it to config.php.';
+$string['reinstalltesttables'] = 'Reinstall test tables';
 $string['retest'] = 'Re-run the tests';
 $string['retestonlythisfile'] = 'Re-run only this test file.';
 $string['runall'] = 'Run the tests from all the test files.';
@@ -31,6 +34,7 @@ $string['showsearch'] = 'Show the search for test files.';
 $string['stacktrace'] = 'Stack trace:';
 $string['summary'] = '{$a->run}/{$a->total} test cases complete: <strong>{$a->passes}</strong> passes, <strong>{$a->fails}</strong> fails and <strong>{$a->exceptions}</strong> exceptions.';
 $string['tablesnotsetup'] = 'Unit test tables are not yet built. Do you want to build them now?.';
+$string['testtablesneedupgrade'] = 'The test DB tables need to be upgraded. Do you wish to proceed with the upgrade now?';
 $string['testtablesok'] = 'The test DB tables were successfully installed.';
 $string['testtablescsvfileunwritable'] = 'The test tables CSV file is not writable ($a->filename)';
 $string['thorough'] = 'Run a thorough test (may be slow).';
index b04cf7e6afc187176444182ae49bd46c92d07160..297e16c081ae8f3034eadc37dba20f8b61aa7413 100644 (file)
@@ -36,17 +36,18 @@ function upgrade_db($version, $release) {
         $unittest = false;
     }
 
-    $confirmupgrade = optional_param('confirmupgrade', $unittest, PARAM_BOOL);
-    $confirmrelease = optional_param('confirmrelease', $unittest, PARAM_BOOL);
-    $confirmplugins = optional_param('confirmplugincheck', $unittest, PARAM_BOOL);
-    $agreelicense   = optional_param('agreelicense', $unittest, PARAM_BOOL);
-    $autopilot      = optional_param('autopilot', $unittest, PARAM_BOOL);
-    $setuptesttables= optional_param('setuptesttables', $unittest, PARAM_BOOL);
-    $continuesetuptesttables= optional_param('continuesetuptesttables', $unittest, PARAM_BOOL);
+    $confirmupgrade          = optional_param('confirmupgrade', $unittest, PARAM_BOOL);
+    $confirmrelease          = optional_param('confirmrelease', $unittest, PARAM_BOOL);
+    $confirmplugins          = optional_param('confirmplugincheck', $unittest, PARAM_BOOL);
+    $agreelicense            = optional_param('agreelicense', $unittest, PARAM_BOOL);
+    $autopilot               = optional_param('autopilot', $unittest, PARAM_BOOL);
+    $setuptesttables         = optional_param('setuptesttables', false, PARAM_BOOL);
+    $continuesetuptesttables = optional_param('continuesetuptesttables', false, PARAM_BOOL);
+    $upgradetesttables       = optional_param('upgradetesttables', false, PARAM_BOOL);
 
     $return_url = "$CFG->wwwroot/$CFG->admin/index.php";
     if ($unittest) {
-        $return_url = "$CFG->wwwroot/$CFG->admin/report/simpletest/index.php?continuesetuptesttables=".$continuesetuptesttables;
+        $return_url = "$CFG->wwwroot/$CFG->admin/report/simpletest/index.php?continuesetuptesttables=$continuesetuptesttables&amp;upgradetesttables=$upgradetesttables";
     }
 
     /// set install/upgrade autocontinue session flag
@@ -175,7 +176,7 @@ function upgrade_db($version, $release) {
         // hack - set up mnet
         require_once $CFG->dirroot.'/mnet/lib.php';
 
-        print_continue('index.php?continuesetuptesttables='.$setuptesttables);
+        print_continue("index.php?continuesetuptesttables=$setuptesttables&amp;upgradetesttables=$upgradetesttables");
         print_footer('none');
 
         die;
@@ -319,7 +320,12 @@ function upgrade_db($version, $release) {
                 if (set_config("version", $version)) {
                     remove_dir($CFG->dataroot . '/cache', true); // flush cache
                     notify($strdatabasesuccess, "green");
-                    print_continue("upgradesettings.php");
+
+                    if ($unittest) {
+                        print_continue("index.php?testtablesok=1");
+                    } else {
+                        print_continue("upgradesettings.php");
+                    }
                     print_footer('none');
                     exit;
                 } else {
@@ -428,7 +434,7 @@ function upgrade_db($version, $release) {
     /// Set up the blank site - to be customized later at the end of install.
         if (! $site = get_site()) {
             build_site_course();
-            redirect('index.php?continuesetuptesttables='.$continuesetuptesttables);
+            redirect("index.php?continuesetuptesttables=$continuesetuptesttables&amp;upgradetesttables=$upgradetesttables");
         }
 
         // initialise default blocks on admin and site page if needed