1f8369d7dSTobias Sarnowski<?php 2f8369d7dSTobias Sarnowski 3f8369d7dSTobias Sarnowski/** 4f8369d7dSTobias Sarnowski * @group integration 5f8369d7dSTobias Sarnowski */ 6f8369d7dSTobias Sarnowskiclass InttestsBasicTest extends DokuWikiTest { 7*fb0b3fbfSChristopher Smith 8*fb0b3fbfSChristopher Smith private $some_headers = array( 9*fb0b3fbfSChristopher Smith 'Content-Type: image/png', 10*fb0b3fbfSChristopher Smith 'Date: Fri, 22 Mar 2013 16:10:01 GMT', 11*fb0b3fbfSChristopher Smith 'X-Powered-By: PHP/5.3.15', 12*fb0b3fbfSChristopher Smith 'Expires: Sat, 23 Mar 2013 17:03:46 GMT', 13*fb0b3fbfSChristopher Smith 'Cache-Control: public, proxy-revalidate, no-transform, max-age=86400', 14*fb0b3fbfSChristopher Smith 'Pragma: public', 15*fb0b3fbfSChristopher Smith 'Last-Modified: Fri, 22 Mar 2013 01:48:28 GMT', 16*fb0b3fbfSChristopher Smith 'ETag: "63daab733b38c30c337229b2e587f8fb"', 17*fb0b3fbfSChristopher Smith 'Content-Disposition: inline; filename="fe389b0db8c1088c336abb502d2f9ae7.media.200x200.png', 18*fb0b3fbfSChristopher Smith 'Accept-Ranges: bytes', 19*fb0b3fbfSChristopher Smith 'Content-Type: image/png', 20*fb0b3fbfSChristopher Smith 'Content-Length: 62315', 21*fb0b3fbfSChristopher Smith 'Status: 200 OK', 22*fb0b3fbfSChristopher Smith 'Status: 404 Not Found', 23*fb0b3fbfSChristopher Smith ); 24*fb0b3fbfSChristopher 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( 36f8369d7dSTobias Sarnowski strpos($response->getContent(), 'DokuWiki') >= 0, 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 639e777ceeSAndreas Gohr $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); 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 879e777ceeSAndreas Gohr $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); 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 1199e777ceeSAndreas Gohr $this->assertTrue(strpos($response->getContent(), 'Andreas Gohr') >= 0); 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 141*fb0b3fbfSChristopher Smith function testHeaders(){ 142*fb0b3fbfSChristopher Smith $request = new TestRequest(); 143*fb0b3fbfSChristopher Smith $response = $request->get(array(),'/lib/exe/fetch.php?media=wiki:dokuwiki-128.png'); 144*fb0b3fbfSChristopher Smith $headers = $response->getHeaders(); 145*fb0b3fbfSChristopher Smith $this->assertTrue(!empty($headers)); 146*fb0b3fbfSChristopher Smith } 147*fb0b3fbfSChristopher Smith 148*fb0b3fbfSChristopher Smith function testGetHeader(){ 149*fb0b3fbfSChristopher Smith $response = new TestResponse('',$this->some_headers); 150*fb0b3fbfSChristopher Smith 151*fb0b3fbfSChristopher Smith $this->assertEquals('Pragma: public', $response->getHeader('Pragma')); 152*fb0b3fbfSChristopher Smith $this->assertEmpty($response->getHeader('Junk')); 153*fb0b3fbfSChristopher Smith $this->assertEquals(array('Content-Type: image/png','Content-Type: image/png'), $response->getHeader('Content-Type')); 154*fb0b3fbfSChristopher Smith } 155*fb0b3fbfSChristopher Smith 156*fb0b3fbfSChristopher Smith function testGetStatus(){ 157*fb0b3fbfSChristopher Smith $response = new TestResponse('',$this->some_headers); 158*fb0b3fbfSChristopher Smith $this->assertEquals(404, $response->getStatusCode()); 159*fb0b3fbfSChristopher Smith 160*fb0b3fbfSChristopher Smith $response = new TestResponse('',array_slice($this->some_headers,0,-2)); // slide off the last two headers to leave no status header 161*fb0b3fbfSChristopher Smith $this->assertNull($response->getStatusCode()); 162*fb0b3fbfSChristopher Smith } 163*fb0b3fbfSChristopher Smith 164f8369d7dSTobias Sarnowski} 165