logo       


CVS: phpwiki/tests/unit test.php,1.16,1.17: msg#00051

Subject: CVS: phpwiki/tests/unit test.php,1.16,1.17
Update of /cvsroot/phpwiki/phpwiki/tests/unit
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28425

Modified Files:
        test.php 
Log Message:
improved commend-line handling: 
  test=<testname>... db=<backend>... debug=<num> level=<num>
added level to user object (certain tests require admin privileges)
improved windows memory trace: for getmypid only. (requires cygwin)
  TODO: not the bash, just the php or apache pid. use /proc/#/stat instead of 
statm?


Index: test.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/tests/unit/test.php,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -2 -b -p -d -r1.16 -r1.17
--- test.php    4 Oct 2004 23:45:28 -0000       1.16
+++ test.php    19 Oct 2004 15:21:17 -0000      1.17
@@ -28,4 +28,6 @@
  * These tests run from the command-line as well as from the browser.
  * Use the argv (from cli) or tests (from browser) params to run only certain 
tests.
+ *
+ * $ tests.php test=<testname1> test=<testname2> ... db=dba debug=9 level=10
  */
 /****************************************************************
@@ -67,15 +69,8 @@ $ini_sep = substr(PHP_OS,0,3) == 'WIN' ?
 ini_set('include_path', ini_get('include_path') . $ini_sep . $rootdir);
 
-# This quiets a warning in config.php
+# Quiet warnings in IniConfig.php
 $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1';
 $HTTP_SERVER_VARS['HTTP_USER_AGENT'] = "PHPUnit";
 
-define('PHPWIKI_NOMAIN',true);
-define('DEBUG', 9); //_DEBUG_VERBOSE | _DEBUG_TRACE
-
-# Other needed files
-require_once $rootdir.'index.php';
-require_once $rootdir.'lib/main.php';
-
 function printSimpleTrace($bt) {
     //print_r($bt);
@@ -103,5 +98,8 @@ $foo = assert_options( ASSERT_CALLBACK, 
 #
 // set the error reporting level for this script
-error_reporting(E_ALL);
+if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
+    error_reporting(E_ALL & ~E_STRICT);        // exclude E_STRICT
+else
+    error_reporting(E_ALL); // php4
 // This is too strict, fails on every notice and warning. 
 /*
@@ -127,43 +125,4 @@ function _ErrorHandler_CB(&$error) {
 */
 
-if (ENABLE_USER_NEW) {
-    class MockUser extends _WikiUser {
-        function MockUser($name, $isSignedIn) {
-            $this->_userid = $name;
-            $this->_isSignedIn = $isSignedIn;
-        }
-        function isSignedIn() {
-            return $this->_isSignedIn;
-        }
-    }
-} else {
-    class MockUser extends WikiUser {
-        function MockUser($name, $isSignedIn) {
-            $this->_userid = $name;
-            $this->_isSignedIn = $isSignedIn;
-        }
-        function isSignedIn() {
-            return $this->_isSignedIn;
-        }
-    }
-}
-
-//FIXME: ignore cached requests (if-modified-since) from cli
-class MockRequest extends WikiRequest {
-    function MockRequest(&$dbparams) {
-        $this->_dbi = WikiDB::open($dbparams);
-        $this->_user = new MockUser("a_user", true);
-        $this->_group = WikiGroup::getGroup();
-        $this->_args = array('pagename' => 'HomePage', 'action' => 'browse');
-        $this->Request();
-    }
-    function getGroup() {
-       if (is_object($this->_group))
-            return $this->_group;
-        else // FIXME: this is set to "/f:" somewhere.
-            return WikiGroup::getGroup();
-    }
-}
-
 function purge_dir($dir) {
     static $finder;
@@ -207,17 +166,4 @@ function purge_testbox() {
 }
 
-global $ErrorManager;
-$ErrorManager->setPostponedErrorMask(EM_FATAL_ERRORS|EM_WARNING_ERRORS|EM_NOTICE_ERRORS);
-
-/*
-if (ENABLE_USER_NEW)
-    $request->_user = WikiUser('AnonUser');
-else {
-    $request->_user = new WikiUser($request, 'AnonUser');
-    $request->_prefs = $request->_user->getPreferences();
-}
-*/
-include_once("themes/" . THEME . "/themeinfo.php");
-
 ####################################################################
 #
@@ -234,4 +180,109 @@ if (isset($HTTP_SERVER_VARS['REQUEST_MET
 // purge the testbox
     
+$debug_level = 9; //_DEBUG_VERBOSE | _DEBUG_TRACE
+$user_level  = 1; // BOGO
+// use argv (from cli) or tests (from browser) params to run only certain tests
+// avoid pear: Console::Getopt
+$alltests = 
array('InlineParserTest','HtmlParserTest','PageListTest','ListPagesTest',
+                  
'SetupWiki','DumpHtml','AllPagesTest','AllUsersTest','OrphanedPagesTest');
+if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
+    $argv = array();
+    foreach ($HTTP_GET_VARS as $key => $val) {
+        $argv[] = $key."=".$val;
+    }
+} elseif (!empty($argv) and preg_match("/test\.php$/", $argv[0]))
+    array_shift($argv);
+if (!empty($argv)) {
+    //support db=file db=dba test=SetupWiki test=DumpHtml debug=num
+    $runtests = array();
+    $run_database_backends = array();
+    foreach ($argv as $arg) {
+        if (in_array($arg, $alltests))
+            $runtests[] = $arg;
+        elseif (preg_match("/test=(.+)/",$arg,$m) and in_array($m[1], 
$alltests))
+            $runtests[] = $m[1];
+        elseif (preg_match("/db=(.+)/",$arg,$m) and in_array($m[1], 
$database_backends))
+            $run_database_backends[] = $m[1];
+        elseif (preg_match("/debug=(\d+)/",$arg,$m))
+            $debug_level = $m[1];
+        elseif (preg_match("/level=(\d+)/",$arg,$m))
+            $user_level = $m[1];
+        elseif ($debug_level & 1)
+            echo "ignored arg: ", $arg, "\n";
+    }
+    if (!empty($run_database_backends))
+        $database_backends = $run_database_backends;
+    if (!empty($runtests))
+        $alltests = $runtests;
+    if ($debug_level & 1) {
+        echo "test=", join(",",$alltests),"\n";
+        echo "db=", join(",",$database_backends),"\n";
+        echo "debug=", $debug_level,"\n";
+        echo "level=", $user_level,"\n";
+        echo "pid=",getmypid(),"\n";
+        echo "\n";
+    }
+    flush();
+}
+define('DEBUG', $debug_level); 
+
+define('PHPWIKI_NOMAIN', true);
+# Other needed files
+require_once $rootdir.'index.php';
+require_once $rootdir.'lib/main.php';
+
+global $ErrorManager;
+$ErrorManager->setPostponedErrorMask(EM_FATAL_ERRORS|EM_WARNING_ERRORS|EM_NOTICE_ERRORS);
+//FIXME: ignore cached requests (if-modified-since) from cli
+class MockRequest extends WikiRequest {
+    function MockRequest(&$dbparams) {
+        $this->_dbi = WikiDB::open($dbparams);
+        $this->_user = new MockUser("a_user", $GLOBALS['user_level']);
+        $this->_group = WikiGroup::getGroup();
+        $this->_args = array('pagename' => 'HomePage', 'action' => 'browse');
+        $this->Request();
+    }
+    function getGroup() {
+       if (is_object($this->_group))
+            return $this->_group;
+        else // FIXME: this is set to "/f:" somewhere.
+            return WikiGroup::getGroup();
+    }
+}
+
+if (ENABLE_USER_NEW) {
+    class MockUser extends _WikiUser {
+        function MockUser($name, $level) {
+            $this->_userid = $name;
+            $this->_isSignedIn = $level > 1;
+            $this->_level = $level;
+        }
+        function isSignedIn() {
+            return $this->_isSignedIn;
+        }
+    }
+} else {
+    class MockUser extends WikiUser {
+        function MockUser($name, $level) {
+            $this->_userid = $name;
+            $this->_isSignedIn = $level > 1;
+            $this->_level = $level;
+        }
+        function isSignedIn() {
+            return $this->_isSignedIn;
+        }
+    }
+}
+
+/*
+if (ENABLE_USER_NEW)
+    $request->_user = WikiUser('AnonUser');
+else {
+    $request->_user = new WikiUser($request, 'AnonUser');
+    $request->_prefs = $request->_user->getPreferences();
+}
+*/
+include_once("themes/" . THEME . "/themeinfo.php");
+
 // save and restore all args for each test.
 class phpwiki_TestCase extends PHPUnit_TestCase {
@@ -247,5 +298,7 @@ class phpwiki_TestCase extends PHPUnit_T
             echo "-- MEMORY USAGE: ";
             if (isWindows()) { // requires a newer cygwin
-               echo `cat /proc/meminfo | grep Mem:|perl -ane"print 
\$F[2];"`,"\n";
+                // what we want is the process memory only: apache or php
+               $pid = getmypid();
+               echo `cat /proc/$pid/statm |cut -f1`,"\n";
             } elseif (function_exists('memory_get_usage')) {
                 echo memory_get_usage(),"\n";
@@ -262,22 +315,4 @@ class phpwiki_TestCase extends PHPUnit_T
 }
 
-// use argv (from cli) or tests (from browser) params to run only certain tests
-$alltests = 
array('InlineParserTest','HtmlParserTest','PageListTest','ListPagesTest',
-                  
'SetupWiki','DumpHtml','AllPagesTest','AllUsersTest','OrphanedPagesTest');
-if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']) and 
!empty($HTTP_GET_VARS['tests']))
-    $argv = explode(',',$HTTP_GET_VARS['tests']);
-if (!empty($argv) and preg_match("/test\.php$/", $argv[0]))
-    array_shift($argv);
-if (!empty($argv)) {
-    $runtests = array();
-    foreach ($argv as $test) {
-        if (in_array($test,$alltests))
-            $runtests[] = $test;
-    }
-    $alltests = $runtests;
-    print_r($runtests);
-    flush();
-}
-
 # Test all db backends.
 foreach ($database_backends as $dbtype) {



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl


Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
Search:
Java, servers, webhosting, windows, cisco ...
more...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe