Skip to content

Commit

Permalink
MDL-16486 Improved interface, added permission warning and other mino…
Browse files Browse the repository at this point in the history
…r fixes
  • Loading branch information
nicolasconnault committed Sep 23, 2008
1 parent 4bbe9e9 commit d27a349
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
72 changes: 43 additions & 29 deletions admin/report/simpletest/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,43 +52,53 @@
// 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();
}
Expand Down Expand Up @@ -248,9 +258,9 @@
}
// 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>';
Expand All @@ -262,25 +272,29 @@
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();

Expand Down
1 change: 1 addition & 0 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
$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
Expand Down
4 changes: 4 additions & 0 deletions lang/en_utf8/simpletest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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: <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';
Expand Down Expand Up @@ -34,13 +36,15 @@
$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['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: <strong>$CFG->unittestprefix</strong> (Edit config.php to modify this).';
$string['version'] = 'Using <a href=\"http://sourceforge.net/projects/simpletest/\">SimpleTest</a> version $a.';

?>

0 comments on commit d27a349

Please sign in to comment.