xref: /dokuwiki/_test/tests/inc/common_basicinfo.test.php (revision 7ae29fa453970036576e8b18fe228c24a25e94ff)
1*7ae29fa4SChristopher Smith<?php
2*7ae29fa4SChristopher Smith
3*7ae29fa4SChristopher Smithclass common_infofunctions_test extends DokuWikiTest {
4*7ae29fa4SChristopher Smith
5*7ae29fa4SChristopher Smith    function setup(){
6*7ae29fa4SChristopher Smith        parent::setup();
7*7ae29fa4SChristopher Smith
8*7ae29fa4SChristopher Smith        global $USERINFO;
9*7ae29fa4SChristopher Smith        $USERINFO = array(
10*7ae29fa4SChristopher Smith           'pass' => '179ad45c6ce2cb97cf1029e212046e81',
11*7ae29fa4SChristopher Smith           'name' => 'Arthur Dent',
12*7ae29fa4SChristopher Smith           'mail' => 'arthur@example.com',
13*7ae29fa4SChristopher Smith           'grps' => array ('admin','user'),
14*7ae29fa4SChristopher Smith        );
15*7ae29fa4SChristopher Smith        $_SERVER['REMOTE_USER'] = 'testuser';
16*7ae29fa4SChristopher Smith        $_SERVER['REMOTE_ADDR'] = '1.2.3.4';
17*7ae29fa4SChristopher Smith    }
18*7ae29fa4SChristopher Smith
19*7ae29fa4SChristopher Smith    function _get_info() {
20*7ae29fa4SChristopher Smith        global $USERINFO;
21*7ae29fa4SChristopher Smith        $info = array (
22*7ae29fa4SChristopher Smith          'isadmin' => true,
23*7ae29fa4SChristopher Smith          'ismanager' => true,
24*7ae29fa4SChristopher Smith          'userinfo' => $USERINFO,
25*7ae29fa4SChristopher Smith          'perm' => 255,
26*7ae29fa4SChristopher Smith          'namespace' => false,
27*7ae29fa4SChristopher Smith          'ismobile' => false,
28*7ae29fa4SChristopher Smith          'client' => 'testuser',
29*7ae29fa4SChristopher Smith        );
30*7ae29fa4SChristopher Smith
31*7ae29fa4SChristopher Smith        return $info;
32*7ae29fa4SChristopher Smith    }
33*7ae29fa4SChristopher Smith
34*7ae29fa4SChristopher Smith    /**
35*7ae29fa4SChristopher Smith     * Its important to have the correct set of keys.
36*7ae29fa4SChristopher Smith     * Other functions provide the values
37*7ae29fa4SChristopher Smith     */
38*7ae29fa4SChristopher Smith    function test_basicinfo(){
39*7ae29fa4SChristopher Smith        // test with REMOTE_USER set and the user an admin user
40*7ae29fa4SChristopher Smith        $info = $this->_get_info();
41*7ae29fa4SChristopher Smith        $this->assertEquals(basicinfo($ID,true),$info);
42*7ae29fa4SChristopher Smith
43*7ae29fa4SChristopher Smith        // with $httpclient parameter set to false
44*7ae29fa4SChristopher Smith        unset($info['ismobile']);
45*7ae29fa4SChristopher Smith        $this->assertEquals(basicinfo($ID,false),$info);
46*7ae29fa4SChristopher Smith
47*7ae29fa4SChristopher Smith        // with anonymous user
48*7ae29fa4SChristopher Smith        unset($_SERVER['REMOTE_USER']);
49*7ae29fa4SChristopher Smith        global $USERINFO; $USERINFO = array();
50*7ae29fa4SChristopher Smith
51*7ae29fa4SChristopher Smith        $info = array(
52*7ae29fa4SChristopher Smith          'isadmin' => false,
53*7ae29fa4SChristopher Smith          'ismanager' => false,
54*7ae29fa4SChristopher Smith          'perm' => 8,
55*7ae29fa4SChristopher Smith          'namespace' => false,
56*7ae29fa4SChristopher Smith          'ismobile' => false,
57*7ae29fa4SChristopher Smith          'client' => '1.2.3.4',
58*7ae29fa4SChristopher Smith        );
59*7ae29fa4SChristopher Smith        $this->assertEquals(basicinfo($ID,true),$info);
60*7ae29fa4SChristopher Smith    }
61*7ae29fa4SChristopher Smith
62*7ae29fa4SChristopher Smith    /**
63*7ae29fa4SChristopher Smith     * We're interested in the extra keys required for $INFO when its a page request
64*7ae29fa4SChristopher Smith     * and that $REV, $RANGE globals are set/cleared correctly
65*7ae29fa4SChristopher Smith     */
66*7ae29fa4SChristopher Smith    function test_pageinfo(){
67*7ae29fa4SChristopher Smith        global $ID,$conf;
68*7ae29fa4SChristopher Smith        $ID = 'wiki:start';
69*7ae29fa4SChristopher Smith
70*7ae29fa4SChristopher Smith        $info = $this->_get_info();
71*7ae29fa4SChristopher Smith        $info['id'] = 'wiki:start';
72*7ae29fa4SChristopher Smith        $info['namespace'] = 'wiki';
73*7ae29fa4SChristopher Smith        $info['rev'] = null;
74*7ae29fa4SChristopher Smith        $info['subscribed'] = false;
75*7ae29fa4SChristopher Smith        $info['locked'] = false;
76*7ae29fa4SChristopher Smith        $info['filepath'] = $conf['datadir'].'/wiki/start.txt';
77*7ae29fa4SChristopher Smith        $info['exists'] = false;
78*7ae29fa4SChristopher Smith        $info['writable'] = true;
79*7ae29fa4SChristopher Smith        $info['editable'] = true;
80*7ae29fa4SChristopher Smith        $info['lastmod'] = false;
81*7ae29fa4SChristopher Smith        $info['meta'] = array();
82*7ae29fa4SChristopher Smith        $info['ip'] = null;
83*7ae29fa4SChristopher Smith        $info['user'] = null;
84*7ae29fa4SChristopher Smith        $info['sum'] = null;
85*7ae29fa4SChristopher Smith        $info['editor'] = null;
86*7ae29fa4SChristopher Smith
87*7ae29fa4SChristopher Smith        // basic test, no revision
88*7ae29fa4SChristopher Smith        $this->assertEquals(pageinfo(),$info);
89*7ae29fa4SChristopher Smith
90*7ae29fa4SChristopher Smith        // TODO: test with revision = current page
91*7ae29fa4SChristopher Smith
92*7ae29fa4SChristopher Smith        // TODO: test with true revision
93*7ae29fa4SChristopher Smith
94*7ae29fa4SChristopher Smith        // TODO: test with revision & range
95*7ae29fa4SChristopher Smith
96*7ae29fa4SChristopher Smith        // TODO: validate against the same test run on master branch pre this change
97*7ae29fa4SChristopher Smith    }
98*7ae29fa4SChristopher Smith
99*7ae29fa4SChristopher Smith    /**
100*7ae29fa4SChristopher Smith     * We're interested in the extra keys for $INFO when its a media request
101*7ae29fa4SChristopher Smith     */
102*7ae29fa4SChristopher Smith    function test_mediainfo(){
103*7ae29fa4SChristopher Smith        global $NS, $IMG;
104*7ae29fa4SChristopher Smith        $NS = '';
105*7ae29fa4SChristopher Smith        $IMG = 'testimage.png';
106*7ae29fa4SChristopher Smith
107*7ae29fa4SChristopher Smith        $info = $this->_get_info();
108*7ae29fa4SChristopher Smith        $info['image'] = 'testimage.png';
109*7ae29fa4SChristopher Smith
110*7ae29fa4SChristopher Smith        $this->assertEquals(mediainfo(),$info);
111*7ae29fa4SChristopher Smith    }
112*7ae29fa4SChristopher Smith}
113*7ae29fa4SChristopher Smith
114*7ae29fa4SChristopher Smith//Setup VIM: ex: et ts=4 :
115