mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-16483 $CFG->unittestprefix not required anymore to run unit tests that do not need fake db; it should be saer to let admins modify the prefix in config.php instead of modifying it from php
This commit is contained in:
parent
efd8c7fc6b
commit
84ebf08dcc
5 changed files with 163 additions and 153 deletions
|
@ -16,23 +16,21 @@ require_once($CFG->libdir.'/simpletestlib.php');
|
||||||
require_once('ex_simple_test.php');
|
require_once('ex_simple_test.php');
|
||||||
require_once('ex_reporter.php');
|
require_once('ex_reporter.php');
|
||||||
|
|
||||||
// CGI arguments
|
// page parameters
|
||||||
$path = optional_param('path', null, PARAM_PATH);
|
$path = optional_param('path', null, PARAM_PATH);
|
||||||
$showpasses = optional_param('showpasses', false, PARAM_BOOL);
|
$showpasses = optional_param('showpasses', false, PARAM_BOOL);
|
||||||
$showsearch = optional_param('showsearch', false, PARAM_BOOL);
|
$showsearch = optional_param('showsearch', false, PARAM_BOOL);
|
||||||
$addconfigprefix = optional_param('addconfigprefix', false, PARAM_RAW);
|
$setuptesttables = optional_param('setuptesttables', false, PARAM_BOOL);
|
||||||
$setuptesttables = optional_param('setuptesttables', false, PARAM_BOOL);
|
$upgradetesttables = optional_param('upgradetesttables', false, PARAM_BOOL);
|
||||||
$upgradetesttables = optional_param('upgradetesttables', false, PARAM_BOOL);
|
|
||||||
$continuesetuptesttables = optional_param('continuesetuptesttables', false, PARAM_BOOL);
|
$continuesetuptesttables = optional_param('continuesetuptesttables', false, PARAM_BOOL);
|
||||||
$droptesttables = optional_param('droptesttables', false, PARAM_BOOL);
|
$droptesttables = optional_param('droptesttables', false, PARAM_BOOL);
|
||||||
$testtablesok = optional_param('testtablesok', false, PARAM_BOOL);
|
$testtablesok = optional_param('testtablesok', false, PARAM_BOOL);
|
||||||
|
|
||||||
if ($setuptesttables || $continuesetuptesttables || $upgradetesttables) {
|
if ($setuptesttables || $continuesetuptesttables || $upgradetesttables) {
|
||||||
// Make sure this option is off during upgrade. It is not very helpful, and can break things.
|
// Make sure this option is off during upgrade. It is not very helpful, and can break things.
|
||||||
$CFG->xmlstrictheaders = false;
|
$CFG->xmlstrictheaders = false;
|
||||||
}
|
}
|
||||||
admin_externalpage_setup('reportsimpletest', '', array('showpasses' => $showpasses,
|
admin_externalpage_setup('reportsimpletest', '', array('showpasses'=>$showpasses, 'showsearch'=>$showsearch));
|
||||||
'showsearch' => $showsearch));
|
|
||||||
admin_externalpage_print_header();
|
admin_externalpage_print_header();
|
||||||
|
|
||||||
$langfile = 'simpletest';
|
$langfile = 'simpletest';
|
||||||
|
@ -48,149 +46,97 @@ if ($testtablesok) {
|
||||||
print_heading(get_string('testtablesok', 'simpletest'));
|
print_heading(get_string('testtablesok', 'simpletest'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$baseurl = "$CFG->wwwroot/$CFG->admin/report/unittest/index.php";
|
if (!empty($CFG->unittestprefix)) {
|
||||||
|
// Temporarily override $DB and $CFG for a fresh install on the unit test prefix
|
||||||
|
$real_version = $CFG->version;
|
||||||
|
|
||||||
// Add unittest prefix to config.php if needed
|
$real_db = $DB;
|
||||||
if ($addconfigprefix && !isset($CFG->unittestprefix)) {
|
$real_cfg = $CFG;
|
||||||
// Open config file, search for $CFG->prefix and append a new line under it
|
$CFG = new stdClass();
|
||||||
if ($handle = @fopen($CFG->dirroot.'/config.php', 'r+')) {
|
$CFG->dbhost = $real_cfg->dbhost;
|
||||||
|
$CFG->dbtype = $real_cfg->dbtype;
|
||||||
|
$CFG->dblibrary = $real_cfg->dblibrary;
|
||||||
|
$CFG->dbuser = $real_cfg->dbuser;
|
||||||
|
$CFG->dbpass = $real_cfg->dbpass;
|
||||||
|
$CFG->dbname = $real_cfg->dbname;
|
||||||
|
$CFG->unittestprefix = $real_cfg->unittestprefix;
|
||||||
|
$CFG->wwwroot = $real_cfg->wwwroot;
|
||||||
|
$CFG->dirroot = $real_cfg->dirroot;
|
||||||
|
$CFG->libdir = $real_cfg->libdir;
|
||||||
|
$CFG->dataroot = $real_cfg->dataroot;
|
||||||
|
$CFG->admin = $real_cfg->admin;
|
||||||
|
$CFG->release = $real_cfg->release;
|
||||||
|
$CFG->version = $real_cfg->version;
|
||||||
|
$CFG->config_php_settings = $real_cfg->config_php_settings;
|
||||||
|
$CFG->frametarget = $real_cfg->frametarget;
|
||||||
|
$CFG->framename = $real_cfg->framename;
|
||||||
|
$CFG->footer = $real_cfg->footer;
|
||||||
|
$CFG->debug = $real_cfg->debug;
|
||||||
|
|
||||||
$new_file = '';
|
$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
|
||||||
|
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->unittestprefix);
|
||||||
|
|
||||||
while (!feof($handle)) {
|
if ($DB->get_manager()->table_exists(new xmldb_table('config')) && $config = $DB->get_records('config')) {
|
||||||
$line = fgets($handle, 4096);
|
foreach ($config as $conf) {
|
||||||
$prefix_line = null;
|
$CFG->{$conf->name} = $conf->value;
|
||||||
|
}
|
||||||
|
$testtablesok = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (preg_match('/CFG\-\>prefix/', $line, $matches)) {
|
$test_tables = $DB->get_tables();
|
||||||
$prefix_line = "\$CFG->unittestprefix = '$addconfigprefix';\n";
|
|
||||||
|
// Test DB upgrade
|
||||||
|
if (!$upgradetesttables && $real_version != $CFG->version) {
|
||||||
|
notice_yesno(get_string('testtablesneedupgrade', 'simpletest'), $FULLSCRIPT . '?upgradetesttables=1', $FULLSCRIPT);
|
||||||
|
$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 && !$upgradetesttables) {
|
||||||
|
// Drop all tables first if they exist
|
||||||
|
$manager = $DB->get_manager();
|
||||||
|
foreach ($test_tables as $table) {
|
||||||
|
$xmldbtable = new xmldb_table($table);
|
||||||
|
$manager->drop_table($xmldbtable);
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_file .= $line;
|
|
||||||
$new_file .= $prefix_line;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($handle);
|
upgrade_db($version, $release, true);
|
||||||
$handle = fopen($CFG->dirroot.'/config.php', 'w');
|
|
||||||
fwrite($handle, $new_file);
|
|
||||||
fclose($handle);
|
|
||||||
$CFG->unittestprefix = $addconfigprefix;
|
|
||||||
} else {
|
|
||||||
notify(get_string('confignonwritable', 'simpletest'));
|
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($CFG->unittestprefix)) {
|
if ($droptesttables) {
|
||||||
// TODO replace error with proper admin dialog
|
|
||||||
|
|
||||||
print_box_start('generalbox', 'notice');
|
|
||||||
if (is_writable($CFG->dirroot.'/config.php')) {
|
|
||||||
echo '<p>'.get_string("prefixnotset", 'simpletest').'</p>';
|
|
||||||
echo '<form method="post" action="'.$baseurl.'">
|
|
||||||
<table class="generaltable">
|
|
||||||
<tr>
|
|
||||||
<th class="header"><label for="prefix">'.get_string('prefix', 'simpletest').'</label></th>
|
|
||||||
<td class="cell"><input type="text" size="5" name="addconfigprefix" id="prefix" value="tst_" /></td>
|
|
||||||
<td class="cell"><input type="submit" value="'.get_string('addconfigprefix', 'simpletest').'" /></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</form>';
|
|
||||||
} else {
|
|
||||||
notify(get_string('confignonwritable', 'simpletest'));
|
|
||||||
}
|
|
||||||
print_box_end();
|
|
||||||
|
|
||||||
admin_externalpage_print_footer();
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
$CFG->dbhost = $real_cfg->dbhost;
|
|
||||||
$CFG->dbtype = $real_cfg->dbtype;
|
|
||||||
$CFG->dblibrary = $real_cfg->dblibrary;
|
|
||||||
$CFG->dbuser = $real_cfg->dbuser;
|
|
||||||
$CFG->dbpass = $real_cfg->dbpass;
|
|
||||||
$CFG->dbname = $real_cfg->dbname;
|
|
||||||
$CFG->unittestprefix = $real_cfg->unittestprefix;
|
|
||||||
$CFG->wwwroot = $real_cfg->wwwroot;
|
|
||||||
$CFG->dirroot = $real_cfg->dirroot;
|
|
||||||
$CFG->libdir = $real_cfg->libdir;
|
|
||||||
$CFG->dataroot = $real_cfg->dataroot;
|
|
||||||
$CFG->admin = $real_cfg->admin;
|
|
||||||
$CFG->release = $real_cfg->release;
|
|
||||||
$CFG->version = $real_cfg->version;
|
|
||||||
$CFG->config_php_settings = $real_cfg->config_php_settings;
|
|
||||||
$CFG->frametarget = $real_cfg->frametarget;
|
|
||||||
$CFG->framename = $real_cfg->framename;
|
|
||||||
$CFG->footer = $real_cfg->footer;
|
|
||||||
$CFG->debug = $real_cfg->debug;
|
|
||||||
|
|
||||||
$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
|
|
||||||
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->unittestprefix);
|
|
||||||
|
|
||||||
if ($DB->get_manager()->table_exists(new xmldb_table('config')) && $config = $DB->get_records('config')) {
|
|
||||||
foreach ($config as $conf) {
|
|
||||||
$CFG->{$conf->name} = $conf->value;
|
|
||||||
}
|
|
||||||
$testtablesok = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$test_tables = $DB->get_tables();
|
|
||||||
|
|
||||||
// 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 && !$upgradetesttables) {
|
|
||||||
// Drop all tables first if they exist
|
|
||||||
$manager = $DB->get_manager();
|
$manager = $DB->get_manager();
|
||||||
foreach ($test_tables as $table) {
|
foreach ($test_tables as $table) {
|
||||||
$xmldbtable = new xmldb_table($table);
|
$xmldbtable = new xmldb_table($table);
|
||||||
$manager->drop_table($xmldbtable);
|
$manager->drop_table($xmldbtable);
|
||||||
}
|
}
|
||||||
|
$test_tables = $DB->get_tables();
|
||||||
|
$testtablesok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
upgrade_db($version, $release, true);
|
if (empty($test_tables['config'])) {
|
||||||
}
|
// TODO replace error with proper admin dialog
|
||||||
|
notice_yesno(get_string('tablesnotsetup', 'simpletest'), $FULLSCRIPT . '?setuptesttables=1', $FULLSCRIPT);
|
||||||
if ($droptesttables) {
|
$DB = $real_db;
|
||||||
$manager = $DB->get_manager();
|
admin_externalpage_print_footer();
|
||||||
foreach ($test_tables as $table) {
|
exit();
|
||||||
$xmldbtable = new xmldb_table($table);
|
|
||||||
$manager->drop_table($xmldbtable);
|
|
||||||
}
|
}
|
||||||
$test_tables = $DB->get_tables();
|
|
||||||
$testtablesok = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($test_tables['config'])) {
|
$DB->dispose();
|
||||||
// TODO replace error with proper admin dialog
|
|
||||||
notice_yesno(get_string('tablesnotsetup', 'simpletest'), $baseurl . '?setuptesttables=1', $baseurl);
|
|
||||||
$DB = $real_db;
|
$DB = $real_db;
|
||||||
admin_externalpage_print_footer();
|
$CFG = $real_cfg;
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
$DB->dispose();
|
// end of ugly hack
|
||||||
$DB = $real_db;
|
}
|
||||||
$CFG = $real_cfg;
|
|
||||||
|
|
||||||
if (!is_null($path)) {
|
if (!is_null($path)) {
|
||||||
// Create the group of tests.
|
// Create the group of tests.
|
||||||
|
@ -261,7 +207,12 @@ echo '</form>';
|
||||||
print_box_end();
|
print_box_end();
|
||||||
|
|
||||||
print_box_start('generalbox boxwidthwide boxaligncenter');
|
print_box_start('generalbox boxwidthwide boxaligncenter');
|
||||||
if ($testtablesok) {
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
print_heading(get_string('testdboperations', 'simpletest'));
|
||||||
|
// TODO: localise
|
||||||
|
echo '<p>Please add $CFG->unittestprefix="tst_"; or some other unique test table prefix if you want to execute all tests';
|
||||||
|
|
||||||
|
} else {
|
||||||
print_heading(get_string('testdboperations', 'simpletest'));
|
print_heading(get_string('testdboperations', 'simpletest'));
|
||||||
echo '<p>'.get_string('unittestprefixsetting', 'simpletest', $CFG).'</p>';
|
echo '<p>'.get_string('unittestprefixsetting', 'simpletest', $CFG).'</p>';
|
||||||
echo '<form style="display:inline" method="get" action="index.php">';
|
echo '<form style="display:inline" method="get" action="index.php">';
|
||||||
|
|
|
@ -54,7 +54,6 @@ $CFG->dbname = 'moodle'; // database name, eg moodle
|
||||||
$CFG->dbuser = 'username'; // your database username
|
$CFG->dbuser = 'username'; // your database username
|
||||||
$CFG->dbpass = 'password'; // your database password
|
$CFG->dbpass = 'password'; // your database password
|
||||||
$CFG->prefix = 'mdl_'; // Prefix to use for all table names
|
$CFG->prefix = 'mdl_'; // Prefix to use for all table names
|
||||||
// $CFG->unittest_prefix = 'tst_'; // Prefix used for unit test tables. Needs to be un-commented for test tables installation to proceed
|
|
||||||
|
|
||||||
$CFG->dbpersist = false; // Should database connections be reused?
|
$CFG->dbpersist = false; // Should database connections be reused?
|
||||||
// "false" is the most stable setting
|
// "false" is the most stable setting
|
||||||
|
@ -287,6 +286,26 @@ $CFG->admin = 'admin';
|
||||||
//
|
//
|
||||||
// NOTE: if you are using custompix in your theme, see /fixpix.php.
|
// NOTE: if you are using custompix in your theme, see /fixpix.php.
|
||||||
//
|
//
|
||||||
|
// Set the priority of themes from highest to lowest. This is useful (for
|
||||||
|
// example) in sites where the user theme should override all other theme
|
||||||
|
// settings for accessibility reasons. You can also disable types of themes
|
||||||
|
// by removing them from the array. The default setting is:
|
||||||
|
// $CFG->themeorder = array('page', 'course', 'category', 'session', 'user', 'site');
|
||||||
|
// NOTE: course, category, session, user themes still require the
|
||||||
|
// respective settings to be enabled
|
||||||
|
//
|
||||||
|
// When working with production data on test servers, no emails should ever be send to real users
|
||||||
|
// $CFG->noemailever = true;
|
||||||
|
//
|
||||||
|
|
||||||
|
//=========================================================================
|
||||||
|
// 8. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!
|
||||||
|
//=========================================================================
|
||||||
|
//
|
||||||
|
// Specify prefix for fake unit test tables. If not specified only tests
|
||||||
|
// taht do not need fake tables will be executed.
|
||||||
|
// $CFG->unittestprefix = 'tst_';
|
||||||
|
//
|
||||||
// special magic evil developer only wanting to edit the xmldb files manually
|
// special magic evil developer only wanting to edit the xmldb files manually
|
||||||
// AND don't use the XMLDBEditor nor the prev/next stuff at all (Mahara and others)
|
// AND don't use the XMLDBEditor nor the prev/next stuff at all (Mahara and others)
|
||||||
// Uncomment these if you're lazy like Penny
|
// Uncomment these if you're lazy like Penny
|
||||||
|
@ -299,18 +318,7 @@ $CFG->admin = 'admin';
|
||||||
// Uncomment this if you're lazy like Petr
|
// Uncomment this if you're lazy like Petr
|
||||||
// $CFG->xmldbreconstructprevnext = true;
|
// $CFG->xmldbreconstructprevnext = true;
|
||||||
//
|
//
|
||||||
// Set the priority of themes from highest to lowest. This is useful (for
|
|
||||||
// example) in sites where the user theme should override all other theme
|
|
||||||
// settings for accessibility reasons. You can also disable types of themes
|
|
||||||
// by removing them from the array. The default setting is:
|
|
||||||
// $CFG->themeorder = array('page', 'course', 'category', 'session', 'user', 'site');
|
|
||||||
// NOTE: course, category, session, user themes still require the
|
|
||||||
// respective settings to be enabled
|
|
||||||
//
|
|
||||||
// When working with production data on test servers, no emails should ever be send to real users
|
|
||||||
// $CFG->noemailever = true;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
// ALL DONE! To continue installation, visit your main page with a browser
|
// ALL DONE! To continue installation, visit your main page with a browser
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
|
|
|
@ -163,9 +163,15 @@ class FakeDBUnitTestCase extends UnitTestCase {
|
||||||
* @throws moodle_exception if CSV file cannot be created
|
* @throws moodle_exception if CSV file cannot be created
|
||||||
*/
|
*/
|
||||||
public function __construct($label = false) {
|
public function __construct($label = false) {
|
||||||
|
global $DB, $CFG;
|
||||||
|
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
parent::UnitTestCase($label);
|
parent::UnitTestCase($label);
|
||||||
// MDL-16483 Get PKs and save data to text file
|
// MDL-16483 Get PKs and save data to text file
|
||||||
global $DB, $CFG;
|
|
||||||
$this->pkfile = $CFG->dataroot.'/testtablespks.csv';
|
$this->pkfile = $CFG->dataroot.'/testtablespks.csv';
|
||||||
$this->cfg = $CFG;
|
$this->cfg = $CFG;
|
||||||
|
|
||||||
|
@ -203,6 +209,10 @@ class FakeDBUnitTestCase extends UnitTestCase {
|
||||||
private function truncate_test_tables($tabledata) {
|
private function truncate_test_tables($tabledata) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$tables = $DB->get_tables();
|
$tables = $DB->get_tables();
|
||||||
|
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
|
@ -220,6 +230,12 @@ class FakeDBUnitTestCase extends UnitTestCase {
|
||||||
* @throws moodle_exception if file doesn't exist
|
* @throws moodle_exception if file doesn't exist
|
||||||
*/
|
*/
|
||||||
public function get_table_data($filename) {
|
public function get_table_data($filename) {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists($this->pkfile)) {
|
if (file_exists($this->pkfile)) {
|
||||||
$handle = fopen($this->pkfile, 'r');
|
$handle = fopen($this->pkfile, 'r');
|
||||||
$tabledata = array();
|
$tabledata = array();
|
||||||
|
@ -243,8 +259,13 @@ class FakeDBUnitTestCase extends UnitTestCase {
|
||||||
* TODO Improve detection of incorrectly built DB test tables (e.g. detect version discrepancy and offer to upgrade/rebuild)
|
* TODO Improve detection of incorrectly built DB test tables (e.g. detect version discrepancy and offer to upgrade/rebuild)
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
global $DB, $CFG;
|
||||||
|
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
global $DB;
|
|
||||||
$this->DB =& $DB;
|
$this->DB =& $DB;
|
||||||
ob_start();
|
ob_start();
|
||||||
}
|
}
|
||||||
|
@ -253,7 +274,12 @@ class FakeDBUnitTestCase extends UnitTestCase {
|
||||||
* Method called after each test method. Doesn't do anything extraordinary except restore the global $DB to the real one.
|
* Method called after each test method. Doesn't do anything extraordinary except restore the global $DB to the real one.
|
||||||
*/
|
*/
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
global $DB;
|
global $DB, $CFG;
|
||||||
|
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($DB)) {
|
if (empty($DB)) {
|
||||||
$DB = $this->DB;
|
$DB = $this->DB;
|
||||||
}
|
}
|
||||||
|
@ -273,6 +299,10 @@ class FakeDBUnitTestCase extends UnitTestCase {
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$CFG = $this->cfg;
|
$CFG = $this->cfg;
|
||||||
$this->tearDown();
|
$this->tearDown();
|
||||||
UnitTestDB::restore();
|
UnitTestDB::restore();
|
||||||
|
@ -295,7 +325,12 @@ class FakeDBUnitTestCase extends UnitTestCase {
|
||||||
* @return array $objects corresponding to $data.
|
* @return array $objects corresponding to $data.
|
||||||
*/
|
*/
|
||||||
public function load_test_data($table, array $cols, array $data) {
|
public function load_test_data($table, array $cols, array $data) {
|
||||||
global $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
foreach ($data as $rowid => $row) {
|
foreach ($data as $rowid => $row) {
|
||||||
$obj = new stdClass;
|
$obj = new stdClass;
|
||||||
|
@ -318,7 +353,12 @@ class FakeDBUnitTestCase extends UnitTestCase {
|
||||||
* @param array $rows the rows to delete. Actually, only $rows[$key]->id is used.
|
* @param array $rows the rows to delete. Actually, only $rows[$key]->id is used.
|
||||||
*/
|
*/
|
||||||
public function delete_test_data($table, array $rows) {
|
public function delete_test_data($table, array $rows) {
|
||||||
global $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$ids = array();
|
$ids = array();
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$ids[] = $row->id;
|
$ids[] = $row->id;
|
||||||
|
|
|
@ -8,6 +8,7 @@ Changes:
|
||||||
* Bug fix in simpletest.php and test_case.php. Marked with //moodlefix begins,
|
* Bug fix in simpletest.php and test_case.php. Marked with //moodlefix begins,
|
||||||
//moodlefix ends comments. This has been reported back to the simpletest mailing
|
//moodlefix ends comments. This has been reported back to the simpletest mailing
|
||||||
list. Hopefully will be included in a future release.
|
list. Hopefully will be included in a future release.
|
||||||
|
* modified run() in test_case.php - skipping tests that need fake db if prefix not set
|
||||||
|
|
||||||
skodak, Tim
|
skodak, Tim
|
||||||
|
|
||||||
|
|
|
@ -596,6 +596,16 @@ class TestSuite {
|
||||||
if (is_string($this->_test_cases[$i])) {
|
if (is_string($this->_test_cases[$i])) {
|
||||||
$class = $this->_test_cases[$i];
|
$class = $this->_test_cases[$i];
|
||||||
$test = &new $class();
|
$test = &new $class();
|
||||||
|
// moodle hack start
|
||||||
|
global $CFG;
|
||||||
|
if (empty($CFG->unittestprefix)) {
|
||||||
|
if ($test instanceof FakeDBUnitTestCase) {
|
||||||
|
// do not execute this test because test tables not present!
|
||||||
|
unset($test);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// moodle hack end
|
||||||
$test->run($reporter);
|
$test->run($reporter);
|
||||||
unset($test);
|
unset($test);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue