Skip to content

Commit

Permalink
transformed common unit tests for phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-mel committed Apr 1, 2012
1 parent a140095 commit c42a452
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _testing/unittests/inc/common_cleanText.test.php
Expand Up @@ -3,7 +3,7 @@
require_once DOKU_INC . 'inc/init.php';
require_once DOKU_INC . 'inc/common.php';

class common_clientIP_test extends PHPUnit_Framework_TestCase {
class common_cleanText_test extends PHPUnit_Framework_TestCase {

function test_unix(){
$unix = 'one
Expand Down
154 changes: 154 additions & 0 deletions _testing/unittests/inc/common_clientip.test.php
@@ -0,0 +1,154 @@
<?php

require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/common.php';

class common_clientIP_test extends PHPUnit_Framework_TestCase {

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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(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->assertEquals(clientIP(),$out);
}

}

//Setup VIM: ex: et ts=4 :
29 changes: 29 additions & 0 deletions _testing/unittests/inc/common_obfuscate.test.php
@@ -0,0 +1,29 @@
<?php

require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/common.php';

class common_obfuscate_test extends PHPUnit_Framework_TestCase {

function test_none(){
global $conf;
$conf['mailguard'] = 'none';
$this->assertEquals(obfuscate('jon-doe@example.com'), 'jon-doe@example.com');
}

function test_hex(){
global $conf;
$conf['mailguard'] = 'hex';
$this->assertEquals(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->assertEquals(obfuscate('jon-doe@example.com'), 'jon [dash] doe [at] example [dot] com');
}


}
//Setup VIM: ex: et ts=4 :
18 changes: 18 additions & 0 deletions _testing/unittests/inc/common_pagetemplate.test.php
@@ -0,0 +1,18 @@
<?php

require_once DOKU_INC.'inc/init.php';
require_once DOKU_INC.'inc/common.php';

class common_pagetemplate_test extends PHPUnit_Framework_TestCase {

function test_none(){
global $conf;
$conf['sepchar'] = '-';
$data = array(
'id' => 'page-id-long',
'tpl' => '"@PAGE@" "@!PAGE@" "@!!PAGE@" "@!PAGE!@"',
);
$this->assertEquals(parsePageTemplate($data), '"page id long" "Page id long" "Page Id Long" "PAGE ID LONG"');
}
}
//Setup VIM: ex: et ts=4 :

0 comments on commit c42a452

Please sign in to comment.