summaryrefslogtreecommitdiff
path: root/_test/tests/test/basic.test.php
blob: 05778ccf99c956158531a6acd5d3b75032749066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php

/**
 * @group integration
 */
class InttestsBasicTest extends DokuWikiTest {

    private $some_headers =  array(
          'Content-Type: image/png',
          'Date: Fri, 22 Mar 2013 16:10:01 GMT',
          'X-Powered-By: PHP/5.3.15',
          'Expires: Sat, 23 Mar 2013 17:03:46 GMT',
          'Cache-Control: public, proxy-revalidate, no-transform, max-age=86400',
          'Pragma: public',
          'Last-Modified: Fri, 22 Mar 2013 01:48:28 GMT',
          'ETag: "63daab733b38c30c337229b2e587f8fb"',
          'Content-Disposition: inline; filename="fe389b0db8c1088c336abb502d2f9ae7.media.200x200.png',
          'Accept-Ranges: bytes',
          'Content-Type: image/png',
          'Content-Length: 62315',
          'Status: 200 OK',
          'Status: 404 Not Found',
     );

    /**
     * Execute the simplest possible request and expect
     * a dokuwiki page which obviously has the word "DokuWiki"
     * in it somewhere.
     */
    function testSimpleRun() {
        $request = new TestRequest();

        $response = $request->execute();

        $this->assertTrue(
            strpos($response->getContent(), 'DokuWiki') >= 0,
            'DokuWiki was not a word in the output'
        );
    }

    function testPost() {
        $request = new TestRequest();

        $input = array(
            'string' => 'A string',
            'array'  => array(1, 2, 3),
            'id'     => 'wiki:dokuwiki'
        );

        $response = $request->post($input);

        // server var check
        $this->assertEquals('POST',$request->getServer('REQUEST_METHOD'));
        $this->assertEquals('',$request->getServer('QUERY_STRING'));
        $this->assertEquals('/doku.php',$request->getServer('REQUEST_URI'));

        // variable setup check
        $this->assertEquals('A string', $request->getPost('string'));
        $this->assertEquals(array(1, 2, 3), $request->getPost('array'));
        $this->assertEquals('wiki:dokuwiki', $request->getPost('id'));

        // output check
        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0);
    }

    function testPostGet() {
        $request = new TestRequest();

        $input = array(
            'string' => 'A string',
            'array'  => array(1, 2, 3),
        );

        $response = $request->post($input,'/doku.php?id=wiki:dokuwiki');

        // server var check
        $this->assertEquals('POST',$request->getServer('REQUEST_METHOD'));
        $this->assertEquals('?id=wiki:dokuwiki',$request->getServer('QUERY_STRING'));
        $this->assertEquals('/doku.php?id=wiki:dokuwiki',$request->getServer('REQUEST_URI'));

        // variable setup check
        $this->assertEquals('A string', $request->getPost('string'));
        $this->assertEquals(array(1, 2, 3), $request->getPost('array'));
        $this->assertEquals('wiki:dokuwiki', $request->getGet('id'));

        // output check
        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0);
    }

    function testGet() {
        $request = new TestRequest();

        $input = array(
            'string' => 'A string',
            'array'  => array(1, 2, 3),
            'test'   => 'bar'
        );

        $response = $request->get($input,'/doku.php?id=wiki:dokuwiki&test=foo');

        // server var check
        $this->assertEquals('GET',$request->getServer('REQUEST_METHOD'));
        $this->assertEquals(
            '?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3',
            $request->getServer('QUERY_STRING')
        );
        $this->assertEquals(
            '/doku.php?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3',
            $request->getServer('REQUEST_URI')
        );

        // variable setup check
        $this->assertEquals('A string', $request->getGet('string'));
        $this->assertEquals(array(1, 2, 3), $request->getGet('array'));
        $this->assertEquals('wiki:dokuwiki', $request->getGet('id'));
        $this->assertEquals('bar', $request->getGet('test'));

        // output check
        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0);
    }

    function testScripts() {
        $request = new TestRequest();

        // doku
        $response = $request->get();
        $this->assertEquals('doku.php',$request->getScript());

        $response = $request->get(array(),'/doku.php?id=wiki:dokuwiki&test=foo');
        $this->assertEquals('doku.php',$request->getScript());

        // fetch
        $response = $request->get(array(),'/lib/exe/fetch.php?media=wiki:dokuwiki-128.png');
        $this->assertEquals('lib/exe/fetch.php',$request->getScript());

        // detail
        $response = $request->get(array(),'/lib/exe/detail.php?id=start&media=wiki:dokuwiki-128.png');
        $this->assertEquals('lib/exe/detail.php',$request->getScript());
    }

    function testHeaders(){
        header('X-Test: check headers working');
        $header_check = function_exists('xdebug_get_headers') ? xdebug_get_headers() : headers_list();
        if (empty($header_check)) {
            $this->markTestSkipped('headers not returned, perhaps your sapi does not return headers, try xdebug');
        } else {
            header_remove('X-Test');
        }

        $request = new TestRequest();
        $response = $request->get(array(),'/lib/exe/fetch.php?media=wiki:dokuwiki-128.png');
        $headers = $response->getHeaders();
        $this->assertTrue(!empty($headers));
    }

    function testGetHeader(){
        $response = new TestResponse('',$this->some_headers);

        $this->assertEquals('Pragma: public', $response->getHeader('Pragma'));
        $this->assertEmpty($response->getHeader('Junk'));
        $this->assertEquals(array('Content-Type: image/png','Content-Type: image/png'), $response->getHeader('Content-Type'));
    }

    function testGetStatus(){
       $response = new TestResponse('',$this->some_headers);
       $this->assertEquals(404, $response->getStatusCode());

       $response = new TestResponse('',array_slice($this->some_headers,0,-2));  // slice off the last two headers to leave no status header
       $this->assertNull($response->getStatusCode());
    }

}