From 03c4aec3c817c51eda2cf5c241f76e3bef585799 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 4 Aug 2006 16:22:43 +0200 Subject: unittest fixes darcs-hash:20060804142243-9b6ab-d208f7f1a67a9958fda05c519c8407ad5e733cea.gz --- _test/cases/inc/common_clientIP.test.php | 147 ---------------------- _test/cases/inc/common_clientip.test.php | 147 ++++++++++++++++++++++ _test/cases/inc/pageutils_resolve_pageid.test.php | 3 + _test/cases/inc/parser/parser.test.php | 1 + _test/index.php | 52 ++++---- _test/lib/testmanager.php | 6 +- inc/auth.php | 8 +- inc/events.php | 1 + inc/init.php | 12 +- inc/pageutils.php | 8 +- inc/parser/handler.php | 2 +- inc/pluginutils.php | 3 +- 12 files changed, 208 insertions(+), 182 deletions(-) delete mode 100644 _test/cases/inc/common_clientIP.test.php create mode 100644 _test/cases/inc/common_clientip.test.php diff --git a/_test/cases/inc/common_clientIP.test.php b/_test/cases/inc/common_clientIP.test.php deleted file mode 100644 index 257229811..000000000 --- a/_test/cases/inc/common_clientIP.test.php +++ /dev/null @@ -1,147 +0,0 @@ -assertEqual(clientIP(),$out); - } - - function test_proxy1_all(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = '77.77.77.77'; - $_SERVER['HTTP_X_FORWARDED_FOR'] = ''; - $out = '123.123.123.123,77.77.77.77'; - $this->assertEqual(clientIP(),$out); - } - - function test_proxy2_all(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77'; - $out = '123.123.123.123,77.77.77.77'; - $this->assertEqual(clientIP(),$out); - } - - function test_proxyhops_all(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77,66.66.66.66'; - $out = '123.123.123.123,77.77.77.77,66.66.66.66'; - $this->assertEqual(clientIP(),$out); - } - - function test_simple_single(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = ''; - $out = '123.123.123.123'; - $this->assertEqual(clientIP(true),$out); - } - - function test_proxy1_single(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = '77.77.77.77'; - $_SERVER['HTTP_X_FORWARDED_FOR'] = ''; - $out = '77.77.77.77'; - $this->assertEqual(clientIP(true),$out); - } - - function test_proxy2_single(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77'; - $out = '77.77.77.77'; - $this->assertEqual(clientIP(true),$out); - } - - function test_proxyhops_single(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77,66.66.66.66'; - $out = '66.66.66.66'; - $this->assertEqual(clientIP(true),$out); - } - - function test_local_all(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1'; - $out = '123.123.123.123,127.0.0.1'; - $this->assertEqual(clientIP(),$out); - } - - function test_local1_single(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1'; - $out = '123.123.123.123'; - $this->assertEqual(clientIP(true),$out); - } - - function test_local2_single(){ - $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '123.123.123.123'; - $out = '123.123.123.123'; - $this->assertEqual(clientIP(true),$out); - } - - function test_local3_single(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,10.0.0.1,192.168.0.2,172.17.1.1,172.21.1.1,172.31.1.1'; - $out = '123.123.123.123'; - $this->assertEqual(clientIP(true),$out); - } - - function test_local4_single(){ - $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.0.5'; - $out = '192.168.0.5'; - $this->assertEqual(clientIP(true),$out); - } - - function test_garbage_all(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222'; - $out = '123.123.123.123'; - $this->assertEqual(clientIP(),$out); - } - - function test_garbage_single(){ - $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222'; - $out = '123.123.123.123'; - $this->assertEqual(clientIP(true),$out); - } - - function test_garbageonly_all(){ - $_SERVER['REMOTE_ADDR'] = 'argh'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222'; - $out = '0.0.0.0'; - $this->assertEqual(clientIP(),$out); - } - - function test_garbageonly_single(){ - $_SERVER['REMOTE_ADDR'] = 'argh'; - $_SERVER['HTTP_X_REAL_IP'] = ''; - $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222'; - $out = '0.0.0.0'; - $this->assertEqual(clientIP(true),$out); - } - - -} - -//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/_test/cases/inc/common_clientip.test.php b/_test/cases/inc/common_clientip.test.php new file mode 100644 index 000000000..257229811 --- /dev/null +++ b/_test/cases/inc/common_clientip.test.php @@ -0,0 +1,147 @@ +assertEqual(clientIP(),$out); + } + + function test_proxy1_all(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = '77.77.77.77'; + $_SERVER['HTTP_X_FORWARDED_FOR'] = ''; + $out = '123.123.123.123,77.77.77.77'; + $this->assertEqual(clientIP(),$out); + } + + function test_proxy2_all(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77'; + $out = '123.123.123.123,77.77.77.77'; + $this->assertEqual(clientIP(),$out); + } + + function test_proxyhops_all(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77,66.66.66.66'; + $out = '123.123.123.123,77.77.77.77,66.66.66.66'; + $this->assertEqual(clientIP(),$out); + } + + function test_simple_single(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = ''; + $out = '123.123.123.123'; + $this->assertEqual(clientIP(true),$out); + } + + function test_proxy1_single(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = '77.77.77.77'; + $_SERVER['HTTP_X_FORWARDED_FOR'] = ''; + $out = '77.77.77.77'; + $this->assertEqual(clientIP(true),$out); + } + + function test_proxy2_single(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77'; + $out = '77.77.77.77'; + $this->assertEqual(clientIP(true),$out); + } + + function test_proxyhops_single(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77,66.66.66.66'; + $out = '66.66.66.66'; + $this->assertEqual(clientIP(true),$out); + } + + function test_local_all(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1'; + $out = '123.123.123.123,127.0.0.1'; + $this->assertEqual(clientIP(),$out); + } + + function test_local1_single(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1'; + $out = '123.123.123.123'; + $this->assertEqual(clientIP(true),$out); + } + + function test_local2_single(){ + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '123.123.123.123'; + $out = '123.123.123.123'; + $this->assertEqual(clientIP(true),$out); + } + + function test_local3_single(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,10.0.0.1,192.168.0.2,172.17.1.1,172.21.1.1,172.31.1.1'; + $out = '123.123.123.123'; + $this->assertEqual(clientIP(true),$out); + } + + function test_local4_single(){ + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.0.5'; + $out = '192.168.0.5'; + $this->assertEqual(clientIP(true),$out); + } + + function test_garbage_all(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222'; + $out = '123.123.123.123'; + $this->assertEqual(clientIP(),$out); + } + + function test_garbage_single(){ + $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222'; + $out = '123.123.123.123'; + $this->assertEqual(clientIP(true),$out); + } + + function test_garbageonly_all(){ + $_SERVER['REMOTE_ADDR'] = 'argh'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222'; + $out = '0.0.0.0'; + $this->assertEqual(clientIP(),$out); + } + + function test_garbageonly_single(){ + $_SERVER['REMOTE_ADDR'] = 'argh'; + $_SERVER['HTTP_X_REAL_IP'] = ''; + $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222'; + $out = '0.0.0.0'; + $this->assertEqual(clientIP(true),$out); + } + + +} + +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/_test/cases/inc/pageutils_resolve_pageid.test.php b/_test/cases/inc/pageutils_resolve_pageid.test.php index 2546bd2af..ab282b57a 100644 --- a/_test/cases/inc/pageutils_resolve_pageid.test.php +++ b/_test/cases/inc/pageutils_resolve_pageid.test.php @@ -2,6 +2,9 @@ require_once DOKU_INC.'inc/utf8.php'; require_once DOKU_INC.'inc/pageutils.php'; +global $conf; +if (!isset($conf['datadir'])) $conf['datadir'] = $conf['savedir'].'/pages'; + class init_resolve_pageid_test extends UnitTestCase { diff --git a/_test/cases/inc/parser/parser.test.php b/_test/cases/inc/parser/parser.test.php index c760c127a..d18a245f7 100644 --- a/_test/cases/inc/parser/parser.test.php +++ b/_test/cases/inc/parser/parser.test.php @@ -10,6 +10,7 @@ */ require_once DOKU_INC . 'inc/parser/parser.php'; require_once DOKU_INC . 'inc/parser/handler.php'; +require_once DOKU_INC . 'inc/events.php'; //require_once DOKU . 'parser/renderer.php'; //Mock::generate('Doku_Renderer'); diff --git a/_test/index.php b/_test/index.php index 7410cf461..99fae4b95 100644 --- a/_test/index.php +++ b/_test/index.php @@ -1,7 +1,13 @@ Run more tests

"; + echo "

Run more tests

"; break; } } @@ -94,8 +100,8 @@ function DW_TESTS_PaintSuiteHeader() { case DW_TESTS_OUTPUT_HTML: default: echo "

Dokuwiki: Unit Test Suite

\n"; - echo "

Test groups"; - echo " || Test cases

"; + echo "

Test groups"; + echo " || Test cases

"; break; } } @@ -140,25 +146,25 @@ EOD; } /** OUTPUT STARTS HERE **/ - -// If it's a group test -if (isset($_GET['group'])) { - if ('all' == $_GET['group']) { - TestManager::runAllTests(DW_TESTS_GetReporter()); - } else { - TestManager::runGroupTest(ucfirst($_GET['group']), - TEST_GROUPS, - DW_TESTS_GetReporter()); - } - DW_TESTS_PaintRunMore(); - exit(); -} - -// If it's a single test case -if (isset($_GET['case'])) { - TestManager::runTestCase($_GET['case'], TEST_CASES, DW_TESTS_GetReporter()); - DW_TESTS_PaintRunMore(); - exit(); + +// If it's a group test +if (isset($_GET['group'])) { + if ('all' == $_GET['group']) { + TestManager::runAllTests(DW_TESTS_GetReporter()); + } else { + TestManager::runGroupTest(ucfirst($_GET['group']), + TEST_GROUPS, + DW_TESTS_GetReporter()); + } + DW_TESTS_PaintRunMore(); + exit(); +} + +// If it's a single test case +if (isset($_GET['case'])) { + TestManager::runTestCase($_GET['case'], TEST_CASES, DW_TESTS_GetReporter()); + DW_TESTS_PaintRunMore(); + exit(); } // Else it's the main page diff --git a/_test/lib/testmanager.php b/_test/lib/testmanager.php index 51d7f5a99..def86ca27 100644 --- a/_test/lib/testmanager.php +++ b/_test/lib/testmanager.php @@ -47,7 +47,7 @@ class TestManager { require_once SIMPLE_TEST . 'web_tester.php'; require_once SIMPLE_TEST . 'mock_objects.php'; require_once 'web.inc.php'; - require_once 'mock_functions.php'; + require_once 'mock_functions.php'; } function runAllTests(&$reporter) { @@ -286,7 +286,9 @@ class HTMLTestManager extends TestManager { "?case=" . urlencode($testcase) . "'>" . $testcase . "\n"; } - return $buffer . "\n"; + + $buffer .= "\n"; + return $buffer; } } diff --git a/inc/auth.php b/inc/auth.php index 467f4b0cd..8043feb45 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -17,6 +17,8 @@ require_once(DOKU_INC.'inc/blowfish.php'); require_once(DOKU_INC.'inc/mail.php'); + global $auth; + // load the the backend auth functions and instantiate the auth object if (@file_exists(DOKU_INC.'inc/auth/'.$conf['authtype'].'.class.php')) { require_once(DOKU_INC.'inc/auth/basic.class.php'); @@ -54,11 +56,15 @@ // do the login either by cookie or provided credentials if($conf['useacl']){ // if no credentials were given try to use HTTP auth (for SSO) - if(!$_REQUEST['u'] && !$_COOKIE[DOKU_COOKIE] && $_SERVER['PHP_AUTH_USER']){ + if(empty($_REQUEST['u']) && !$_COOKIE[DOKU_COOKIE] && $_SERVER['PHP_AUTH_USER']){ $_REQUEST['u'] = $_SERVER['PHP_AUTH_USER']; $_REQUEST['p'] = $_SERVER['PHP_AUTH_PW']; } + if (!isset($_REQUEST['u'])) $_REQUEST['u'] = ''; + if (!isset($_REQUEST['p'])) $_REQUEST['p'] = ''; + if (!isset($_REQUEST['r'])) $_REQUEST['r'] = ''; + // external trust mechanism in place? if(!is_null($auth) && $auth->canDo('external')){ $auth->trustExternal($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']); diff --git a/inc/events.php b/inc/events.php index cb3f52143..ddb0eb277 100644 --- a/inc/events.php +++ b/inc/events.php @@ -198,4 +198,5 @@ function trigger_event($name, &$data, $action=NULL, $canPreventDefault=true) { } // create the event handler +global $EVENT_HANDLER; $EVENT_HANDLER = new Doku_Event_Handler(); diff --git a/inc/init.php b/inc/init.php index 934b14dd7..783d3d9c4 100644 --- a/inc/init.php +++ b/inc/init.php @@ -25,12 +25,14 @@ //prepare config array() global $conf; - $conf = array(); + if (!defined('DOKU_UNITTEST')) { + $conf = array(); - // load the config file(s) - require_once(DOKU_CONF.'dokuwiki.php'); - if(@file_exists(DOKU_CONF.'local.php')){ - require_once(DOKU_CONF.'local.php'); + // load the config file(s) + require_once(DOKU_CONF.'dokuwiki.php'); + if(@file_exists(DOKU_CONF.'local.php')){ + require_once(DOKU_CONF.'local.php'); + } } //prepare language array diff --git a/inc/pageutils.php b/inc/pageutils.php index a478ecd3a..aacee1b13 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -21,7 +21,7 @@ function getID($param='id',$clean=true){ global $conf; - $id = $_REQUEST[$param]; + $id = isset($_REQUEST[$param]) ? $_REQUEST[$param] : null; //construct page id from request URI if(empty($id) && $conf['userewrite'] == 2){ @@ -301,7 +301,11 @@ function resolve_pageid($ns,&$page,&$exists){ $exists = false; //keep hashlink if exists then clean both parts - list($page,$hash) = split('#',$page,2); + if (strpos($page,'#')) { + list($page,$hash) = split('#',$page,2); + } else { + $hash = ''; + } $hash = cleanID($hash); $page = resolve_id($ns,$page,false); // resolve but don't clean, yet diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 519336caa..602ef1b6d 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1341,7 +1341,7 @@ class Doku_Handler_Block { function Doku_Handler_Block(){ global $DOKU_PLUGINS; //check if syntax plugins were loaded - if(!is_array($DOKU_PLUGINS['syntax'])) return; + if(empty($DOKU_PLUGINS['syntax'])) return; foreach($DOKU_PLUGINS['syntax'] as $n => $p){ $ptype = $p->getPType(); if($ptype == 'block'){ diff --git a/inc/pluginutils.php b/inc/pluginutils.php index 4d3b5cbd6..a93cca936 100644 --- a/inc/pluginutils.php +++ b/inc/pluginutils.php @@ -7,6 +7,7 @@ */ // plugin related constants +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); $plugin_types = array('admin','syntax','action'); /** @@ -67,7 +68,7 @@ function &plugin_load($type,$name){ //plugin already loaded? - if($DOKU_PLUGINS[$type][$name] != null){ + if(!empty($DOKU_PLUGINS[$type][$name])){ return $DOKU_PLUGINS[$type][$name]; } -- cgit v1.2.3