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