mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 08:09:47 +02:00
MDL-16486 Implemented test DB upgrade, needs further testing
This commit is contained in:
parent
274e2947a2
commit
2d5b05c878
3 changed files with 57 additions and 14 deletions
|
@ -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.
|
||||
|
|
|
@ -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).';
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue