From: nicolasconnault Date: Tue, 16 Sep 2008 16:40:15 +0000 (+0000) Subject: MDL-16483 minor fixes X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=356e0010311c2ed1a2861124ae8ed6b751021288;p=moodle.git MDL-16483 minor fixes --- diff --git a/admin/report/simpletest/index.php b/admin/report/simpletest/index.php index bd1b080dff..e6a365ca88 100644 --- a/admin/report/simpletest/index.php +++ b/admin/report/simpletest/index.php @@ -29,6 +29,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); +$droptesttables = optional_param('droptesttables', false, PARAM_BOOL); global $UNITTEST; $UNITTEST = new object(); @@ -84,8 +85,10 @@ if (empty($CFG->unittest_prefix)) { exit(); } -$test_tables = $DB->get_tables($CFG->unittest_prefix); -$real_tables = $DB->get_tables(); +$real_db = clone($DB); +$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary); +$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->unittest_prefix); +$test_tables = $DB->get_tables(); // Build test tables if requested and needed if ($setuptesttables) { @@ -93,10 +96,6 @@ if ($setuptesttables) { $release = null; include("$CFG->dirroot/version.php"); // defines $version and $release - $real_db = clone($DB); - $DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary); - $DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->unittest_prefix); - // Drop all tables first if they exist $manager = $DB->get_manager(); foreach ($test_tables as $table) { @@ -104,16 +103,26 @@ if ($setuptesttables) { } upgrade_db($version, $release, true); - $DB = $real_db; +} + +if ($droptesttables) { + $manager = $DB->get_manager(); + foreach ($test_tables as $table) { + $manager->drop_table($table); + } + $test_tables = $DB->get_tables(); } if (empty($test_tables['config'])) { // TODO replace error with proper admin dialog notice_yesno(get_string('tablesnotsetup', 'simpletest'), $baseurl . '?setuptesttables=1', $baseurl); + $DB = $real_db; admin_externalpage_print_footer(); exit(); } +$DB = $real_db; + if (!is_null($path)) { // Create the group of tests. $test = new AutoGroupTest($showsearch, $thorough); diff --git a/lib/adminlib.php b/lib/adminlib.php index ba5a745041..56fc2ecfe9 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -39,6 +39,11 @@ function upgrade_db($version, $release, $unittest=false) { $autopilot = optional_param('autopilot', $unittest, PARAM_BOOL); $setuptesttables= optional_param('setuptesttables', $unittest, PARAM_BOOL); + $return_url = "$CFG->wwwroot/$CFG->admin/index.php"; + if ($unittest) { + $return_url = "$CFG->wwwroot/$CFG->admin/report/simpletest/index.php"; + } + /// Check if the main tables have been installed yet or not. if (!$tables = $DB->get_tables() ) { // No tables yet at all. $maintables = false; @@ -330,67 +335,67 @@ function upgrade_db($version, $release, $unittest=false) { /// Find and check all main modules and load them up or upgrade them if necessary /// first old *.php update and then the new upgrade.php script - upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + upgrade_activity_modules($return_url); // Return here afterwards /// Check all questiontype plugins and upgrade if necessary /// first old *.php update and then the new upgrade.php script /// It is important that this is done AFTER the quiz module has been upgraded - upgrade_plugins('qtype', 'question/type', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + upgrade_plugins('qtype', 'question/type', $return_url); // Return here afterwards /// Upgrade backup/restore system if necessary /// first old *.php update and then the new upgrade.php script require_once("$CFG->dirroot/backup/lib.php"); - upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + upgrade_backup_db($return_url); // Return here afterwards /// Upgrade blocks system if necessary /// first old *.php update and then the new upgrade.php script require_once("$CFG->dirroot/lib/blocklib.php"); - upgrade_blocks_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + upgrade_blocks_db($return_url); // Return here afterwards /// Check all blocks and load (or upgrade them if necessary) /// first old *.php update and then the new upgrade.php script - upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + upgrade_blocks_plugins($return_url); // Return here afterwards /// Check all enrolment plugins and upgrade if necessary /// first old *.php update and then the new upgrade.php script - upgrade_plugins('enrol', 'enrol', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + upgrade_plugins('enrol', 'enrol', $return_url); // Return here afterwards /// Check all auth plugins and upgrade if necessary - upgrade_plugins('auth','auth',"$CFG->wwwroot/$CFG->admin/index.php"); + upgrade_plugins('auth','auth',$return_url); /// Check all course formats and upgrade if necessary - upgrade_plugins('format','course/format',"$CFG->wwwroot/$CFG->admin/index.php"); + upgrade_plugins('format','course/format',$return_url); /// Check for local database customisations /// first old *.php update and then the new upgrade.php script require_once("$CFG->dirroot/lib/locallib.php"); - upgrade_local_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + upgrade_local_db($return_url); // Return here afterwards /// Check for changes to RPC functions require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php"); - upgrade_RPC_functions("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + upgrade_RPC_functions($return_url); // Return here afterwards /// Upgrade all plugins for gradebook - upgrade_plugins('gradeexport', 'grade/export', "$CFG->wwwroot/$CFG->admin/index.php"); - upgrade_plugins('gradeimport', 'grade/import', "$CFG->wwwroot/$CFG->admin/index.php"); - upgrade_plugins('gradereport', 'grade/report', "$CFG->wwwroot/$CFG->admin/index.php"); + upgrade_plugins('gradeexport', 'grade/export', $return_url); + upgrade_plugins('gradeimport', 'grade/import', $return_url); + upgrade_plugins('gradereport', 'grade/report', $return_url); /// Check all message output plugins and upgrade if necessary - upgrade_plugins('message','message/output',"$CFG->wwwroot/$CFG->admin/index.php"); + upgrade_plugins('message','message/output',$return_url); /// Check all admin report plugins and upgrade if necessary - upgrade_plugins('report', $CFG->admin.'/report', "$CFG->wwwroot/$CFG->admin/index.php"); + upgrade_plugins('report', $CFG->admin.'/report', $return_url); /// Check all quiz report plugins and upgrade if necessary - upgrade_plugins('quizreport', 'mod/quiz/report', "$CFG->wwwroot/$CFG->admin/index.php"); + upgrade_plugins('quizreport', 'mod/quiz/report', $return_url); /// Check all portfolio plugins and upgrade if necessary - upgrade_plugins('portfolio', 'portfolio/type', "$CFG->wwwroot/$CFG->admin/index.php"); + upgrade_plugins('portfolio', 'portfolio/type', $return_url); /// Check all progress tracker plugins and upgrade if necessary - upgrade_plugins('trackerexport', 'tracker/export', "$CFG->wwwroot/$CFG->admin/index.php"); - upgrade_plugins('trackerimport', 'tracker/import', "$CFG->wwwroot/$CFG->admin/index.php"); - upgrade_plugins('trackerreport', 'tracker/report', "$CFG->wwwroot/$CFG->admin/index.php"); + upgrade_plugins('trackerexport', 'tracker/export', $return_url); + upgrade_plugins('trackerimport', 'tracker/import', $return_url); + upgrade_plugins('trackerreport', 'tracker/report', $return_url); /// just make sure upgrade logging is properly terminated upgrade_log_finish(); diff --git a/lib/simpletest/portfolio_testclass.php b/lib/simpletest/portfolio_testclass.php index 1b4f1d3958..62dc5af835 100644 --- a/lib/simpletest/portfolio_testclass.php +++ b/lib/simpletest/portfolio_testclass.php @@ -188,35 +188,6 @@ require_once($CFG->libdir . '/portfoliolib.php'); require_once($CFG->dirroot . '/admin/generator.php'); class portfoliolib_test extends MoodleUnitTestCase { - public $tables = array(); - - function setUp() { - global $DB, $CFG; - - $this->tables = $DB->get_tables(); - - foreach ($this->tables as $key => $table) { - if ($table == 'sessions2') { - unset($this->tables[$key]); - continue; - } - - if ($max_id = $DB->get_field_sql("SELECT MAX(id) FROM {$CFG->prefix}{$table}")) { - $this->tables[$table] = $max_id; - } else { - $this->tables[$table] = 0; - } - } - } - - function tearDown() { - global $DB; - - // Truncate all data created during unit tests - foreach ($this->tables as $table => $max_pk) { - $DB->delete_records_select($table, "id > $max_pk"); - } - } function test_construct_dupe_instance() { $gotexception = false; diff --git a/lib/simpletestlib.php b/lib/simpletestlib.php index 9a1b6e0d14..4cc713d463 100644 --- a/lib/simpletestlib.php +++ b/lib/simpletestlib.php @@ -150,25 +150,58 @@ class CheckSpecifiedFieldsExpectation extends SimpleExpectation { } class MoodleUnitTestCase extends UnitTestCase { + public $real_db; + public $tables = array(); + public function __construct($label = false) { parent::UnitTestCase($label); + + } + + public function setUp() { global $CFG, $DB; + parent::setUp(); + + $this->real_db = $DB; if (empty($CFG->unittest_prefix)) { print_error("prefixnotset", 'simpletest'); } - if (!$DB->table_exists('user')) { + $DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary); + $DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->unittest_prefix); + $manager = $DB->get_manager(); + + if (!$manager->table_exists('user')) { print_error('tablesnotsetup', 'simpletest'); } - } - public function setUp() { - parent::setUp(); + $this->tables = $DB->get_tables(); + + foreach ($this->tables as $key => $table) { + if ($table == 'sessions2') { + unset($this->tables[$key]); + continue; + } + + if ($max_id = $DB->get_field_sql("SELECT MAX(id) FROM {$CFG->prefix}{$table}")) { + $this->tables[$table] = $max_id; + } else { + $this->tables[$table] = 0; + } + } } public function tearDown() { + global $DB; parent::tearDown(); + + // Truncate all data created during unit tests + foreach ($this->tables as $table => $max_pk) { + $DB->delete_records_select($table, "id > $max_pk"); + } + + $DB = $this->real_db; } /**