diff options
-rw-r--r-- | _testing/README | 1 | ||||
-rw-r--r-- | _testing/unittest.xml | 3 | ||||
-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 |
5 files changed, 313 insertions, 1 deletions
diff --git a/_testing/README b/_testing/README index 7150da5a4..dc58e1805 100644 --- a/_testing/README +++ b/_testing/README @@ -23,3 +23,4 @@ Bad tests are tests that do not run out of the box. * inc/html_hilight (runkit) * inc/indexer_idx_indexlengths * inc/mail_send + * inc/pageutils_resolve_pageid diff --git a/_testing/unittest.xml b/_testing/unittest.xml index e0058eaca..dc2c57015 100644 --- a/_testing/unittest.xml +++ b/_testing/unittest.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit - bootstrap="unittests/bootstrap.php"> + bootstrap="unittests/bootstrap.php" + convertNoticesToExceptions="false"> <testsuites> <testsuite> 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 : |