From c30fce0219f0c027ae1cdd3a108188312ed67f98 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sun, 1 Apr 2012 22:53:41 +0200 Subject: transformed pageutils_ tests to phpunit --- _testing/unittests/inc/pageutils_clean_id.test.php | 157 +++++++++++++++++++++ _testing/unittests/inc/pageutils_getid.test.php | 108 ++++++++++++++ .../unittests/inc/pageutils_resolve_id.test.php | 45 ++++++ 3 files changed, 310 insertions(+) create mode 100644 _testing/unittests/inc/pageutils_clean_id.test.php create mode 100644 _testing/unittests/inc/pageutils_getid.test.php create mode 100644 _testing/unittests/inc/pageutils_resolve_id.test.php (limited to '_testing/unittests/inc') 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 @@ +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 @@ + + */ + 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 @@ +assertEquals(resolve_id($test[0],$test[1]),$test[2]); + } + } + +} +//Setup VIM: ex: et ts=4 : -- cgit v1.2.3