MediaWiki  REL1_23
FauxResponseTest.php
Go to the documentation of this file.
00001 <?php
00025 class FauxResponseTest extends MediaWikiTestCase {
00027     protected $response;
00028 
00029     protected function setUp() {
00030         parent::setUp();
00031         $this->response = new FauxResponse;
00032     }
00033 
00038     public function testCookie() {
00039         $this->assertEquals( null, $this->response->getcookie( 'key' ), 'Non-existing cookie' );
00040         $this->response->setcookie( 'key', 'val' );
00041         $this->assertEquals( 'val', $this->response->getcookie( 'key' ), 'Existing cookie' );
00042     }
00043 
00048     public function testHeader() {
00049         $this->assertEquals( null, $this->response->getheader( 'Location' ), 'Non-existing header' );
00050 
00051         $this->response->header( 'Location: http://localhost/' );
00052         $this->assertEquals( 'http://localhost/', $this->response->getheader( 'Location' ), 'Set header' );
00053 
00054         $this->response->header( 'Location: http://127.0.0.1/' );
00055         $this->assertEquals( 'http://127.0.0.1/', $this->response->getheader( 'Location' ), 'Same header' );
00056 
00057         $this->response->header( 'Location: http://127.0.0.2/', false );
00058         $this->assertEquals( 'http://127.0.0.1/', $this->response->getheader( 'Location' ), 'Same header with override disabled' );
00059 
00060         $this->response->header( 'Location: http://localhost/' );
00061         $this->assertEquals( 'http://localhost/', $this->response->getheader( 'LOCATION' ), 'Get header case insensitive' );
00062     }
00063 
00067     public function testResponseCode() {
00068         $this->response->header( 'HTTP/1.1 200' );
00069         $this->assertEquals( 200, $this->response->getStatusCode(), 'Header with no message' );
00070 
00071         $this->response->header( 'HTTP/1.x 201' );
00072         $this->assertEquals( 201, $this->response->getStatusCode(), 'Header with no message and protocol 1.x' );
00073 
00074         $this->response->header( 'HTTP/1.1 202 OK' );
00075         $this->assertEquals( 202, $this->response->getStatusCode(), 'Normal header' );
00076 
00077         $this->response->header( 'HTTP/1.x 203 OK' );
00078         $this->assertEquals( 203, $this->response->getStatusCode(), 'Normal header with no message and protocol 1.x' );
00079 
00080         $this->response->header( 'HTTP/1.x 204 OK', false, 205 );
00081         $this->assertEquals( 205, $this->response->getStatusCode(), 'Third parameter overrides the HTTP/... header' );
00082 
00083         $this->response->header( 'Location: http://localhost/', false, 206 );
00084         $this->assertEquals( 206, $this->response->getStatusCode(), 'Third parameter with another header' );
00085     }
00086 }