]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16486 Improved interface, added permission warning and other minor fixes
authornicolasconnault <nicolasconnault>
Tue, 23 Sep 2008 06:42:18 +0000 (06:42 +0000)
committernicolasconnault <nicolasconnault>
Tue, 23 Sep 2008 06:42:18 +0000 (06:42 +0000)
admin/report/simpletest/index.php
config-dist.php
lang/en_utf8/simpletest.php

index 74bf98b9153ff2d2bf73c31d1a2d373d1790b022..2b3db447b4502ed1d8271c63163a1043c389f227 100644 (file)
@@ -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 '<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();
 }
@@ -248,9 +258,9 @@ if (!is_null($path)) {
 }
 // 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>';
@@ -262,25 +272,29 @@ echo '<p>'; print_checkbox('rundbtests', 1, $rundbtests, get_string('rundbtests'
 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();
 
index 0a69338ecc8bb6a6144b56de1117a23cd71bd5a3..f018d4c3fafeb4ede2ab0e6557240c296d07ce60 100644 (file)
@@ -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
index 675349ad17b212c40942296a921db362c2438416..a0db5f772361a8a0d394c8fb63fe367f563896a6 100644 (file)
@@ -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';
@@ -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: <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)';
@@ -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: <strong>$CFG->unittestprefix</strong> (Edit config.php to modify this).';
 $string['version'] = 'Using <a href=\"http://sourceforge.net/projects/simpletest/\">SimpleTest</a> version $a.';
 
 ?>