xref: /dokuwiki/_test/tests/test/basic.test.php (revision 9e777cee116bd29c51b62ccd1c4353cc00014522)
1f8369d7dSTobias Sarnowski<?php
2f8369d7dSTobias Sarnowski
3f8369d7dSTobias Sarnowski/**
4f8369d7dSTobias Sarnowski * @group integration
5f8369d7dSTobias Sarnowski */
6f8369d7dSTobias Sarnowskiclass InttestsBasicTest extends DokuWikiTest {
7f8369d7dSTobias Sarnowski    /**
8f8369d7dSTobias Sarnowski     * Execute the simplest possible request and expect
9f8369d7dSTobias Sarnowski     * a dokuwiki page which obviously has the word "DokuWiki"
10f8369d7dSTobias Sarnowski     * in it somewhere.
11f8369d7dSTobias Sarnowski     */
12f8369d7dSTobias Sarnowski    function testSimpleRun() {
13f8369d7dSTobias Sarnowski        $request = new TestRequest();
14f8369d7dSTobias Sarnowski
15f8369d7dSTobias Sarnowski        $response = $request->execute();
16f8369d7dSTobias Sarnowski
17f8369d7dSTobias Sarnowski        $this->assertTrue(
18f8369d7dSTobias Sarnowski            strpos($response->getContent(), 'DokuWiki') >= 0,
19f8369d7dSTobias Sarnowski            'DokuWiki was not a word in the output'
20f8369d7dSTobias Sarnowski        );
21f8369d7dSTobias Sarnowski    }
22*9e777ceeSAndreas Gohr
23*9e777ceeSAndreas Gohr    function testPost() {
24*9e777ceeSAndreas Gohr        $request = new TestRequest();
25*9e777ceeSAndreas Gohr
26*9e777ceeSAndreas Gohr        $input = array(
27*9e777ceeSAndreas Gohr            'string' => 'A string',
28*9e777ceeSAndreas Gohr            'array'  => array(1, 2, 3),
29*9e777ceeSAndreas Gohr            'id'     => 'wiki:dokuwiki'
30*9e777ceeSAndreas Gohr        );
31*9e777ceeSAndreas Gohr
32*9e777ceeSAndreas Gohr        $response = $request->post($input);
33*9e777ceeSAndreas Gohr
34*9e777ceeSAndreas Gohr        // server var check
35*9e777ceeSAndreas Gohr        $this->assertEquals('POST',$request->getServer('REQUEST_METHOD'));
36*9e777ceeSAndreas Gohr        $this->assertEquals('',$request->getServer('QUERY_STRING'));
37*9e777ceeSAndreas Gohr        $this->assertEquals('/doku.php',$request->getServer('REQUEST_URI'));
38*9e777ceeSAndreas Gohr
39*9e777ceeSAndreas Gohr        // variable setup check
40*9e777ceeSAndreas Gohr        $this->assertEquals('A string', $request->getPost('string'));
41*9e777ceeSAndreas Gohr        $this->assertEquals(array(1, 2, 3), $request->getPost('array'));
42*9e777ceeSAndreas Gohr        $this->assertEquals('wiki:dokuwiki', $request->getPost('id'));
43*9e777ceeSAndreas Gohr
44*9e777ceeSAndreas Gohr        // output check
45*9e777ceeSAndreas Gohr        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0);
46*9e777ceeSAndreas Gohr    }
47*9e777ceeSAndreas Gohr
48*9e777ceeSAndreas Gohr    function testPostGet() {
49*9e777ceeSAndreas Gohr        $request = new TestRequest();
50*9e777ceeSAndreas Gohr
51*9e777ceeSAndreas Gohr        $input = array(
52*9e777ceeSAndreas Gohr            'string' => 'A string',
53*9e777ceeSAndreas Gohr            'array'  => array(1, 2, 3),
54*9e777ceeSAndreas Gohr        );
55*9e777ceeSAndreas Gohr
56*9e777ceeSAndreas Gohr        $response = $request->post($input,'/doku.php?id=wiki:dokuwiki');
57*9e777ceeSAndreas Gohr
58*9e777ceeSAndreas Gohr        // server var check
59*9e777ceeSAndreas Gohr        $this->assertEquals('POST',$request->getServer('REQUEST_METHOD'));
60*9e777ceeSAndreas Gohr        $this->assertEquals('?id=wiki:dokuwiki',$request->getServer('QUERY_STRING'));
61*9e777ceeSAndreas Gohr        $this->assertEquals('/doku.php?id=wiki:dokuwiki',$request->getServer('REQUEST_URI'));
62*9e777ceeSAndreas Gohr
63*9e777ceeSAndreas Gohr        // variable setup check
64*9e777ceeSAndreas Gohr        $this->assertEquals('A string', $request->getPost('string'));
65*9e777ceeSAndreas Gohr        $this->assertEquals(array(1, 2, 3), $request->getPost('array'));
66*9e777ceeSAndreas Gohr        $this->assertEquals('wiki:dokuwiki', $request->getGet('id'));
67*9e777ceeSAndreas Gohr
68*9e777ceeSAndreas Gohr        // output check
69*9e777ceeSAndreas Gohr        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0);
70*9e777ceeSAndreas Gohr    }
71*9e777ceeSAndreas Gohr
72*9e777ceeSAndreas Gohr    function testGet() {
73*9e777ceeSAndreas Gohr        $request = new TestRequest();
74*9e777ceeSAndreas Gohr
75*9e777ceeSAndreas Gohr        $input = array(
76*9e777ceeSAndreas Gohr            'string' => 'A string',
77*9e777ceeSAndreas Gohr            'array'  => array(1, 2, 3),
78*9e777ceeSAndreas Gohr            'test'   => 'bar'
79*9e777ceeSAndreas Gohr        );
80*9e777ceeSAndreas Gohr
81*9e777ceeSAndreas Gohr        $response = $request->get($input,'/doku.php?id=wiki:dokuwiki&test=foo');
82*9e777ceeSAndreas Gohr
83*9e777ceeSAndreas Gohr        // server var check
84*9e777ceeSAndreas Gohr        $this->assertEquals('GET',$request->getServer('REQUEST_METHOD'));
85*9e777ceeSAndreas Gohr        $this->assertEquals(
86*9e777ceeSAndreas Gohr            '?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3',
87*9e777ceeSAndreas Gohr            $request->getServer('QUERY_STRING')
88*9e777ceeSAndreas Gohr        );
89*9e777ceeSAndreas Gohr        $this->assertEquals(
90*9e777ceeSAndreas Gohr            '/doku.php?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3',
91*9e777ceeSAndreas Gohr            $request->getServer('REQUEST_URI')
92*9e777ceeSAndreas Gohr        );
93*9e777ceeSAndreas Gohr
94*9e777ceeSAndreas Gohr        // variable setup check
95*9e777ceeSAndreas Gohr        $this->assertEquals('A string', $request->getGet('string'));
96*9e777ceeSAndreas Gohr        $this->assertEquals(array(1, 2, 3), $request->getGet('array'));
97*9e777ceeSAndreas Gohr        $this->assertEquals('wiki:dokuwiki', $request->getGet('id'));
98*9e777ceeSAndreas Gohr        $this->assertEquals('bar', $request->getGet('test'));
99*9e777ceeSAndreas Gohr
100*9e777ceeSAndreas Gohr        // output check
101*9e777ceeSAndreas Gohr        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0);
102*9e777ceeSAndreas Gohr    }
103*9e777ceeSAndreas Gohr
104*9e777ceeSAndreas Gohr
105f8369d7dSTobias Sarnowski}
106