xref: /dokuwiki/_test/tests/test/basic.test.php (revision fe717f57f7a1c262eb6104ccb575ee3294712afa)
1f8369d7dSTobias Sarnowski<?php
2f8369d7dSTobias Sarnowski
3f8369d7dSTobias Sarnowski/**
4f8369d7dSTobias Sarnowski * @group integration
5f8369d7dSTobias Sarnowski */
6f8369d7dSTobias Sarnowskiclass InttestsBasicTest extends DokuWikiTest {
7fb0b3fbfSChristopher Smith
8fb0b3fbfSChristopher Smith    private $some_headers =  array(
9fb0b3fbfSChristopher Smith          'Content-Type: image/png',
10fb0b3fbfSChristopher Smith          'Date: Fri, 22 Mar 2013 16:10:01 GMT',
11fb0b3fbfSChristopher Smith          'X-Powered-By: PHP/5.3.15',
12fb0b3fbfSChristopher Smith          'Expires: Sat, 23 Mar 2013 17:03:46 GMT',
13fb0b3fbfSChristopher Smith          'Cache-Control: public, proxy-revalidate, no-transform, max-age=86400',
14fb0b3fbfSChristopher Smith          'Pragma: public',
15fb0b3fbfSChristopher Smith          'Last-Modified: Fri, 22 Mar 2013 01:48:28 GMT',
16fb0b3fbfSChristopher Smith          'ETag: "63daab733b38c30c337229b2e587f8fb"',
17fb0b3fbfSChristopher Smith          'Content-Disposition: inline; filename="fe389b0db8c1088c336abb502d2f9ae7.media.200x200.png',
18fb0b3fbfSChristopher Smith          'Accept-Ranges: bytes',
19fb0b3fbfSChristopher Smith          'Content-Type: image/png',
20fb0b3fbfSChristopher Smith          'Content-Length: 62315',
21fb0b3fbfSChristopher Smith          'Status: 200 OK',
22fb0b3fbfSChristopher Smith          'Status: 404 Not Found',
23fb0b3fbfSChristopher Smith     );
24fb0b3fbfSChristopher Smith
25f8369d7dSTobias Sarnowski    /**
26f8369d7dSTobias Sarnowski     * Execute the simplest possible request and expect
27f8369d7dSTobias Sarnowski     * a dokuwiki page which obviously has the word "DokuWiki"
28f8369d7dSTobias Sarnowski     * in it somewhere.
29f8369d7dSTobias Sarnowski     */
30f8369d7dSTobias Sarnowski    function testSimpleRun() {
31f8369d7dSTobias Sarnowski        $request = new TestRequest();
32f8369d7dSTobias Sarnowski
33f8369d7dSTobias Sarnowski        $response = $request->execute();
34f8369d7dSTobias Sarnowski
35f8369d7dSTobias Sarnowski        $this->assertTrue(
36*fe717f57Slisps            strpos($response->getContent(), 'DokuWiki') !== false,
37f8369d7dSTobias Sarnowski            'DokuWiki was not a word in the output'
38f8369d7dSTobias Sarnowski        );
39f8369d7dSTobias Sarnowski    }
409e777ceeSAndreas Gohr
419e777ceeSAndreas Gohr    function testPost() {
429e777ceeSAndreas Gohr        $request = new TestRequest();
439e777ceeSAndreas Gohr
449e777ceeSAndreas Gohr        $input = array(
459e777ceeSAndreas Gohr            'string' => 'A string',
469e777ceeSAndreas Gohr            'array'  => array(1, 2, 3),
479e777ceeSAndreas Gohr            'id'     => 'wiki:dokuwiki'
489e777ceeSAndreas Gohr        );
499e777ceeSAndreas Gohr
509e777ceeSAndreas Gohr        $response = $request->post($input);
519e777ceeSAndreas Gohr
529e777ceeSAndreas Gohr        // server var check
539e777ceeSAndreas Gohr        $this->assertEquals('POST',$request->getServer('REQUEST_METHOD'));
549e777ceeSAndreas Gohr        $this->assertEquals('',$request->getServer('QUERY_STRING'));
559e777ceeSAndreas Gohr        $this->assertEquals('/doku.php',$request->getServer('REQUEST_URI'));
569e777ceeSAndreas Gohr
579e777ceeSAndreas Gohr        // variable setup check
589e777ceeSAndreas Gohr        $this->assertEquals('A string', $request->getPost('string'));
599e777ceeSAndreas Gohr        $this->assertEquals(array(1, 2, 3), $request->getPost('array'));
609e777ceeSAndreas Gohr        $this->assertEquals('wiki:dokuwiki', $request->getPost('id'));
619e777ceeSAndreas Gohr
629e777ceeSAndreas Gohr        // output check
63*fe717f57Slisps        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') !== false);
649e777ceeSAndreas Gohr    }
659e777ceeSAndreas Gohr
669e777ceeSAndreas Gohr    function testPostGet() {
679e777ceeSAndreas Gohr        $request = new TestRequest();
689e777ceeSAndreas Gohr
699e777ceeSAndreas Gohr        $input = array(
709e777ceeSAndreas Gohr            'string' => 'A string',
719e777ceeSAndreas Gohr            'array'  => array(1, 2, 3),
729e777ceeSAndreas Gohr        );
739e777ceeSAndreas Gohr
749e777ceeSAndreas Gohr        $response = $request->post($input,'/doku.php?id=wiki:dokuwiki');
759e777ceeSAndreas Gohr
769e777ceeSAndreas Gohr        // server var check
779e777ceeSAndreas Gohr        $this->assertEquals('POST',$request->getServer('REQUEST_METHOD'));
789e777ceeSAndreas Gohr        $this->assertEquals('?id=wiki:dokuwiki',$request->getServer('QUERY_STRING'));
799e777ceeSAndreas Gohr        $this->assertEquals('/doku.php?id=wiki:dokuwiki',$request->getServer('REQUEST_URI'));
809e777ceeSAndreas Gohr
819e777ceeSAndreas Gohr        // variable setup check
829e777ceeSAndreas Gohr        $this->assertEquals('A string', $request->getPost('string'));
839e777ceeSAndreas Gohr        $this->assertEquals(array(1, 2, 3), $request->getPost('array'));
849e777ceeSAndreas Gohr        $this->assertEquals('wiki:dokuwiki', $request->getGet('id'));
859e777ceeSAndreas Gohr
869e777ceeSAndreas Gohr        // output check
87*fe717f57Slisps        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') !== false);
889e777ceeSAndreas Gohr    }
899e777ceeSAndreas Gohr
909e777ceeSAndreas Gohr    function testGet() {
919e777ceeSAndreas Gohr        $request = new TestRequest();
929e777ceeSAndreas Gohr
939e777ceeSAndreas Gohr        $input = array(
949e777ceeSAndreas Gohr            'string' => 'A string',
959e777ceeSAndreas Gohr            'array'  => array(1, 2, 3),
969e777ceeSAndreas Gohr            'test'   => 'bar'
979e777ceeSAndreas Gohr        );
989e777ceeSAndreas Gohr
999e777ceeSAndreas Gohr        $response = $request->get($input,'/doku.php?id=wiki:dokuwiki&test=foo');
1009e777ceeSAndreas Gohr
1019e777ceeSAndreas Gohr        // server var check
1029e777ceeSAndreas Gohr        $this->assertEquals('GET',$request->getServer('REQUEST_METHOD'));
1039e777ceeSAndreas Gohr        $this->assertEquals(
1049e777ceeSAndreas Gohr            '?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3',
1059e777ceeSAndreas Gohr            $request->getServer('QUERY_STRING')
1069e777ceeSAndreas Gohr        );
1079e777ceeSAndreas Gohr        $this->assertEquals(
1089e777ceeSAndreas Gohr            '/doku.php?id=wiki:dokuwiki&test=bar&string=A+string&array[0]=1&array[1]=2&array[2]=3',
1099e777ceeSAndreas Gohr            $request->getServer('REQUEST_URI')
1109e777ceeSAndreas Gohr        );
1119e777ceeSAndreas Gohr
1129e777ceeSAndreas Gohr        // variable setup check
1139e777ceeSAndreas Gohr        $this->assertEquals('A string', $request->getGet('string'));
1149e777ceeSAndreas Gohr        $this->assertEquals(array(1, 2, 3), $request->getGet('array'));
1159e777ceeSAndreas Gohr        $this->assertEquals('wiki:dokuwiki', $request->getGet('id'));
1169e777ceeSAndreas Gohr        $this->assertEquals('bar', $request->getGet('test'));
1179e777ceeSAndreas Gohr
1189e777ceeSAndreas Gohr        // output check
119*fe717f57Slisps        $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') !== false);
1209e777ceeSAndreas Gohr    }
1219e777ceeSAndreas Gohr
1229894e7afSChristopher Smith    function testScripts() {
1239894e7afSChristopher Smith        $request = new TestRequest();
1249894e7afSChristopher Smith
1259894e7afSChristopher Smith        // doku
1269894e7afSChristopher Smith        $response = $request->get();
1279894e7afSChristopher Smith        $this->assertEquals('doku.php',$request->getScript());
1289894e7afSChristopher Smith
1299894e7afSChristopher Smith        $response = $request->get(array(),'/doku.php?id=wiki:dokuwiki&test=foo');
1309894e7afSChristopher Smith        $this->assertEquals('doku.php',$request->getScript());
1319894e7afSChristopher Smith
1329894e7afSChristopher Smith        // fetch
1339894e7afSChristopher Smith        $response = $request->get(array(),'/lib/exe/fetch.php?media=wiki:dokuwiki-128.png');
1349894e7afSChristopher Smith        $this->assertEquals('lib/exe/fetch.php',$request->getScript());
1359894e7afSChristopher Smith
1369894e7afSChristopher Smith        // detail
1379894e7afSChristopher Smith        $response = $request->get(array(),'/lib/exe/detail.php?id=start&media=wiki:dokuwiki-128.png');
1389894e7afSChristopher Smith        $this->assertEquals('lib/exe/detail.php',$request->getScript());
1399894e7afSChristopher Smith    }
1409e777ceeSAndreas Gohr
141fb0b3fbfSChristopher Smith    function testHeaders(){
1423e8bad3aSChristopher Smith        header('X-Test: check headers working');
1433e8bad3aSChristopher Smith        $header_check = function_exists('xdebug_get_headers') ? xdebug_get_headers() : headers_list();
1443e8bad3aSChristopher Smith        if (empty($header_check)) {
1453e8bad3aSChristopher Smith            $this->markTestSkipped('headers not returned, perhaps your sapi does not return headers, try xdebug');
1463e8bad3aSChristopher Smith        } else {
1473e8bad3aSChristopher Smith            header_remove('X-Test');
1483e8bad3aSChristopher Smith        }
1493e8bad3aSChristopher Smith
150fb0b3fbfSChristopher Smith        $request = new TestRequest();
151fb0b3fbfSChristopher Smith        $response = $request->get(array(),'/lib/exe/fetch.php?media=wiki:dokuwiki-128.png');
152fb0b3fbfSChristopher Smith        $headers = $response->getHeaders();
153fb0b3fbfSChristopher Smith        $this->assertTrue(!empty($headers));
154fb0b3fbfSChristopher Smith    }
155fb0b3fbfSChristopher Smith
156fb0b3fbfSChristopher Smith    function testGetHeader(){
157fb0b3fbfSChristopher Smith        $response = new TestResponse('',$this->some_headers);
158fb0b3fbfSChristopher Smith
159fb0b3fbfSChristopher Smith        $this->assertEquals('Pragma: public', $response->getHeader('Pragma'));
160fb0b3fbfSChristopher Smith        $this->assertEmpty($response->getHeader('Junk'));
161fb0b3fbfSChristopher Smith        $this->assertEquals(array('Content-Type: image/png','Content-Type: image/png'), $response->getHeader('Content-Type'));
162fb0b3fbfSChristopher Smith    }
163fb0b3fbfSChristopher Smith
164fb0b3fbfSChristopher Smith    function testGetStatus(){
165fb0b3fbfSChristopher Smith       $response = new TestResponse('',$this->some_headers);
166fb0b3fbfSChristopher Smith       $this->assertEquals(404, $response->getStatusCode());
167fb0b3fbfSChristopher Smith
1683e8bad3aSChristopher Smith       $response = new TestResponse('',array_slice($this->some_headers,0,-2));  // slice off the last two headers to leave no status header
169fb0b3fbfSChristopher Smith       $this->assertNull($response->getStatusCode());
170fb0b3fbfSChristopher Smith    }
171fb0b3fbfSChristopher Smith
172*fe717f57Slisps    function testINPUT() {
173*fe717f57Slisps        $request = new TestRequest();
174*fe717f57Slisps        $response = $request->get(array('id' => 'mailinglist'), '/doku.php');
175*fe717f57Slisps
176*fe717f57Slisps        // output check
177*fe717f57Slisps        $this->assertTrue(strpos($response->getContent(), 'Netiquette') !== false);
178*fe717f57Slisps    }
179*fe717f57Slisps
180f8369d7dSTobias Sarnowski}
181