// 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 '<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>';
+ 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();
}
}
// Print the form for adjusting options.
print_box_start('generalbox boxwidthwide boxaligncenter');
+print_heading($formheader);
echo '<form method="get" action="index.php">';
echo '<fieldset class="invisiblefieldset">';
-print_heading($formheader);
echo '<p>'; print_checkbox('showpasses', 1, $showpasses, get_string('showpasses', $langfile)); echo '</p>';
echo '<p>'; print_checkbox('showsearch', 1, $showsearch, get_string('showsearch', $langfile)); echo '</p>';
echo '<p>'; print_checkbox('thorough', 1, $thorough, get_string('thorough', $langfile)); echo '</p>';
echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
echo '</fieldset>';
echo '</form>';
+print_box_end();
+print_box_start('generalbox boxwidthwide boxaligncenter');
if ($testtablesok) {
- echo '<form method="get" action="index.php">';
+ print_heading(get_string('testdboperations', 'simpletest'));
+ echo '<p>'.get_string('unittestprefixsetting', 'simpletest', $CFG).'</p>';
+ echo '<form style="display:inline" 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 '<form style="display:inline" 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.
admin_externalpage_print_footer();
$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: <br />
+\$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';
$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['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)';
$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: <strong>$CFG->unittestprefix</strong> (Edit config.php to modify this).';
$string['version'] = 'Using <a href=\"http://sourceforge.net/projects/simpletest/\">SimpleTest</a> version $a.';
?>