Skip to content
Snippets Groups Projects
Commit d59108b9 authored by Tobias Sarnowski's avatar Tobias Sarnowski
Browse files

removed deprecated old test framework

parent 96199bdf
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 1862 deletions
--------------------------------------------------------------------------------
Dokuwiki Unit Test Suite
--------------------------------------------------------------------------------
$Date: 2004/02/14 02:14:50 $
Credits: to the WACT team - http://www.phpwact.org, from whom the basis of
this test suite was stolen
--------------------------------------------------------------------------------
INSTALLING & SETUP
1. Grab a copy of the SimpleTest unit testing framework an extract somewhere
http://www.lastcraft.com/simple_test.php
or
http://sourceforge.net/projects/simpletest
2. Edit ./tests.ini
- TEST_ENABLED - set to "1" to allow the test suite to be used
by vistors to your site. Generally best to leave as 0 for
a productive site - running tests alot will hammer the server
Note: you will still be able to run the tests from the command
line even when this is set to 0
- WEB_TEST_URL - this is for running "web tests" where SimpleTest
acts as a web browser and executes HTTP requests against pages.
Should point at your Dokuwiki URL e.g.
http://localhost/dokuwiki
- PROXY - if you're behind a proxy, specify it here
Note: username / password are optional e.g.
http://proxyuser:proxypwd@proxy.yourdomain.com:8080
- REMOTE_TEST_URL - it's possible to run the full test suite
remotely (over HTTP) with some XML goodness. This should
point at the URL of the test suite you want to test
See the following URL for more info;
http://www.sitepoint.com/blogs/2004/06/15/simple-test-remote-testing/
- Simple Test
Update the library_path to point at the directory where you installed
Simple Test
--------------------------------------------------------------------------------
RUNNING THE TESTS
You can run the tests in three ways. From the command line:
$ ./runtests.php -h
Using a web browser;
http://localhost/dokuwiki/_test/index.php
As remote tests run on a remote serveri (specified in tests.ini with REMOTE_TEST_URL) and driven locally from the command line using;
$ ./remotetests.php -h
--------------------------------------------------------------------------------
ADDING TESTS
The test cases are kept in the './cases' directory in a directory structure
mirroring that of the Dokuwiki's
Files with the extension .group.php are group tests (collections of
one or more seperate unit test files) - there should be one group
test per file in Dokuwiki's real directory.
Individual tests files have the extension .test.php
To add tests, create a .test.php file in the correct directory under ./cases
Probably best to use one of the existing scripts as a basis
The test will not be executable via one of the test runners (see above).
To add it to a group of tests, modify the corresponding .group.php file.
One exception to the naming convention - files named .webtest.php and
.webgroup.php are run using SimpleTest's browser simulator.
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/auth.php';
require_once DOKU_INC.'inc/auth/basic.class.php';
class auth_acl_test extends UnitTestCase {
var $oldConf;
var $oldAuthAcl;
function setup() {
global $conf;
global $AUTH_ACL;
global $auth;
$this->oldConf = $conf;
$this->oldAuthAcl = $AUTH_ACL;
$auth = new auth_basic();
}
function teardown() {
global $conf;
global $AUTH_ACL;
$conf = $this->oldConf;
$AUTH_ACL = $this->oldAuthAcl;
}
function test_restricted(){
global $conf;
global $AUTH_ACL;
$conf['superuser'] = 'john';
$conf['useacl'] = 1;
$AUTH_ACL = array(
'* @ALL 0',
'* @user 8',
);
// anonymous user
$this->assertEqual(auth_aclcheck('page', '',array()), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:page','',array()), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:*', '',array()), AUTH_NONE);
// user with no matching group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo')), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo')), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo')), AUTH_NONE);
// user with matching group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo','user')), AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo','user')), AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo','user')), AUTH_UPLOAD);
// super user
$this->assertEqual(auth_aclcheck('page', 'john',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','john',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'john',array('foo')), AUTH_ADMIN);
}
function test_restricted_ropage(){
global $conf;
global $AUTH_ACL;
$conf['superuser'] = 'john';
$conf['useacl'] = 1;
$AUTH_ACL = array(
'* @ALL 0',
'* @user 8',
'namespace:page @user 1',
);
// anonymous user
$this->assertEqual(auth_aclcheck('page', '',array()), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:page','',array()), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:*', '',array()), AUTH_NONE);
// user with no matching group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo')), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo')), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo')), AUTH_NONE);
// user with matching group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo','user')), AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo','user')), AUTH_READ);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo','user')), AUTH_UPLOAD);
// super user
$this->assertEqual(auth_aclcheck('page', 'john',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','john',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'john',array('foo')), AUTH_ADMIN);
}
function test_aclexample(){
global $conf;
global $AUTH_ACL;
$conf['superuser'] = 'john';
$conf['useacl'] = 1;
$AUTH_ACL = array(
'* @ALL 4',
'* bigboss 16',
'start @ALL 1',
'marketing:* @marketing 8',
'devel:* @ALL 0',
'devel:* @devel 8',
'devel:* bigboss 16',
'devel:funstuff bigboss 0',
'devel:* @marketing 1',
'devel:marketing @marketing 2',
);
$this->assertEqual(auth_aclcheck('page', '' ,array()) , AUTH_CREATE);
$this->assertEqual(auth_aclcheck('page', 'bigboss' ,array('foo')) , AUTH_DELETE);
$this->assertEqual(auth_aclcheck('page', 'jill' ,array('marketing')) , AUTH_CREATE);
$this->assertEqual(auth_aclcheck('page', 'jane' ,array('devel')) , AUTH_CREATE);
$this->assertEqual(auth_aclcheck('start', '' ,array()) , AUTH_READ);
$this->assertEqual(auth_aclcheck('start', 'bigboss' ,array('foo')) , AUTH_READ);
$this->assertEqual(auth_aclcheck('start', 'jill' ,array('marketing')) , AUTH_READ);
$this->assertEqual(auth_aclcheck('start', 'jane' ,array('devel')) , AUTH_READ);
$this->assertEqual(auth_aclcheck('marketing:page', '' ,array()) , AUTH_CREATE);
$this->assertEqual(auth_aclcheck('marketing:page', 'bigboss' ,array('foo')) , AUTH_DELETE);
$this->assertEqual(auth_aclcheck('marketing:page', 'jill' ,array('marketing')) , AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('marketing:page', 'jane' ,array('devel')) , AUTH_CREATE);
$this->assertEqual(auth_aclcheck('devel:page', '' ,array()) , AUTH_NONE);
$this->assertEqual(auth_aclcheck('devel:page', 'bigboss' ,array('foo')) , AUTH_DELETE);
$this->assertEqual(auth_aclcheck('devel:page', 'jill' ,array('marketing')) , AUTH_READ);
$this->assertEqual(auth_aclcheck('devel:page', 'jane' ,array('devel')) , AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('devel:funstuff', '' ,array()) , AUTH_NONE);
$this->assertEqual(auth_aclcheck('devel:funstuff', 'bigboss' ,array('foo')) , AUTH_NONE);
$this->assertEqual(auth_aclcheck('devel:funstuff', 'jill' ,array('marketing')) , AUTH_READ);
$this->assertEqual(auth_aclcheck('devel:funstuff', 'jane' ,array('devel')) , AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('devel:marketing', '' ,array()) , AUTH_NONE);
$this->assertEqual(auth_aclcheck('devel:marketing', 'bigboss' ,array('foo')) , AUTH_DELETE);
$this->assertEqual(auth_aclcheck('devel:marketing', 'jill' ,array('marketing')) , AUTH_EDIT);
$this->assertEqual(auth_aclcheck('devel:marketing', 'jane' ,array('devel')) , AUTH_UPLOAD);
}
function test_multiadmin_restricted(){
global $conf;
global $AUTH_ACL;
$conf['superuser'] = 'john,@admin,doe,@roots';
$conf['useacl'] = 1;
$AUTH_ACL = array(
'* @ALL 0',
'* @user 8',
);
// anonymous user
$this->assertEqual(auth_aclcheck('page', '',array()), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:page','',array()), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:*', '',array()), AUTH_NONE);
// user with no matching group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo')), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo')), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo')), AUTH_NONE);
// user with matching group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo','user')), AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo','user')), AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo','user')), AUTH_UPLOAD);
// super user john
$this->assertEqual(auth_aclcheck('page', 'john',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','john',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'john',array('foo')), AUTH_ADMIN);
// super user doe
$this->assertEqual(auth_aclcheck('page', 'doe',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','doe',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'doe',array('foo')), AUTH_ADMIN);
// user with matching admin group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo','admin')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo','admin')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo','admin')), AUTH_ADMIN);
// user with matching another admin group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo','roots')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo','roots')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo','roots')), AUTH_ADMIN);
}
function test_multiadmin_restricted_ropage(){
global $conf;
global $AUTH_ACL;
$conf['superuser'] = 'john,@admin,doe,@roots';
$conf['useacl'] = 1;
$AUTH_ACL = array(
'* @ALL 0',
'* @user 8',
'namespace:page @user 1',
);
// anonymous user
$this->assertEqual(auth_aclcheck('page', '',array()), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:page','',array()), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:*', '',array()), AUTH_NONE);
// user with no matching group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo')), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo')), AUTH_NONE);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo')), AUTH_NONE);
// user with matching group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo','user')), AUTH_UPLOAD);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo','user')), AUTH_READ);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo','user')), AUTH_UPLOAD);
// super user john
$this->assertEqual(auth_aclcheck('page', 'john',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','john',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'john',array('foo')), AUTH_ADMIN);
// super user doe
$this->assertEqual(auth_aclcheck('page', 'doe',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','doe',array('foo')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'doe',array('foo')), AUTH_ADMIN);
// user with matching admin group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo','admin')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo','admin')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo','admin')), AUTH_ADMIN);
// user with matching another admin group
$this->assertEqual(auth_aclcheck('page', 'jill',array('foo','roots')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:page','jill',array('foo','roots')), AUTH_ADMIN);
$this->assertEqual(auth_aclcheck('namespace:*', 'jill',array('foo','roots')), AUTH_ADMIN);
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/auth.php';
require_once DOKU_INC.'inc/auth/basic.class.php';
class auth_admin_test_AuthInSensitive extends auth_basic {
function isCaseSensitive(){
return false;
}
}
class auth_admin_test extends UnitTestCase {
private $oldauth;
function setup() {
global $auth;
$this->oldauth = $auth;
parent::setup();
}
function setSensitive() {
global $auth;
$auth = new auth_basic;
}
function setInSensitive() {
global $auth;
$auth = new auth_admin_test_AuthInSensitive;
}
function teardown() {
global $auth;
global $conf;
global $AUTH_ACL;
unset($conf);
unset($AUTH_ACL);
$auth = $this->oldauth;
parent::teardown();
}
function test_ismanager_insensitive(){
$this->setInSensitive();
global $conf;
$conf['superuser'] = 'john,@admin,@Mötly Görls, Dörte';
$conf['manager'] = 'john,@managers,doe, @Mötly Böys, Dänny';
// anonymous user
$this->assertEqual(auth_ismanager('jill', null,false), false);
// admin or manager users
$this->assertEqual(auth_ismanager('john', null,false), true);
$this->assertEqual(auth_ismanager('doe', null,false), true);
$this->assertEqual(auth_ismanager('dörte', null,false), true);
$this->assertEqual(auth_ismanager('dänny', null,false), true);
// admin or manager groups
$this->assertEqual(auth_ismanager('jill', array('admin'),false), true);
$this->assertEqual(auth_ismanager('jill', array('managers'),false), true);
$this->assertEqual(auth_ismanager('jill', array('mötly görls'),false), true);
$this->assertEqual(auth_ismanager('jill', array('mötly böys'),false), true);
}
function test_isadmin_insensitive(){
$this->setInSensitive();
global $conf;
$conf['superuser'] = 'john,@admin,doe,@roots';
// anonymous user
$this->assertEqual(auth_ismanager('jill', null,true), false);
// admin user
$this->assertEqual(auth_ismanager('john', null,true), true);
$this->assertEqual(auth_ismanager('doe', null,true), true);
// admin groups
$this->assertEqual(auth_ismanager('jill', array('admin'),true), true);
$this->assertEqual(auth_ismanager('jill', array('roots'),true), true);
$this->assertEqual(auth_ismanager('john', array('admin'),true), true);
$this->assertEqual(auth_ismanager('doe', array('admin'),true), true);
}
function test_ismanager_sensitive(){
$this->setSensitive();
global $conf;
$conf['superuser'] = 'john,@admin,@Mötly Görls, Dörte';
$conf['manager'] = 'john,@managers,doe, @Mötly Böys, Dänny';
// anonymous user
$this->assertEqual(auth_ismanager('jill', null,false), false);
// admin or manager users
$this->assertEqual(auth_ismanager('john', null,false), true);
$this->assertEqual(auth_ismanager('doe', null,false), true);
$this->assertEqual(auth_ismanager('dörte', null,false), false);
$this->assertEqual(auth_ismanager('dänny', null,false), false);
// admin or manager groups
$this->assertEqual(auth_ismanager('jill', array('admin'),false), true);
$this->assertEqual(auth_ismanager('jill', array('managers'),false), true);
$this->assertEqual(auth_ismanager('jill', array('mötly görls'),false), false);
$this->assertEqual(auth_ismanager('jill', array('mötly böys'),false), false);
}
function test_isadmin_sensitive(){
$this->setSensitive();
global $conf;
$conf['superuser'] = 'john,@admin,doe,@roots';
// anonymous user
$this->assertEqual(auth_ismanager('jill', null,true), false);
// admin user
$this->assertEqual(auth_ismanager('john', null,true), true);
$this->assertEqual(auth_ismanager('Doe', null,true), false);
// admin groups
$this->assertEqual(auth_ismanager('jill', array('admin'),true), true);
$this->assertEqual(auth_ismanager('jill', array('roots'),true), true);
$this->assertEqual(auth_ismanager('john', array('admin'),true), true);
$this->assertEqual(auth_ismanager('doe', array('admin'),true), true);
$this->assertEqual(auth_ismanager('Doe', array('admin'),true), true);
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/auth.php';
class auth_nameencode_test extends UnitTestCase {
function teardown() {
global $cache_authname;
$cache_authname = array();
}
function test_simple(){
$in = 'hey$you';
$out = 'hey%24you';
$this->assertEqual(auth_nameencode($in),$out);
}
function test_quote(){
$in = 'hey"you';
$out = 'hey%22you';
$this->assertEqual(auth_nameencode($in),$out);
}
function test_complex(){
$in = 'hey $ you !$%! foo ';
$out = 'hey%20%24%20you%20%21%24%25%21%20foo%20';
$this->assertEqual(auth_nameencode($in),$out);
}
function test_complexutf8(){
$in = 'häü $ yü !$%! foo ';
$out = 'häü%20%24%20yü%20%21%24%25%21%20foo%20';
$this->assertEqual(auth_nameencode($in),$out);
}
function test_groupskipon(){
$in = '@hey$you';
$out = '@hey%24you';
$this->assertEqual(auth_nameencode($in,true),$out);
}
function test_groupskipoff(){
$in = '@hey$you';
$out = '%40hey%24you';
$this->assertEqual(auth_nameencode($in),$out);
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/auth.php';
class auth_password_test extends UnitTestCase {
// hashes for the password foo$method, using abcdefgh as salt
var $passes = array(
'smd5' => '$1$abcdefgh$SYbjm2AEvSoHG7Xapi8so.',
'apr1' => '$apr1$abcdefgh$C/GzYTF4kOVByYLEoD5X4.',
'md5' => '8fa22d62408e5351553acdd91c6b7003',
'sha1' => 'b456d3b0efd105d613744ffd549514ecafcfc7e1',
'ssha' => '{SSHA}QMHG+uC7bHNYKkmoLbNsNI38/dJhYmNk',
'lsmd5' => '{SMD5}HGbkPrkWgy9KgcRGWlrsUWFiY2RlZmdo',
'crypt' => 'ablvoGr1hvZ5k',
'mysql' => '4a1fa3780bd6fd55',
'my411' => '*e5929347e25f82e19e4ebe92f1dc6b6e7c2dbd29',
'kmd5' => 'a579299436d7969791189acadd86fcb716',
'pmd5' => '$P$abcdefgh1RC6Fd32heUzl7EYCG9uGw.',
'hmd5' => '$H$abcdefgh1ZbJodHxmeXVAhEzTG7IAp.',
'djangomd5' => 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158',
'djangosha1' => 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678',
);
function test_cryptPassword(){
foreach($this->passes as $method => $hash){
$info = "testing method $method";
$this->signal('failinfo',$info);
$this->assertEqual(auth_cryptPassword('foo'.$method,$method,'abcdefgh12345678912345678912345678'),$hash);
}
}
function test_verifyPassword(){
foreach($this->passes as $method => $hash){
$info = "testing method $method";
$this->signal('failinfo',$info);
$this->assertTrue(auth_verifyPassword('foo'.$method,$hash));
}
}
function test_verifySelf(){
foreach($this->passes as $method => $hash){
$info = "testing method $method";
$this->signal('failinfo',$info);
$hash = auth_cryptPassword('foo'.$method,$method);
$this->assertTrue(auth_verifyPassword('foo'.$method,$hash));
}
}
function test_bcrypt_self(){
$hash = auth_cryptPassword('foobcrypt','bcrypt');
$this->assertTrue(auth_verifyPassword('foobcrypt',$hash));
}
function test_verifyPassword_fixedbcrypt(){
$this->assertTrue(auth_verifyPassword('foobcrypt','$2a$12$uTWercxbq4sjp2xAzv3we.ZOxk51m5V/Bv5bp2H27oVFJl5neFQoC'));
}
function test_verifyPassword_nohash(){
$this->assertTrue(auth_verifyPassword('foo','$1$$n1rTiFE0nRifwV/43bVon/'));
}
function test_verifyPassword_fixedpmd5(){
$this->assertTrue(auth_verifyPassword('test12345','$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0'));
$this->assertTrue(auth_verifyPassword('test12345','$H$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0'));
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/common.php';
class common_cleanText extends UnitTestCase {
function test_unix(){
$unix = 'one
two
three';
$this->assertEqual($unix,cleanText($unix));
}
function test_win(){
$unix = 'one
two
three';
$win = 'one
two
three';
$this->assertEqual(bin2hex($unix),'6f6e650a2020202020202020202020202020202074776f0a0a202020202020202020202020202020207468726565');
$this->assertEqual(bin2hex($win),'6f6e650d0a2020202020202020202020202020202074776f0d0a0d0a202020202020202020202020202020207468726565');
$this->assertNotEqual($unix,$win);
$this->assertEqual($unix,cleanText($win));
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/common.php';
class common_clientIP_test extends UnitTestCase {
function test_simple_all(){
$_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(),$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);
}
function test_malicious(){
$_SERVER['REMOTE_ADDR'] = '';
$_SERVER['HTTP_X_REAL_IP'] = '';
$_SERVER['HTTP_X_FORWARDED_FOR'] = '<?php set_time_limit(0);echo \'my_delim\';passthru(123.123.123.123);die;?>';
$out = '0.0.0.0';
$this->assertEqual(clientIP(),$out);
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/common.php';
class common_obfuscate_test extends UnitTestCase {
function test_none(){
global $conf;
$conf['mailguard'] = 'none';
$this->assertEqual(obfuscate('jon-doe@example.com'), 'jon-doe@example.com');
}
function test_hex(){
global $conf;
$conf['mailguard'] = 'hex';
$this->assertEqual(obfuscate('jon-doe@example.com'),
'&#x6a;&#x6f;&#x6e;&#x2d;&#x64;&#x6f;&#x65;&#x40;&#x65;&#x78;&#x61;&#x6d;&#x70;&#x6c;&#x65;&#x2e;&#x63;&#x6f;&#x6d;');
}
function test_visible(){
global $conf;
$conf['mailguard'] = 'visible';
$this->assertEqual(obfuscate('jon-doe@example.com'), 'jon [dash] doe [at] example [dot] com');
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/common.php';
class common_pagetemplate_test extends UnitTestCase {
function test_none(){
global $conf;
$conf['sepchar'] = '-';
$data = array(
'id' => 'page-id-long',
'tpl' => '"@PAGE@" "@!PAGE@" "@!!PAGE@" "@!PAGE!@"',
);
$this->assertEqual(parsePageTemplate($data), '"page id long" "Page id long" "Page Id Long" "PAGE ID LONG"');
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/DifferenceEngine.php';
class differenceengine_test extends UnitTestCase {
function test_white_between_words(){
// From FS#2161
global $lang;
$df = new Diff(explode("\n","example"),
explode("\n","example example2"));
$idf = new InlineDiffFormatter();
$tdf = new TableDiffFormatter();
$this->assertEqual($idf->format($df), '<tr><td colspan="4" class="diff-blockheader">@@ ' . $lang['line'] .
' -1 +1 @@&nbsp;<span class="diff-deletedline"><del>' . $lang['deleted'] .
'</del></span>&nbsp;<span class="diff-addedline">' . $lang['created'] .
'</span></td></tr>
<tr><td colspan="4">example&nbsp;<span class="diff-addedline">example2</span></td></tr>
');
$this->assertEqual($tdf->format($df),
'<tr><td class="diff-blockheader" colspan="2">' . $lang['line'] . ' 1:</td>
<td class="diff-blockheader" colspan="2">' . $lang['line'] . ' 1:</td>
</tr>
<tr><td>-</td><td class="diff-deletedline">example</td><td>+</td><td class="diff-addedline">example&nbsp;<strong>example2</strong></td></tr>
');
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
class form_test extends UnitTestCase {
function _testform() {
$form = new Doku_Form(array('id' => 'dw__testform', 'action' => '/test'));
$form->startFieldset('Test');
$form->addHidden('summary', 'changes &c');
$form->addElement(form_makeTextField('t', 'v', 'Text', 'text__id', 'block'));
$form->addElement(form_makeCheckboxField('r', '1', 'Check', 'check__id', 'simple'));
$form->addElement(form_makeButton('submit', 'save', 'Save', array('accesskey'=>'s')));
$form->addElement(form_makeButton('submit', 'cancel', 'Cancel'));
$form->endFieldset();
return $form;
}
function _realoutput() {
global $lang;
$realoutput = '<form id="dw__testform" action="/test" method="post" ';
$realoutput .= 'accept-charset="'.$lang['encoding'].'">';
$realoutput .= "\n";
$realoutput .= '<div class="no"><input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
$realoutput .= '<input type="hidden" name="summary" value="changes &amp;c" />';
$realoutput .= "\n";
$realoutput .= "<fieldset ><legend>Test</legend>\n";
$realoutput .= '<label class="block" for="text__id"><span>Text</span> ';
$realoutput .= '<input type="text" id="text__id" name="t" value="v" class="edit" /></label><br />';
$realoutput .= "\n";
$realoutput .= '<label class="simple" for="check__id">';
$realoutput .= '<input type="checkbox" id="check__id" name="r" value="1" /> ';
$realoutput .= '<span>Check</span></label>';
$realoutput .= "\n";
$realoutput .= '<input name="do[save]" type="submit" value="Save" class="button" accesskey="s" title="Save [S]" />';
$realoutput .= "\n";
$realoutput .= '<input name="do[cancel]" type="submit" value="Cancel" class="button" />';
$realoutput .= "\n";
$realoutput .= "</fieldset>\n</div></form>\n";
return $realoutput;
}
function _ignoreTagWS($data){
return preg_replace('/>\s+</','><',$data);
}
function test_form_print() {
$form = $this->_testform();
ob_start();
$form->printForm();
$output = ob_get_contents();
ob_end_clean();
$form->addHidden('sectok', getSecurityToken());
$this->assertEqual($this->_ignoreTagWS($output),$this->_ignoreTagWS($this->_realoutput()));
}
function test_get_element_at() {
$form = $this->_testform();
$e1 =& $form->getElementAt(1);
$this->assertEqual($e1, array('_elem'=>'textfield',
'_text'=>'Text',
'_class'=>'block',
'id'=>'text__id',
'name'=>'t',
'value'=>'v',
'class'=>'edit'));
$e2 =& $form->getElementAt(99);
$this->assertEqual($e2, array('_elem'=>'closefieldset'));
}
function test_find_element_by_type() {
$form = $this->_testform();
$this->assertEqual($form->findElementByType('button'), 3);
$this->assertFalse($form->findElementByType('text'));
}
function test_find_element_by_id() {
$form = $this->_testform();
$this->assertEqual($form->findElementById('check__id'), 2);
$this->assertFalse($form->findElementById('dw__testform'));
}
function test_find_element_by_attribute() {
$form = $this->_testform();
$this->assertEqual($form->findElementByAttribute('value','Cancel'), 4);
$this->assertFalse($form->findElementByAttribute('name','cancel'));
}
function test_close_fieldset() {
$form = new Doku_Form(array('id' => 'dw__testform', 'action' => '/test'));
$form->startFieldset('Test');
$form->addHidden('summary', 'changes &c');
$form->addElement(form_makeTextField('t', 'v', 'Text', 'text__id', 'block'));
$form->addElement(form_makeCheckboxField('r', '1', 'Check', 'check__id', 'simple'));
$form->addElement(form_makeButton('submit', 'save', 'Save', array('accesskey'=>'s')));
$form->addElement(form_makeButton('submit', 'cancel', 'Cancel'));
ob_start();
$form->printForm();
$output = ob_get_contents();
ob_end_clean();
$this->assertEqual($this->_ignoreTagWS($output),$this->_ignoreTagWS($this->_realoutput()));
}
}
<?php
require_once DOKU_INC.'inc/html.php';
if (!extension_loaded('runkit')) {
SimpleTestOptions::ignore('html_hilight_test');
trigger_error('Skipping html_hilight_test - http://www.php.net/runkit required');
}
function html_hilight_test_unslash($string,$char="'"){
$str= str_replace('\\'.$char,$char,$string);
return $str;
}
class html_hilight_test extends UnitTestCase{
function setup() {
if ( function_exists('unslash') ) {
runkit_function_rename('unslash','html_hilight_test_unslash_real');
}
runkit_function_rename('html_hilight_test_unslash','unslash');
}
function teardown() {
runkit_function_rename('unslash','html_hilight_test_unslash');
if ( function_exists('html_hilight_test_unslash_real') ) {
runkit_function_rename('html_hilight_test_unslash_real','unslash');
}
}
function testHighlightOneWord() {
$html = 'Foo bar Foo';
$this->assertPattern(
'/Foo <span.*>bar<\/span> Foo/',
html_hilight($html,'bar')
);
}
function testHighlightTwoWords() {
$html = 'Foo bar Foo php Foo';
$this->assertPattern(
'/Foo <span.*>bar<\/span> Foo <span.*>php<\/span> Foo/',
html_hilight($html,array('bar','php'))
);
}
function testHighlightTwoWordsHtml() {
$html = 'Foo <b>bar</b> <i>Foo</i> php Foo';
$this->assertPattern(
'/Foo <b><span.*>bar<\/span><\/b> <i>Foo<\/i> <span.*>php<\/span> Foo/',
html_hilight($html,array('bar','php'))
);
}
function testNoHighlight() {
$html = 'Foo bar Foo';
$this->assertPattern(
'/Foo bar Foo/',
html_hilight($html,'php')
);
}
function testHighlightPHP() {
$html = 'Foo $_GET[\'bar\'] Foo';
$this->assertEqual(
'Foo <span class="search_hit">$_GET[\'bar\']</span> Foo',
html_hilight($html,'$_GET[\'bar\']')
);
}
function testMatchAttribute() {
$html = 'Foo <b class="x">bar</b> Foo';
$this->assertPattern(
'/Foo <b class="x">bar<\/b> Foo/',
html_hilight($html,'class="x"')
);
}
function testMatchAttributeWord() {
$html = 'Foo <b class="x">bar</b> Foo';
$this->assertEqual(
'Foo <b class="x">bar</b> Foo',
html_hilight($html,'class="x">bar')
);
}
function testRegexInjection() {
$html = 'Foo bar Foo';
$this->assertPattern(
'/Foo bar Foo/',
html_hilight($html,'*')
);
}
function testRegexInjectionSlash() {
$html = 'Foo bar Foo';
$this->assertPattern(
'/Foo bar Foo/',
html_hilight($html,'x/')
);
}
}
<?php
require_once DOKU_INC.'inc/indexer.php';
class indexer_idx_indexlengths_test extends UnitTestCase {
/**
* Test the function with an array of one value
*/
function test_oneWord(){
global $conf;
$filter[8] = array('dokuwiki');
// one word should return the index
$ref[] = 8;
sort($ref);
$result = idx_indexLengths(&$filter);
sort($result);
$this->assertIdentical($result, $ref);
}
/**
* Test the function with an array of values
*/
function test_moreWords() {
global $conf;
$filter = array( 4 => array('test'), 8 => array('dokuwiki'), 7 => array('powered'));
// more words should return the indexes
$ref = array(4, 7, 8);
sort($ref);
$result = idx_indexLengths(&$filter);
sort($result);
$this->assertIdentical($result, $ref);
}
/**
* Test a minimal value in case of wildcard search
*/
function test_minValue() {
global $conf;
$filter = 5;
// construction of the list of the index to compare
$dir = @opendir($conf['indexdir']);
$ref = array();
while (($f = readdir($dir)) !== false) {
if (substr($f,0,1) == 'i' && substr($f,-4) == '.idx'){
$i = substr($f,1,-4);
if (is_numeric($i) && $i >= $filter)
$ref[] = (int)$i;
}
}
closedir($dir);
sort($ref);
$result = idx_indexLengths(&$filter);
sort($result);
$this->assertIdentical($result, $ref);
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
class init_fullpath_test extends UnitTestCase {
function test_unix_paths(){
$base = $_SERVER['SCRIPT_FILENAME'];
$_SERVER['SCRIPT_FILENAME'] = '/absolute/path/self.php';
$GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS'] = false;
// paths to check
$tests = array(
'/foo/bar/baz' => '/foo/bar/baz',
'/foo//bar/baz' => '/foo/bar/baz',
'/foo/../bar/baz' => '/bar/baz',
'/foo/./bar/baz' => '/foo/bar/baz',
'/foo/bar/..' => '/foo',
'/foo/bar/../../../baz' => '/baz',
'foo/bar/baz' => '/absolute/path/foo/bar/baz',
'foo//bar/baz' => '/absolute/path/foo/bar/baz',
'foo/../bar/baz' => '/absolute/path/bar/baz',
'foo/./bar/baz' => '/absolute/path/foo/bar/baz',
'foo/bar/..' => '/absolute/path/foo',
'foo/bar/../../../baz' => '/absolute/baz',
);
foreach($tests as $from => $to){
$info = "Testing '$from' resulted in '".fullpath($from)."'";
$this->signal('failinfo',$info);
$this->assertEqual(fullpath($from),$to);
}
$_SERVER['SCRIPT_FILENAME'] = $base;
unset($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']);
}
function test_windows_paths(){
$base = $_SERVER['SCRIPT_FILENAME'];
$_SERVER['SCRIPT_FILENAME'] = '/absolute/path/self.php';
$GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS'] = true;
// paths to check
$tests = array(
'c:foo/bar/baz' => 'c:/foo/bar/baz',
'c:foo//bar/baz' => 'c:/foo/bar/baz',
'c:foo/../bar/baz' => 'c:/bar/baz',
'c:foo/./bar/baz' => 'c:/foo/bar/baz',
'c:foo/bar/..' => 'c:/foo',
'c:foo/bar/../../../baz' => 'c:/baz',
'c:/foo/bar/baz' => 'c:/foo/bar/baz',
'c:/foo//bar/baz' => 'c:/foo/bar/baz',
'c:/foo/../bar/baz' => 'c:/bar/baz',
'c:/foo/./bar/baz' => 'c:/foo/bar/baz',
'c:/foo/bar/..' => 'c:/foo',
'c:/foo/bar/../../../baz' => 'c:/baz',
'c:\\foo\\bar\\baz' => 'c:/foo/bar/baz',
'c:\\foo\\\\bar\\baz' => 'c:/foo/bar/baz',
'c:\\foo\\..\\bar\\baz' => 'c:/bar/baz',
'c:\\foo\\.\\bar\\baz' => 'c:/foo/bar/baz',
'c:\\foo\\bar\\..' => 'c:/foo',
'c:\\foo\\bar\\..\\..\\..\\baz' => 'c:/baz',
'\\\\server\\share/foo/bar/baz' => '\\\\server\\share/foo/bar/baz',
'\\\\server\\share/foo//bar/baz' => '\\\\server\\share/foo/bar/baz',
'\\\\server\\share/foo/../bar/baz' => '\\\\server\\share/bar/baz',
'\\\\server\\share/foo/./bar/baz' => '\\\\server\\share/foo/bar/baz',
'\\\\server\\share/foo/bar/..' => '\\\\server\\share/foo',
'\\\\server\\share/foo/bar/../../../baz' => '\\\\server\\share/baz',
);
foreach($tests as $from => $to){
$info = "Testing '$from' resulted in '".fullpath($from)."'";
$this->signal('failinfo',$info);
$this->assertEqual(fullpath($from),$to);
}
$_SERVER['SCRIPT_FILENAME'] = $base;
unset($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']);
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
class init_getBaseURL_test extends UnitTestCase {
/**
* Apache, mod_php, subdirectory
*
* data provided by Andreas Gohr <andi@splitbrain.org>
*/
function test1(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/var/www/';
$_SERVER['HTTP_HOST'] = 'xerxes.my.home';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/doku.php';
$_SERVER['REQUEST_URI'] = '/dokuwiki/doku.php?do=debug';
$_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php';
$_SERVER['PATH_INFO'] = null;
$_SERVER['PATH_TRANSLATED'] = '/var/www/dokuwiki/doku.php';
$_SERVER['PHP_SELF'] = '/dokuwiki/doku.php';
$this->assertEqual(getBaseURL(),'/dokuwiki/');
}
/**
* Apache, CGI, mod_userdir, subdirectory
*
* data provided by Hilko Bengen <bengen@hilluzination.de>
*/
function test2(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/var/www/localhost';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SCRIPT_FILENAME'] = '/usr/lib/cgi-bin/php4';
$_SERVER['REQUEST_URI'] = '/~bengen/dokuwiki/doku.php?do=debug';
$_SERVER['SCRIPT_NAME'] = '/cgi-bin/php4';
$_SERVER['PATH_INFO'] = '/~bengen/dokuwiki/doku.php';
$_SERVER['PATH_TRANSLATED'] = '/home/bengen/public_html/dokuwiki/doku.php';
$_SERVER['PHP_SELF'] = '/~bengen/dokuwiki/doku.php';
$this->assertEqual(getBaseURL(),'/~bengen/dokuwiki/');
}
/**
* Apache, FastCGI, mod_userdir, subdirectory
*
* data provided by Hilko Bengen <bengen@hilluzination.de>
*/
function test3(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/var/www/localhost';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SCRIPT_FILENAME'] = '/var/run/php-fastcgi/fcgi-bin/bengen/php4';
$_SERVER['REQUEST_URI'] = '/~bengen/dokuwiki/doku.php?do=debug';
$_SERVER['SCRIPT_NAME'] = '/fcgi-bin/php4-bengen';
$_SERVER['PATH_INFO'] = '/~bengen/dokuwiki/doku.php';
$_SERVER['PATH_TRANSLATED'] = '/home/bengen/public_html/dokuwiki/doku.php';
$_SERVER['PHP_SELF'] = '/~bengen/dokuwiki/doku.php';
$this->assertEqual(getBaseURL(),'/~bengen/dokuwiki/');
}
/**
* Apache, mod_php, mod_userdir, subdirectory
*
* data provided by Hilko Bengen <bengen@hilluzination.de>
*/
function test4(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/var/www/localhost';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SCRIPT_FILENAME'] = '/home/bengen/public_html/dokuwiki/doku.php';
$_SERVER['REQUEST_URI'] = '/~bengen/dokuwiki/doku.php?do=debug';
$_SERVER['SCRIPT_NAME'] = '/~bengen/dokuwiki/doku.php';
$_SERVER['PATH_INFO'] = null;
$_SERVER['PATH_TRANSLATED'] = '/home/bengen/public_html/dokuwiki/doku.php';
$_SERVER['PHP_SELF'] = '/~bengen/dokuwiki/doku.php';
$this->assertEqual(getBaseURL(),'/~bengen/dokuwiki/');
}
/**
* IIS
*
* data provided by David Mach <david.mach@centrum.cz>
*/
function test5(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = null;
$_SERVER['HTTP_HOST'] = 'intranet';
$_SERVER['SCRIPT_FILENAME'] = null;
$_SERVER['REQUEST_URI'] = null;
$_SERVER['SCRIPT_NAME'] = '/wiki/doku.php';
$_SERVER['PATH_INFO'] = '/wiki/doku.php';
$_SERVER['PATH_TRANSLATED'] = 'C:\\Inetpub\\wwwroot\\wiki\\doku.php';
$_SERVER['PHP_SELF'] = '/wiki/doku.php';
$this->assertEqual(getBaseURL(),'/wiki/');
}
/**
* Apache 2, mod_php, real URL rewriting, useslash (bug #292)
*
* data provided by Ted <bugsX2904@elcsplace.com>
*/
function test6(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/home/websites/wiki/htdocs';
$_SERVER['HTTP_HOST'] = 'wiki.linuxwan.net';
$_SERVER['SCRIPT_FILENAME'] = '/home/websites/wiki/htdocs/doku.php';
$_SERVER['REQUEST_URI'] = '/wiki/syntax?do=debug';
$_SERVER['SCRIPT_NAME'] = '/wiki/syntax';
$_SERVER['PATH_INFO'] = null;
$_SERVER['PATH_TRANSLATED'] = null;
$_SERVER['PHP_SELF'] = '/wiki/syntax';
$this->assertEqual(getBaseURL(),'/');
}
/**
* lighttpd, fastcgi
*
* data provided by Andreas Gohr <andi@splitbrain.org>
*/
function test7(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/var/www/';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/doku.php';
$_SERVER['REQUEST_URI'] = '/dokuwiki/doku.php?do=debug';
$_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php';
$_SERVER['PATH_INFO'] = '';
$_SERVER['PATH_TRANSLATED'] = null;
$_SERVER['PHP_SELF'] = '';
$this->assertEqual(getBaseURL(),'/dokuwiki/');
}
/**
* Apache, mod_php, Pseudo URL rewrite, useslash
*
* data provided by Andreas Gohr <andi@splitbrain.org>
*/
function test8(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/var/www/';
$_SERVER['HTTP_HOST'] = 'xerxes.my.home';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/doku.php';
$_SERVER['REQUEST_URI'] = '/dokuwiki/doku.php/wiki/syntax?do=debug';
$_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php';
$_SERVER['PATH_INFO'] = '/wiki/syntax';
$_SERVER['PATH_TRANSLATED'] = '/var/www/wiki/syntax';
$_SERVER['PHP_SELF'] = '/dokuwiki/doku.php/wiki/syntax';
$this->assertEqual(getBaseURL(),'/dokuwiki/');
}
/**
* Apache, mod_php, real URL rewrite, useslash
*
* data provided by Andreas Gohr <andi@splitbrain.org>
*/
function test9(){
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/var/www/';
$_SERVER['HTTP_HOST'] = 'xerxes.my.home';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/doku.php';
$_SERVER['REQUEST_URI'] = '/dokuwiki/wiki/syntax?do=debug';
$_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php';
$_SERVER['PATH_INFO'] = null;
$_SERVER['PATH_TRANSLATED'] = '/var/www/dokuwiki/doku.php';
$_SERVER['PHP_SELF'] = '/dokuwiki/doku.php';
$this->assertEqual(getBaseURL(),'/dokuwiki/');
}
/**
* Possible user settings of $conf['baseurl'] & absolute baseURL required
*
* data provided by Andreas Gohr <andi@splitbrain.org>
*/
function test10(){
// values for $conf['baseurl'] and expected results
$tests = array(
'http://www.mysite.com' => 'http://www.mysite.com/dokuwiki/',
'http://www.mysite.com/' => 'http://www.mysite.com/dokuwiki/',
'http://www.mysite.com/path/to/wiki' => 'http://www.mysite.com/path/to/wiki/dokuwiki/',
'http://www.mysite.com/path/to/wiki/' => 'http://www.mysite.com/path/to/wiki/dokuwiki/',
);
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$_SERVER['DOCUMENT_ROOT'] = '/var/www/';
$_SERVER['HTTP_HOST'] = 'xerxes.my.home';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/doku.php';
$_SERVER['REQUEST_URI'] = '/dokuwiki/wiki/syntax?do=debug';
$_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php';
$_SERVER['PATH_INFO'] = null;
$_SERVER['PATH_TRANSLATED'] = '/var/www/dokuwiki/doku.php';
$_SERVER['PHP_SELF'] = '/dokuwiki/doku.php';
foreach ($tests as $test => $correct_result) {
$conf['baseurl'] = $test;
$this->assertEqual(getBaseURL(true),$correct_result);
}
}
/**
* Possible user settings of $conf['baseurl'] & absolute baseURL required
*
* data provided by Andreas Gohr <andi@splitbrain.org>
*/
function test11(){
// values for $conf['baseurl'] and expected results
$tests = array(
'http://www.mysite.com' => 'http://www.mysite.com/dokuwiki/',
'http://www.mysite.com/' => 'http://www.mysite.com/dokuwiki/',
'http://www.mysite.com/path/to/wiki' => 'http://www.mysite.com/path/to/wiki/dokuwiki/',
'http://www.mysite.com/path/to/wiki/' => 'http://www.mysite.com/path/to/wiki/dokuwiki/',
);
global $conf;
$conf['basedir'] = '/dokuwiki';
$conf['baseurl'] = '';
$_SERVER['DOCUMENT_ROOT'] = '/var/www/';
$_SERVER['HTTP_HOST'] = 'xerxes.my.home';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/doku.php';
$_SERVER['REQUEST_URI'] = '/dokuwiki/wiki/syntax?do=debug';
$_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php';
$_SERVER['PATH_INFO'] = null;
$_SERVER['PATH_TRANSLATED'] = '/var/www/dokuwiki/doku.php';
$_SERVER['PHP_SELF'] = '/dokuwiki/doku.php';
foreach ($tests as $test => $correct_result) {
$conf['baseurl'] = $test;
$this->assertEqual(getBaseURL(true),$correct_result);
}
}
/**
* Absolute URL with IPv6 domain name.
* lighttpd, fastcgi
*
* data provided by Michael Hamann <michael@content-space.de>
*/
function test12() {
global $conf;
$conf['basedir'] = '';
$conf['baseurl'] = '';
$conf['canonical'] = 0;
$_SERVER['DOCUMENT_ROOT'] = '/srv/http/';
$_SERVER['HTTP_HOST'] = '[fd00::6592:39ed:a2ed:2c78]';
$_SERVER['SCRIPT_FILENAME'] = '/srv/http/~michitux/dokuwiki/doku.php';
$_SERVER['REQUEST_URI'] = '/~michitux/dokuwiki/doku.php?do=debug';
$_SERVER['SCRIPT_NAME'] = '/~michitux/dokuwiki/doku.php';
$_SERVER['PATH_INFO'] = null;
$_SERVER['PATH_TRANSLATED'] = null;
$_SERVER['PHP_SELF'] = '/~michitux/dokuwiki/doku.php';
$_SERVER['SERVER_PORT'] = '80';
$_SERVER['SERVER_NAME'] = '[fd00';
$this->assertEqual(getBaseURL(true), 'http://[fd00::6592:39ed:a2ed:2c78]/~michitux/dokuwiki/');
}
}
//Setup VIM: ex: et ts=2 :
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/IXR_Library.php';
class ixr_library_date_test extends UnitTestCase {
function test_parseIso(){
// multiple tests
$tests = array(
// full datetime, different formats
array('2010-08-17T09:23:14', 1282036994),
array('20100817T09:23:14', 1282036994),
array('2010-08-17 09:23:14', 1282036994),
array('20100817 09:23:14', 1282036994),
array('2010-08-17T09:23:14Z', 1282036994),
array('20100817T09:23:14Z', 1282036994),
// no seconds
array('2010-08-17T09:23', 1282036980),
array('20100817T09:23', 1282036980),
// no time
array('2010-08-17', 1282003200),
//array('20100817', 1282003200), #this will NOT be parsed, but is assumed to be timestamp
);
foreach($tests as $test){
$dt = new IXR_Date($test[0]);
$this->assertEqual($dt->getTimeStamp(),$test[1]);
}
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/IXR_Library.php';
class ixr_library_ixr_message_test extends UnitTestCase {
function test_untypedvalue1(){
$xml = '<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>wiki.getBackLinks</methodName><params><param><value> change </value></param></params></methodCall>';
$ixrmsg = new IXR_Message($xml);
$ixrmsg->parse();
$this->assertEqual($ixrmsg->messageType,'methodCall');
$this->assertEqual($ixrmsg->methodName,'wiki.getBackLinks');
$this->assertEqual($ixrmsg->params,array(' change '));
}
function test_untypedvalue2(){
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>wiki.getBackLinks</methodName>
<params>
<param>
<value> change </value>
</param>
</params>
</methodCall>';
$ixrmsg = new IXR_Message($xml);
$ixrmsg->parse();
$this->assertEqual($ixrmsg->messageType,'methodCall');
$this->assertEqual($ixrmsg->methodName,'wiki.getBackLinks');
$this->assertEqual($ixrmsg->params,array(' change '));
}
function test_stringvalue1(){
$xml = '<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>wiki.getBackLinks</methodName><params><param><value><string> change </string></value></param></params></methodCall>';
$ixrmsg = new IXR_Message($xml);
$ixrmsg->parse();
$this->assertEqual($ixrmsg->messageType,'methodCall');
$this->assertEqual($ixrmsg->methodName,'wiki.getBackLinks');
$this->assertEqual($ixrmsg->params,array(' change '));
}
function test_stringvalue2(){
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>wiki.getBackLinks</methodName>
<params>
<param>
<value>
<string> change </string>
</value>
</param>
</params>
</methodCall>';
$ixrmsg = new IXR_Message($xml);
$ixrmsg->parse();
$this->assertEqual($ixrmsg->messageType,'methodCall');
$this->assertEqual($ixrmsg->methodName,'wiki.getBackLinks');
$this->assertEqual($ixrmsg->params,array(' change '));
}
function test_emptyvalue1(){
$xml = '<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>wiki.getBackLinks</methodName><params><param><value><string></string></value></param></params></methodCall>';
$ixrmsg = new IXR_Message($xml);
$ixrmsg->parse();
$this->assertEqual($ixrmsg->messageType,'methodCall');
$this->assertEqual($ixrmsg->methodName,'wiki.getBackLinks');
$this->assertEqual($ixrmsg->params,array(''));
}
function test_emptyvalue2(){
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>wiki.getBackLinks</methodName>
<params>
<param>
<value>
<string></string>
</value>
</param>
</params>
</methodCall>';
$ixrmsg = new IXR_Message($xml);
$ixrmsg->parse();
$this->assertEqual($ixrmsg->messageType,'methodCall');
$this->assertEqual($ixrmsg->methodName,'wiki.getBackLinks');
$this->assertEqual($ixrmsg->params,array(''));
}
function test_struct(){
$xml = '<?xml version=\'1.0\'?>
<methodCall>
<methodName>wiki.putPage</methodName>
<params>
<param>
<value><string>start</string></value>
</param>
<param>
<value><string>test text</string></value>
</param>
<param>
<value><struct>
<member>
<name>sum</name>
<value><string>xmlrpc edit</string></value>
</member>
<member>
<name>minor</name>
<value><string>1</string></value>
</member>
</struct></value>
</param>
</params>
</methodCall>';
$ixrmsg = new IXR_Message($xml);
$ixrmsg->parse();
$this->assertEqual($ixrmsg->messageType,'methodCall');
$this->assertEqual($ixrmsg->methodName,'wiki.putPage');
$this->assertEqual($ixrmsg->params,array('start','test text',array('sum'=>'xmlrpc edit','minor'=>'1')));
}
}
//Setup VIM: ex: et ts=4 :
<?php
// use no mbstring help here
require_once DOKU_INC.'inc/init.php';
class mail_isvalid extends UnitTestCase {
function test1(){
$tests = array();
// our own tests
$tests[] = array('bugs@php.net',true);
$tests[] = array('~someone@somewhere.com',true);
$tests[] = array('no+body.here@somewhere.com.au',true);
$tests[] = array('username+tag@domain.com',true); // FS#1447
$tests[] = array("rfc2822+allthesechars_#*!'`/-={}are.legal@somewhere.com.au",true);
$tests[] = array('_foo@test.com',true); // FS#1049
$tests[] = array('bugs@php.net1',true); // new ICAN rulez seem to allow this
$tests[] = array('.bugs@php.net1',false);
$tests[] = array('bu..gs@php.net',false);
$tests[] = array('bugs@php..net',false);
$tests[] = array('bugs@.php.net',false);
$tests[] = array('bugs@php.net.',false);
$tests[] = array('bu(g)s@php.net1',false);
$tests[] = array('bu[g]s@php.net1',false);
$tests[] = array('somebody@somewhere.museum',true);
$tests[] = array('somebody@somewhere.travel',true);
$tests[] = array('root@[2010:fb:fdac::311:2101]',true);
$tests[] = array('test@example', true); // we allow local addresses
// tests from http://code.google.com/p/php-email-address-validation/ below
$tests[] = array('test@example.com', true);
$tests[] = array('TEST@example.com', true);
$tests[] = array('1234567890@example.com', true);
$tests[] = array('test+test@example.com', true);
$tests[] = array('test-test@example.com', true);
$tests[] = array('t*est@example.com', true);
$tests[] = array('+1~1+@example.com', true);
$tests[] = array('{_test_}@example.com', true);
$tests[] = array('"[[ test ]]"@example.com', true);
$tests[] = array('test.test@example.com', true);
$tests[] = array('test."test"@example.com', true);
$tests[] = array('"test@test"@example.com', true);
$tests[] = array('test@123.123.123.123', true);
$tests[] = array('test@[123.123.123.123]', true);
$tests[] = array('test@example.example.com', true);
$tests[] = array('test@example.example.example.com', true);
$tests[] = array('test.example.com', false);
$tests[] = array('test.@example.com', false);
$tests[] = array('test..test@example.com', false);
$tests[] = array('.test@example.com', false);
$tests[] = array('test@test@example.com', false);
$tests[] = array('test@@example.com', false);
$tests[] = array('-- test --@example.com', false); // No spaces allowed in local part
$tests[] = array('[test]@example.com', false); // Square brackets only allowed within quotes
$tests[] = array('"test\test"@example.com', false); // Quotes cannot contain backslash
$tests[] = array('"test"test"@example.com', false); // Quotes cannot be nested
$tests[] = array('()[]\;:,<>@example.com', false); // Disallowed Characters
$tests[] = array('test@.', false);
$tests[] = array('test@example.', false);
$tests[] = array('test@.org', false);
$tests[] = array('12345678901234567890123456789012345678901234567890123456789012345@example.com', false); // 64 characters is maximum length for local part. This is 65.
$tests[] = array('test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com', false); // 255 characters is maximum length for domain. This is 256.
$tests[] = array('test@[123.123.123.123', false);
$tests[] = array('test@123.123.123.123]', false);
foreach($tests as $test){
$info = 'Testing '.$test[0];
$this->signal('failinfo',$info);
if($test[1]){
$this->assertTrue((bool) mail_isvalid($test[0]));
}else{
$this->assertFalse((bool) mail_isvalid($test[0]));
}
}
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/mail.php';
class mail_quotedprintable_encode extends UnitTestCase {
function test_simple(){
$in = 'hello';
$out = 'hello';
$this->assertEqual(mail_quotedprintable_encode($in),$out);
}
function test_spaceend(){
$in = "hello \nhello";
$out = "hello=20\nhello";
$this->assertEqual(mail_quotedprintable_encode($in),$out);
}
function test_german_utf8(){
$in = 'hello überlänge';
$out = 'hello =C3=BCberl=C3=A4nge';
$this->assertEqual(mail_quotedprintable_encode($in),$out);
}
function test_wrap(){
$in = '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789';
$out = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234=\n56789 123456789";
$this->assertEqual(mail_quotedprintable_encode($in,74),$out);
}
function test_nowrap(){
$in = '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789';
$out = '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789';
$this->assertEqual(mail_quotedprintable_encode($in,0),$out);
}
function test_russian_utf8(){
$in = 'Ваш пароль для системы Доку Вики';
$out = '=D0=92=D0=B0=D1=88 =D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8C =D0=B4=D0=BB=D1=8F =D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=8B =D0=94=D0=BE=D0=BA=D1=83 =D0=92=D0=B8=D0=BA=D0=B8';
$this->assertEqual(mail_quotedprintable_encode($in,0),$out);
}
}
//Setup VIM: ex: et ts=4 :
<?php
require_once DOKU_INC.'inc/mail.php';
class mail_send extends UnitTestCase {
/**
* These tests will try to send a bunch of mails to dokuwiki1@spam.la and
* dokuwiki2@spam.la - check the correctness at http://spam.la
*/
function test1(){
$addr = array(
'dokuwiki1@spam.la',
'dokuwiki2@spam.la',
'Test User <dokuwiki1@spam.la>',
'dokuwiki1@spam.la, dokuwiki2@spam.la',
'Test User 1 <dokuwiki1@spam.la>, Test User 2 <dokuwiki2@spam.la>'
);
$run = 0;
foreach($addr as $ad){
$run++;
$data = array(
'to' => $ad,
'subject' => 'mailtest 1-'.$run,
'body' => "Mailtest run 1-$run using to: $ad from:",
);
$this->assertTrue((bool) _mail_send_action($data));
$data = array(
'to' => $ad,
'from' => 'dokuwiki1@spam.la',
'subject' => 'mailtest 2-'.$run,
'body' => "Mailtest run 2-$run using to: $ad from: dokuwiki1@spam.la",
);
$this->assertTrue((bool) _mail_send_action($data));
$data = array(
'to' => $ad,
'from' => '"Foo Bar" <dokuwiki@spam.la>',
'subject' => 'mailtest 3-'.$run,
'body' => "Mailtest run 3-$run using to: $ad from: \"Foo Bar\" <dokuwiki@spam.la>",
);
$this->assertTrue((bool) _mail_send_action($data));
}
}
}
//Setup VIM: ex: et ts=4 :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment