$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);
}
// 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();
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) {
$manager->drop_table($xmldbtable);
}
$test_tables = $DB->get_tables();
+ $testtablesok = false;
}
if (empty($test_tables['config'])) {
exit();
}
+$DB->dispose();
$DB = $real_db;
$CFG = $real_cfg;
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.
$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';
$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.';
$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).';
$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
// 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;
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 {
/// 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