]> git.joonet.de Git - adminer.git/commitdiff
Coverage uses the same cookie so must live in the same directory
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 24 Jun 2009 10:02:12 +0000 (10:02 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 24 Jun 2009 10:02:12 +0000 (10:02 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@756 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/coverage.inc.php [new file with mode: 0644]
adminer/index.php
compile.php
coverage.php [deleted file]
tests/0-login.html
tests/logout.html

diff --git a/adminer/coverage.inc.php b/adminer/coverage.inc.php
new file mode 100644 (file)
index 0000000..dc0bbf4
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+function xhtml_open_tags($s) {
+       // returns array of opened tags in $s
+       $return = array();
+       preg_match_all('~<([^>]+)~', $s, $matches);
+       foreach ($matches[1] as $val) {
+               if ($val{0} == "/") {
+                       array_pop($return);
+               } elseif (substr($val, -1) != "/") {
+                       $return[] = $val;
+               }
+       }
+       return $return;
+}
+
+page_header("Coverage", (extension_loaded("xdebug") ? "" : "Xdebug has to be enabled."));
+
+if ($_GET["coverage"] === "0") {
+       unset($_SESSION["coverage"]); // disable coverage if it is not available
+       if (extension_loaded("xdebug")) {
+               $_SESSION["coverage"] = array();
+               echo "<p class='message'>Coverage started.</p>\n";
+       }
+} elseif (preg_match('~^(include/)?[-_.a-z0-9]+$~i', $_GET["coverage"])) {
+       // highlight single file
+       $filename = $_GET["coverage"];
+       $cov = $_SESSION["coverage"][realpath($filename)];
+       $file = explode("<br />", highlight_file($filename, true));
+       unset($prev_color);
+       $s = "";
+       for ($l=0; $l <= count($file); $l++) {
+               $line = $file[$l];
+               $color = "#C0FFC0"; // tested
+               switch ($cov[$l+1]) {
+                       case -1: $color = "#FFC0C0"; break; // untested
+                       case -2: $color = "Silver"; break; // dead code
+                       case null: $color = ""; break; // not executable
+               }
+               if (!isset($prev_color)) {
+                       $prev_color = $color;
+               }
+               if ($prev_color != $color || !isset($line)) {
+                       echo "<div" . ($prev_color ? " style='background-color: $prev_color;'" : "") . ">" . $s;
+                       $open_tags = xhtml_open_tags($s);
+                       foreach (array_reverse($open_tags) as $tag) {
+                               echo "</" . preg_replace('~ .*~', '', $tag) . ">";
+                       }
+                       echo "</div>\n";
+                       $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : "");
+                       $prev_color = $color;
+               }
+               $s .= "$line<br />\n";
+       }
+} else {
+       // display list of files
+       echo "<table cellspacing='0'>\n";
+       foreach (array_merge(glob("*.php"), glob("include/*.php")) as $filename) {
+               $cov = $_SESSION["coverage"][realpath($filename)];
+               $ratio = 0;
+               if (isset($cov)) {
+                       $values = array_count_values($cov);
+                       $ratio = round(100 - 100 * $values[-1] / count($cov));
+               }
+               echo "<tr><td align='right' style='background-color: " . ($ratio < 50 ? "Red" : ($ratio < 75 ? "#FFEA20" : "#A7FC9D")) . ";'>$ratio%</td><th><a href=\"" . htmlspecialchars($SELF) . "coverage=$filename\">$filename</a></th></tr>\n";
+       }
+       echo "</table>\n";
+       echo '<p><a href="' . htmlspecialchars($SELF) . 'coverage=0">Start new coverage</a></p>' . "\n";
+}
+page_footer("auth");
+exit;
index 23e1e1ded8e68b4321f1a8288632bf64710c146d..04f28c8d2102265028e98e875a48bc2e030a14ce 100644 (file)
@@ -26,10 +26,6 @@ if (isset($_SESSION["coverage"])) {
        }
        xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
        register_shutdown_function('save_coverage');
-       if ($_GET["start"]) {
-               // included from ../coverage.php
-               return;
-       }
 }
 // disable magic quotes to be able to use database escaping function
 if (get_magic_quotes_gpc()) {
@@ -55,6 +51,9 @@ include "./include/functions.inc.php";
 include "./include/lang.inc.php";
 include "./lang/$LANG.inc.php";
 include "./include/design.inc.php";
+if (isset($_GET["coverage"])) {
+       include "./coverage.inc.php";
+}
 include "./include/pdo.inc.php";
 include "./include/mysql.inc.php";
 include "./include/auth.inc.php";
index 3f2ce468776c2944b9024f578271a253d3034349..36624937e58f9038432e26ff53da0fce37bbb794 100644 (file)
@@ -171,6 +171,7 @@ if ($_SERVER["argc"] > 1) {
 
 $filename = "adminer" . ($_COOKIE["adminer_lang"] ? "-$_COOKIE[adminer_lang]" : "") . ".php";
 $file = file_get_contents(dirname(__FILE__) . "/adminer/index.php");
+$file = preg_replace('(' . str_replace(' ', '\\s*', preg_quote(' if (isset($_GET["coverage"])) { include "./coverage.inc.php"; }')) . ')', '', $file);
 $file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file);
 $file = preg_replace("~if \\(isset\\(\\\$_SESSION\\[\"coverage.*\n}\n| && !isset\\(\\\$_SESSION\\[\"coverage\"\\]\\)~sU", '', $file);
 if ($_COOKIE["adminer_lang"]) {
diff --git a/coverage.php b/coverage.php
deleted file mode 100644 (file)
index 055261f..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-error_reporting(E_ALL & ~E_NOTICE);
-if (!ini_get("session.auto_start")) {
-       session_name("adminer_sid");
-       session_set_cookie_params(ini_get("session.cookie_lifetime"), preg_replace('~_coverage\\.php(\\?.*)?$~', '', $_SERVER["REQUEST_URI"]));
-       session_start();
-}
-
-function xhtml_open_tags($s) {
-       // returns array of opened tags in $s
-       $return = array();
-       preg_match_all('~<([^>]+)~', $s, $matches);
-       foreach ($matches[1] as $val) {
-               if ($val{0} == "/") {
-                       array_pop($return);
-               } elseif (substr($val, -1) != "/") {
-                       $return[] = $val;
-               }
-       }
-       return $return;
-}
-
-if (!extension_loaded("xdebug")) {
-       echo "<p>Xdebug has to be enabled.</p>\n";
-}
-
-if ($_GET["start"]) {
-       unset($_SESSION["coverage"]);
-       xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
-       $_SESSION["coverage"] = array();
-       include "./adminer/index.php";
-       header("Location: .");
-       exit;
-}
-if (preg_match('~^(include/)?[-_.a-z0-9]+$~i', $_GET["filename"])) {
-       // highlight single file
-       $filename = "adminer/$_GET[filename]";
-       $cov = $_SESSION["coverage"][realpath($filename)];
-       $file = explode("<br />", highlight_file($filename, true));
-       unset($prev_color);
-       $s = "";
-       for ($l=0; $l <= count($file); $l++) {
-               $line = $file[$l];
-               $color = "#C0FFC0"; // tested
-               switch ($cov[$l+1]) {
-                       case -1: $color = "#FFC0C0"; break; // untested
-                       case -2: $color = "Silver"; break; // dead code
-                       case null: $color = ""; break; // not executable
-               }
-               if (!isset($prev_color)) {
-                       $prev_color = $color;
-               }
-               if ($prev_color != $color || !isset($line)) {
-                       echo "<div" . ($prev_color ? " style='background-color: $prev_color;'" : "") . ">" . $s;
-                       $open_tags = xhtml_open_tags($s);
-                       foreach (array_reverse($open_tags) as $tag) {
-                               echo "</" . preg_replace('~ .*~', '', $tag) . ">";
-                       }
-                       echo "</div>\n";
-                       $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : "");
-                       $prev_color = $color;
-               }
-               $s .= "$line<br />\n";
-       }
-} else {
-       // display list of files
-       echo "<table border='0' cellspacing='0' cellpadding='1'>\n";
-       foreach (array_merge(glob("adminer/*.php"), glob("adminer/include/*.php")) as $filename) {
-               $cov = $_SESSION["coverage"][realpath($filename)];
-               $filename = substr($filename, 8);
-               $ratio = 0;
-               if (isset($cov)) {
-                       $values = array_count_values($cov);
-                       $ratio = round(100 - 100 * $values[-1] / count($cov));
-               }
-               echo "<tr><td align='right' style='background-color: " . ($ratio < 50 ? "Red" : ($ratio < 75 ? "#FFEA20" : "#A7FC9D")) . ";'>$ratio%</td><td><a href='coverage.php?filename=$filename'>$filename</a></td></tr>\n";
-       }
-       echo "</table>\n";
-       echo "<p><a href='coverage.php?start=1'>Start new coverage</a> (requires <a href='http://www.xdebug.org'>Xdebug</a>)</p>\n";
-}
index aac7c98a31a07a4acb7e2a8b7bbdcd7ab8c6ffc5..d1fe3c710ce0c88b7cf849ba3786bf6f05abf270 100644 (file)
@@ -13,7 +13,7 @@
 </thead><tbody>
 <tr>
        <td>open</td>
-       <td>/adminer/coverage.php?start=1</td>
+       <td>/adminer/adminer/?coverage=0</td>
        <td></td>
 </tr>
 <tr>
index 1e1480cda2c8585f54db4e224b30fdaf8b0150e8..d3358b14849ce0776136c3f5ce124a88f16a4002 100644 (file)
@@ -38,7 +38,7 @@
 </tr>
 <tr>
        <td>open</td>
-       <td>/adminer/coverage.php</td>
+       <td>/adminer/adminer/?coverage=</td>
        <td></td>
 </tr>