diff options
author | Dominik Eckelmann <deckelmann@gmail.com> | 2012-04-01 22:53:41 +0200 |
---|---|---|
committer | Dominik Eckelmann <deckelmann@gmail.com> | 2012-04-01 22:53:41 +0200 |
commit | c30fce0219f0c027ae1cdd3a108188312ed67f98 (patch) | |
tree | 9b0221d302738586489d47c9ccb829cc2e7dcc1a /_testing/unittests/inc | |
parent | fb1d67614399c26869db4065da024d3756b657e1 (diff) | |
download | rpg-c30fce0219f0c027ae1cdd3a108188312ed67f98.tar.gz rpg-c30fce0219f0c027ae1cdd3a108188312ed67f98.tar.bz2 |
transformed pageutils_ tests to phpunit
Diffstat (limited to '_testing/unittests/inc')
-rw-r--r-- | _testing/unittests/inc/pageutils_clean_id.test.php | 157 | ||||
-rw-r--r-- | _testing/unittests/inc/pageutils_getid.test.php | 108 | ||||
-rw-r--r-- | _testing/unittests/inc/pageutils_resolve_id.test.php | 45 |
3 files changed, 310 insertions, 0 deletions
diff --git a/_testing/unittests/inc/pageutils_clean_id.test.php b/_testing/unittests/inc/pageutils_clean_id.test.php new file mode 100644 index 000000000..0c9c41da1 --- /dev/null +++ b/_testing/unittests/inc/pageutils_clean_id.test.php @@ -0,0 +1,157 @@ +<?php +require_once DOKU_INC.'inc/utf8.php'; +require_once DOKU_INC.'inc/pageutils.php'; + +class init_clean_id_test extends PHPUnit_Framework_TestCase { + + function teardown() { + global $cache_cleanid; + $cache_cleanid = array(); + } + + function test_default(){ + // we test multiple cases here + // format: $id, $ascii, $correct_output + $tests = array(); + + // set dokuwiki defaults + global $conf; + $conf['sepchar'] = '_'; + $conf['deaccent'] = 1; + + $tests[] = array('page',false,'page'); + $tests[] = array('pa_ge',false,'pa_ge'); + $tests[] = array('pa%ge',false,'pa_ge'); + $tests[] = array('pa#ge',false,'pa_ge'); + $tests[] = array('pàge',false,'page'); + $tests[] = array('pagĖ',false,'page'); + $tests[] = array('pa$%^*#ge',false,'pa_ge'); + $tests[] = array('*page*',false,'page'); + $tests[] = array('ښ',false,'ښ'); + $tests[] = array('päge',false,'paege'); + $tests[] = array('foo bar',false,'foo_bar'); + $tests[] = array('PÄGÖ',false,'paegoe'); + $tests[] = array('Faß','false','fass'); + $tests[] = array('ښ侧化并곦 β',false,'ښ侧化并곦_β'); + $tests[] = array('page:page',false,'page:page'); + $tests[] = array('page;page',false,'page:page'); + $tests[] = array('page:page 1.2',false,'page:page_1.2'); + + $tests[] = array('page._#!','false','page'); + $tests[] = array('._#!page','false','page'); + $tests[] = array('page._#!page','false','page._page'); + $tests[] = array('ns._#!:page','false','ns:page'); + $tests[] = array('ns:._#!page','false','ns:page'); + $tests[] = array('ns._#!ns:page','false','ns._ns:page'); + $tests[] = array('ns_:page',false,'ns:page'); + $tests[] = array('page...page','false','page...page'); + + $conf['useslash'] = 0; + $tests[] = array('page/page',false,'page_page'); + + foreach($tests as $test){ + $this->assertEquals(cleanID($test[0],$test[1]),$test[2]); + } + + $conf['useslash'] = 1; + $tests = array(); + $tests[] = array('page/page',false,'page:page'); + + $this->teardown(); + + foreach($tests as $test){ + $this->assertEquals(cleanID($test[0],$test[1]),$test[2]); + } + } + + function test_sepchar(){ + // we test multiple cases here + // format: $id, $ascii, $correct_output + $tests = array(); + + global $conf; + $conf['sepchar'] = '-'; + $conf['deaccent'] = 1; + + $tests[] = array('pa-ge',false,'pa-ge'); + $tests[] = array('pa%ge',false,'pa-ge'); + + foreach($tests as $test){ + $this->assertEquals(cleanID($test[0],$test[1]),$test[2]); + } + } + + function test_deaccent_keep(){ + // we test multiple cases here + // format: $id, $ascii, $correct_output + $tests = array(); + + global $conf; + $conf['sepchar'] = '_'; + $conf['deaccent'] = 0; + + $tests[] = array('pàge',false,'pàge'); + $tests[] = array('pagĖ',false,'pagė'); + $tests[] = array('pagĒēĔĕĖėĘęĚě',false,'pagēēĕĕėėęęěě'); + $tests[] = array('ښ',false,'ښ'); + $tests[] = array('ښ侧化并곦ঝഈβ',false,'ښ侧化并곦ঝഈβ'); + + foreach($tests as $test){ + $this->assertEquals(cleanID($test[0],$test[1]),$test[2]); + } + } + + function test_deaccent_romanize(){ + // we test multiple cases here + // format: $id, $ascii, $correct_output + $tests = array(); + + global $conf; + $conf['sepchar'] = '_'; + $conf['deaccent'] = 2; + + $tests[] = array('pàge',false,'page'); + $tests[] = array('pagĖ',false,'page'); + $tests[] = array('pagĒēĔĕĖėĘęĚě',false,'pageeeeeeeeee'); + $tests[] = array('ښ',false,'ښ'); + $tests[] = array('ښ侧化并곦ঝഈβ',false,'ښ侧化并곦ঝഈβ'); + + foreach($tests as $test){ + $this->assertEquals(cleanID($test[0],$test[1]),$test[2]); + } + } + + function test_deaccent_ascii(){ + // we test multiple cases here + // format: $id, $ascii, $correct_output + $tests = array(); + + global $conf; + $conf['sepchar'] = '_'; + $conf['deaccent'] = 0; + + $tests[] = array('pàge',true,'page'); + $tests[] = array('pagĖ',true,'page'); + $tests[] = array('pagĒēĔĕĖėĘęĚě',true,'pageeeeeeeeee'); + $tests[] = array('ښ',true,''); + $tests[] = array('ښ侧化并곦ঝഈβ',true,''); + + foreach($tests as $test){ + $this->assertEquals(cleanID($test[0],$test[1]),$test[2]); + } + + $conf['deaccent'] = 1; + + foreach($tests as $test){ + $this->assertEquals(cleanID($test[0],$test[1]),$test[2]); + } + + $conf['deaccent'] = 2; + + foreach($tests as $test){ + $this->assertEquals(cleanID($test[0],$test[1]),$test[2]); + } + } + +} +//Setup VIM: ex: et ts=4 : diff --git a/_testing/unittests/inc/pageutils_getid.test.php b/_testing/unittests/inc/pageutils_getid.test.php new file mode 100644 index 000000000..41cb4bd14 --- /dev/null +++ b/_testing/unittests/inc/pageutils_getid.test.php @@ -0,0 +1,108 @@ +<?php +require_once DOKU_INC.'inc/utf8.php'; +require_once DOKU_INC.'inc/pageutils.php'; + +class init_getID_test extends PHPUnit_Framework_TestCase { + + /** + * fetch media files with basedir and urlrewrite=2 + * + * data provided by Jan Decaluwe <jan@jandecaluwe.com> + */ + function test1(){ + global $conf; + $conf['basedir'] = '//'; + $conf['userewrite'] = 2; + $conf['deaccent'] = 0; // the default (1) gives me strange exceptions + + + $_SERVER['SCRIPT_FILENAME'] = '/lib/exe/fetch.php'; + $_SERVER['REQUEST_URI'] = '/lib/exe/fetch.php/myhdl-0.5dev1.tar.gz?id=snapshots&cache=cache'; + + $this->assertEquals(getID('media'), 'myhdl-0.5dev1.tar.gz'); + } + + + /** + * getID with internal mediafile, urlrewrite=2, no basedir set, apache, mod_php + */ + function test2(){ + global $conf; + $conf['basedir'] = ''; + $conf['userewrite'] = '2'; + $conf['baseurl'] = ''; + $conf['useslash'] = '1'; + $_SERVER['DOCUMENT_ROOT'] = '/var/www/'; + $_SERVER['HTTP_HOST'] = 'xerxes.my.home'; + $_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/lib/exe/detail.php'; + $_SERVER['PHP_SELF'] = '/dokuwiki/lib/exe/detail.php/wiki/discussion/button-dw.png'; + $_SERVER['REQUEST_URI'] = '/dokuwiki/lib/exe/detail.php/wiki/discussion/button-dw.png?id=test&debug=1'; + $_SERVER['SCRIPT_NAME'] = '/dokuwiki/lib/exe/detail.php'; + $_SERVER['PATH_INFO'] = '/wiki/discussion/button-dw.png'; + $_SERVER['PATH_TRANSLATED'] = '/var/www/wiki/discussion/button-dw.png'; + + $this->assertEquals(getID('media',true), 'wiki:discussion:button-dw.png'); + $this->assertEquals(getID('media',false), 'wiki/discussion/button-dw.png'); + } + + /** + * getID with given id in url and userewrite=2, no basedir set, dokuwiki not in document root. + */ + function test3() { + global $conf; + $conf['basedir'] = ''; + $conf['userewrite'] = '2'; + $conf['baseurl'] = ''; + $_SERVER['DOCUMENT_ROOT'] = '/var/www/'; + $_SERVER['SCRIPT_FILENAME'] = '/usr/share/dokuwiki/doku.php'; + $_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php'; + $_SERVER['REQUEST_URI'] = '/dokuwiki/doku.php/wiki:dokuwiki'; + $_SERVER['PATH_INFO'] = '/wiki:dokuwiki'; + $_SERVER['PATH_TRANSLATED'] = '/var/www/wiki:dokuwiki'; + $_SERVER['PHP_SELF'] = '/dokuwiki/doku.php/wiki:dokuwiki'; + + $this->assertEquals(getID(), 'wiki:dokuwiki'); + } + + /** + * getID with given id in url and userewrite=2, no basedir set, Apache and CGI. + */ + function test4() { + global $conf; + $conf['basedir'] = ''; + $conf['userewrite'] = '2'; + $conf['baseurl'] = ''; + $conf['useslash'] = '1'; + + $_SERVER['DOCUMENT_ROOT'] = '/var/www/vhosts/example.com/htdocs'; + $_SERVER['SCRIPT_FILENAME'] = '/var/www/vhosts/example.com/htdocs/doku.php'; + $_SERVER['SCRIPT_NAME'] = '/doku.php'; + $_SERVER['REQUEST_URI'] = '/doku.php/wiki/dokuwiki'; + $_SERVER['PATH_INFO'] = '/wiki/dokuwiki'; + $_SERVER['PATH_TRANSLATED'] = '/var/www/vhosts/example.com/htdocs/doku.php'; + $_SERVER['PHP_SELF'] = '/doku.php/wiki/dokuwiki'; + + $this->assertEquals(getID(), 'wiki:dokuwiki'); + } + + /** + * getID with given id / in url and userewrite=2, no basedir set, Apache and CGI. + */ + function test5() { + global $conf; + $conf['basedir'] = ''; + $conf['userewrite'] = '2'; + $conf['baseurl'] = ''; + $_SERVER['DOCUMENT_ROOT'] = '/var/www/'; + $_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/doku.php'; + $_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php'; + $_SERVER['REQUEST_URI'] = '/dokuwiki/doku.php/?do=debug'; + $_SERVER['PATH_INFO'] = '/'; + $_SERVER['PATH_TRANSLATED'] = '/var/www/index.html'; + $_SERVER['PHP_SELF'] = '/dokuwiki/doku.php/'; + + $this->assertEquals(getID(), cleanID($conf['start'])); + } + +} +//Setup VIM: ex: et ts=4 : diff --git a/_testing/unittests/inc/pageutils_resolve_id.test.php b/_testing/unittests/inc/pageutils_resolve_id.test.php new file mode 100644 index 000000000..e8cec2aef --- /dev/null +++ b/_testing/unittests/inc/pageutils_resolve_id.test.php @@ -0,0 +1,45 @@ +<?php +require_once DOKU_INC.'inc/utf8.php'; +require_once DOKU_INC.'inc/pageutils.php'; + +class init_resolve_id_test extends PHPUnit_Framework_TestCase { + + + function test1(){ + // we test multiple cases here + // format: $ns, $page, $output + $tests = array(); + + // relative current in root + $tests[] = array('','page','page'); + $tests[] = array('','.page','page'); + $tests[] = array('','.:page','page'); + + // relative current in namespace + $tests[] = array('lev1:lev2','page','lev1:lev2:page'); + $tests[] = array('lev1:lev2','.page','lev1:lev2:page'); + $tests[] = array('lev1:lev2','.:page','lev1:lev2:page'); + + // relative upper in root + $tests[] = array('','..page','page'); + $tests[] = array('','..:page','page'); + + // relative upper in namespace + $tests[] = array('lev1:lev2','..page','lev1:page'); + $tests[] = array('lev1:lev2','..:page','lev1:page'); + $tests[] = array('lev1:lev2','..:..:page','page'); + $tests[] = array('lev1:lev2','..:..:..:page','page'); + + // strange and broken ones + $tests[] = array('lev1:lev2','....:....:page','lev1:lev2:page'); + $tests[] = array('lev1:lev2','..:..:lev3:page','lev3:page'); + $tests[] = array('lev1:lev2','..:..:lev3:..:page','page'); + $tests[] = array('lev1:lev2','..:..:lev3:..:page:....:...','page'); + + foreach($tests as $test){ + $this->assertEquals(resolve_id($test[0],$test[1]),$test[2]); + } + } + +} +//Setup VIM: ex: et ts=4 : |