From: nicolasconnault Date: Tue, 23 Sep 2008 06:42:18 +0000 (+0000) Subject: MDL-16486 Improved interface, added permission warning and other minor fixes X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d27a349bfefa2e8e40d9d2ba0312d46c3beeb028;p=moodle.git MDL-16486 Improved interface, added permission warning and other minor fixes --- diff --git a/admin/report/simpletest/index.php b/admin/report/simpletest/index.php index 74bf98b915..2b3db447b4 100644 --- a/admin/report/simpletest/index.php +++ b/admin/report/simpletest/index.php @@ -52,43 +52,53 @@ $baseurl = $CFG->wwwroot . '/admin/report/simpletest/index.php'; // Add unittest prefix to config.php if needed if ($addconfigprefix && !isset($CFG->unittestprefix)) { // Open config file, search for $CFG->prefix and append a new line under it - $handle = fopen($CFG->dirroot.'/config.php', 'r+'); + if ($handle = @fopen($CFG->dirroot.'/config.php', 'r+')) { - $new_file = ''; + $new_file = ''; - while (!feof($handle)) { - $line = fgets($handle, 4096); - $prefix_line = null; + while (!feof($handle)) { + $line = fgets($handle, 4096); + $prefix_line = null; - if (preg_match('/CFG\-\>prefix/', $line, $matches)) { - $prefix_line = "\$CFG->unittestprefix = '$addconfigprefix';\n"; + if (preg_match('/CFG\-\>prefix/', $line, $matches)) { + $prefix_line = "\$CFG->unittestprefix = '$addconfigprefix';\n"; + } + + $new_file .= $line; + $new_file .= $prefix_line; } - $new_file .= $line; - $new_file .= $prefix_line; + fclose($handle); + $handle = fopen($CFG->dirroot.'/config.php', 'w'); + fwrite($handle, $new_file); + fclose($handle); + $CFG->unittestprefix = $addconfigprefix; + } else { + notify(get_string('confignonwritable', 'simpletest')); + die(); } - - fclose($handle); - $handle = fopen($CFG->dirroot.'/config.php', 'w'); - fwrite($handle, $new_file); - fclose($handle); - $CFG->unittestprefix = $addconfigprefix; } if (empty($CFG->unittestprefix)) { // TODO replace error with proper admin dialog + print_box_start('generalbox', 'notice'); - echo '

'.get_string("prefixnotset", 'simpletest').'

'; - echo '
- - - - - - -
-
'; + if (is_writable($CFG->dirroot.'/config.php')) { + echo '

'.get_string("prefixnotset", 'simpletest').'

'; + echo '
+ + + + + + +
+
'; + } else { + notify(get_string('confignonwritable', 'simpletest')); + } print_box_end(); + admin_externalpage_print_footer(); exit(); } @@ -248,9 +258,9 @@ if (!is_null($path)) { } // Print the form for adjusting options. print_box_start('generalbox boxwidthwide boxaligncenter'); +print_heading($formheader); echo '
'; echo '
'; -print_heading($formheader); echo '

'; print_checkbox('showpasses', 1, $showpasses, get_string('showpasses', $langfile)); echo '

'; echo '

'; print_checkbox('showsearch', 1, $showsearch, get_string('showsearch', $langfile)); echo '

'; echo '

'; print_checkbox('thorough', 1, $thorough, get_string('thorough', $langfile)); echo '

'; @@ -262,25 +272,29 @@ echo '

'; print_checkbox('rundbtests', 1, $rundbtests, get_string('rundbtests' echo ''; echo '

'; echo '
'; +print_box_end(); +print_box_start('generalbox boxwidthwide boxaligncenter'); if ($testtablesok) { - echo '
'; + print_heading(get_string('testdboperations', 'simpletest')); + echo '

'.get_string('unittestprefixsetting', 'simpletest', $CFG).'

'; + echo ''; echo '
'; echo ''; echo ''; echo '
'; echo '
'; - echo '
'; + echo ''; echo '
'; echo ''; echo ''; echo '
'; echo '
'; } - print_box_end(); + // Footer. admin_externalpage_print_footer(); diff --git a/config-dist.php b/config-dist.php index 0a69338ecc..f018d4c3fa 100644 --- a/config-dist.php +++ b/config-dist.php @@ -54,6 +54,7 @@ $CFG->dbname = 'moodle'; // database name, eg moodle $CFG->dbuser = 'username'; // your database username $CFG->dbpass = 'password'; // your database password $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? // "false" is the most stable setting diff --git a/lang/en_utf8/simpletest.php b/lang/en_utf8/simpletest.php index 675349ad17..a0db5f7723 100644 --- a/lang/en_utf8/simpletest.php +++ b/lang/en_utf8/simpletest.php @@ -4,6 +4,8 @@ $string['all'] = 'ALL'; $string['addconfigprefix'] = 'Add prefix to config file'; +$string['confignonwritable'] = 'The file config.php is not writeable by the web server. Either change its permissions, or edit it with the appropriate user account, and add the following line before the closing php tag:
+\$CFG->unittestprefix = \'tst_\' // Change tst_ to a prefix of your choice, different from \$CFG->prefix'; $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'; @@ -34,6 +36,7 @@ $string['showsearch'] = 'Show the search for test files.'; $string['stacktrace'] = 'Stack trace:'; $string['summary'] = '{$a->run}/{$a->total} test cases complete: {$a->passes} passes, {$a->fails} fails and {$a->exceptions} exceptions.'; $string['tablesnotsetup'] = 'Unit test tables are not yet built. Do you want to build them now?.'; +$string['testdboperations'] = 'Test Database operations'; $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)'; @@ -41,6 +44,7 @@ $string['thorough'] = 'Run a thorough test (may be slow).'; $string['updatingnoninsertedrecord'] = 'Trying to update a record that was not inserted by these unit tests (id $a->id in table $a->table).'; $string['uncaughtexception'] = 'Uncaught exception [{$a->getMessage()}] in [{$a->getFile()}:{$a->getLine()}] TESTS ABORTED.'; $string['unittests'] = 'Unit tests'; +$string['unittestprefixsetting'] = 'Unit test prefix: $CFG->unittestprefix (Edit config.php to modify this).'; $string['version'] = 'Using SimpleTest version $a.'; ?>