From: nicolasconnault Date: Mon, 22 Sep 2008 08:54:33 +0000 (+0000) Subject: MDL-16486 Implemented test DB upgrade, needs further testing X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2d5b05c8787540299cc0da958ddc57431b64648d;p=moodle.git MDL-16486 Implemented test DB upgrade, needs further testing --- diff --git a/admin/report/simpletest/index.php b/admin/report/simpletest/index.php index d989cb29bd..74bf98b915 100644 --- a/admin/report/simpletest/index.php +++ b/admin/report/simpletest/index.php @@ -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 '

'; print_checkbox('rundbtests', 1, $rundbtests, get_string('rundbtests' echo ''; echo ''; echo ''; + +if ($testtablesok) { + echo '

'; + echo '
'; + echo ''; + echo ''; + echo '
'; + echo '
'; + + echo '
'; + echo '
'; + echo ''; + echo ''; + echo '
'; + echo '
'; +} + print_box_end(); // Footer. diff --git a/lang/en_utf8/simpletest.php b/lang/en_utf8/simpletest.php index e0d2ccfbcc..675349ad17 100644 --- a/lang/en_utf8/simpletest.php +++ b/lang/en_utf8/simpletest.php @@ -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: {$a->passes} passes, {$a->fails} fails and {$a->exceptions} 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).'; diff --git a/lib/adminlib.php b/lib/adminlib.php index b04cf7e6af..297e16c081 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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&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&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&upgradetesttables=$upgradetesttables"); } // initialise default blocks on admin and site page if needed