1<?php 2require_once DOKU_INC.'inc/utf8.php'; 3require_once DOKU_INC.'inc/pageutils.php'; 4 5class init_getID_test extends DokuWikiTest { 6 7 /** 8 * fetch media files with basedir and urlrewrite=2 9 * 10 * data provided by Jan Decaluwe <jan@jandecaluwe.com> 11 */ 12 function test1(){ 13 global $conf; 14 $conf['basedir'] = '//'; 15 $conf['userewrite'] = 2; 16 $conf['deaccent'] = 0; // the default (1) gives me strange exceptions 17 18 19 $_SERVER['SCRIPT_FILENAME'] = '/lib/exe/fetch.php'; 20 $_SERVER['REQUEST_URI'] = '/lib/exe/fetch.php/myhdl-0.5dev1.tar.gz?id=snapshots&cache=cache'; 21 22 $this->assertEquals(getID('media'), 'myhdl-0.5dev1.tar.gz'); 23 } 24 25 26 /** 27 * getID with internal mediafile, urlrewrite=2, no basedir set, apache, mod_php 28 */ 29 function test2(){ 30 global $conf; 31 $conf['basedir'] = ''; 32 $conf['userewrite'] = '2'; 33 $conf['baseurl'] = ''; 34 $conf['useslash'] = '1'; 35 $_SERVER['DOCUMENT_ROOT'] = '/var/www/'; 36 $_SERVER['HTTP_HOST'] = 'xerxes.my.home'; 37 $_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/lib/exe/detail.php'; 38 $_SERVER['PHP_SELF'] = '/dokuwiki/lib/exe/detail.php/wiki/discussion/button-dw.png'; 39 $_SERVER['REQUEST_URI'] = '/dokuwiki/lib/exe/detail.php/wiki/discussion/button-dw.png?id=test&debug=1'; 40 $_SERVER['SCRIPT_NAME'] = '/dokuwiki/lib/exe/detail.php'; 41 $_SERVER['PATH_INFO'] = '/wiki/discussion/button-dw.png'; 42 $_SERVER['PATH_TRANSLATED'] = '/var/www/wiki/discussion/button-dw.png'; 43 44 $this->assertEquals(getID('media',true), 'wiki:discussion:button-dw.png'); 45 $this->assertEquals(getID('media',false), 'wiki/discussion/button-dw.png'); 46 } 47 48 /** 49 * getID with given id in url and userewrite=2, no basedir set, dokuwiki not in document root. 50 */ 51 function test3() { 52 global $conf; 53 $conf['basedir'] = ''; 54 $conf['userewrite'] = '2'; 55 $conf['baseurl'] = ''; 56 $_SERVER['DOCUMENT_ROOT'] = '/var/www/'; 57 $_SERVER['SCRIPT_FILENAME'] = '/usr/share/dokuwiki/doku.php'; 58 $_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php'; 59 $_SERVER['REQUEST_URI'] = '/dokuwiki/doku.php/wiki:dokuwiki'; 60 $_SERVER['PATH_INFO'] = '/wiki:dokuwiki'; 61 $_SERVER['PATH_TRANSLATED'] = '/var/www/wiki:dokuwiki'; 62 $_SERVER['PHP_SELF'] = '/dokuwiki/doku.php/wiki:dokuwiki'; 63 64 $this->assertEquals(getID(), 'wiki:dokuwiki'); 65 } 66 67 /** 68 * getID with given id in url and userewrite=2, no basedir set, Apache and CGI. 69 */ 70 function test4() { 71 global $conf; 72 $conf['basedir'] = ''; 73 $conf['userewrite'] = '2'; 74 $conf['baseurl'] = ''; 75 $conf['useslash'] = '1'; 76 77 $_SERVER['DOCUMENT_ROOT'] = '/var/www/vhosts/example.com/htdocs'; 78 $_SERVER['SCRIPT_FILENAME'] = '/var/www/vhosts/example.com/htdocs/doku.php'; 79 $_SERVER['SCRIPT_NAME'] = '/doku.php'; 80 $_SERVER['REQUEST_URI'] = '/doku.php/wiki/dokuwiki'; 81 $_SERVER['PATH_INFO'] = '/wiki/dokuwiki'; 82 $_SERVER['PATH_TRANSLATED'] = '/var/www/vhosts/example.com/htdocs/doku.php'; 83 $_SERVER['PHP_SELF'] = '/doku.php/wiki/dokuwiki'; 84 85 $this->assertEquals(getID(), 'wiki:dokuwiki'); 86 } 87 88 /** 89 * getID with given id / in url and userewrite=2, no basedir set, Apache and CGI. 90 */ 91 function test5() { 92 global $conf; 93 $conf['basedir'] = ''; 94 $conf['userewrite'] = '2'; 95 $conf['baseurl'] = ''; 96 $_SERVER['DOCUMENT_ROOT'] = '/var/www/'; 97 $_SERVER['SCRIPT_FILENAME'] = '/var/www/dokuwiki/doku.php'; 98 $_SERVER['SCRIPT_NAME'] = '/dokuwiki/doku.php'; 99 $_SERVER['REQUEST_URI'] = '/dokuwiki/doku.php/?do=debug'; 100 $_SERVER['PATH_INFO'] = '/'; 101 $_SERVER['PATH_TRANSLATED'] = '/var/www/index.html'; 102 $_SERVER['PHP_SELF'] = '/dokuwiki/doku.php/'; 103 104 $this->assertEquals(getID(), cleanID($conf['start'])); 105 } 106 107} 108//Setup VIM: ex: et ts=4 : 109