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