summaryrefslogtreecommitdiff
path: root/_test/tests/test/basic.test.php
blob: a0ea48a3a37cf69e3d21669ae1931ba4d797a16c (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
<?php

/**
 * @group integration
 */
class InttestsBasicTest extends DokuWikiTest {
    /**
     * 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);
    }


}