]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16483 minor fixes
authornicolasconnault <nicolasconnault>
Tue, 16 Sep 2008 16:40:15 +0000 (16:40 +0000)
committernicolasconnault <nicolasconnault>
Tue, 16 Sep 2008 16:40:15 +0000 (16:40 +0000)
admin/report/simpletest/index.php
lib/adminlib.php
lib/simpletest/portfolio_testclass.php
lib/simpletestlib.php

index bd1b080dffe6134ff6d4e0914b1b21ee6eef9223..e6a365ca88868ba57c18c06df36a4816df817b8d 100644 (file)
@@ -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);
index ba5a7450414ecf4d71f18e3fe0bc88bcfe00e5f1..56fc2ecfe9794c9f6e0f9db51c6a4c44f5c6a4d0 100644 (file)
@@ -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();
index 1b4f1d39582017dbaeebbb0ccdffd47ce22015fd..62dc5af835b841085179c9395329fbbf113cb730 100644 (file)
@@ -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;
index 9a1b6e0d14ccd3ebb7a5a7aa2d24652fff347430..4cc713d463ae78325a7292d0ab96dd089358c6df 100644 (file)
@@ -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;
     }
 
     /**