MediaWiki
REL1_24
|
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( 00053 'http://localhost/', 00054 $this->response->getheader( 'Location' ), 00055 'Set header' 00056 ); 00057 00058 $this->response->header( 'Location: http://127.0.0.1/' ); 00059 $this->assertEquals( 00060 'http://127.0.0.1/', 00061 $this->response->getheader( 'Location' ), 00062 'Same header' 00063 ); 00064 00065 $this->response->header( 'Location: http://127.0.0.2/', false ); 00066 $this->assertEquals( 00067 'http://127.0.0.1/', 00068 $this->response->getheader( 'Location' ), 00069 'Same header with override disabled' 00070 ); 00071 00072 $this->response->header( 'Location: http://localhost/' ); 00073 $this->assertEquals( 00074 'http://localhost/', 00075 $this->response->getheader( 'LOCATION' ), 00076 'Get header case insensitive' 00077 ); 00078 } 00079 00083 public function testResponseCode() { 00084 $this->response->header( 'HTTP/1.1 200' ); 00085 $this->assertEquals( 200, $this->response->getStatusCode(), 'Header with no message' ); 00086 00087 $this->response->header( 'HTTP/1.x 201' ); 00088 $this->assertEquals( 00089 201, 00090 $this->response->getStatusCode(), 00091 'Header with no message and protocol 1.x' 00092 ); 00093 00094 $this->response->header( 'HTTP/1.1 202 OK' ); 00095 $this->assertEquals( 202, $this->response->getStatusCode(), 'Normal header' ); 00096 00097 $this->response->header( 'HTTP/1.x 203 OK' ); 00098 $this->assertEquals( 00099 203, 00100 $this->response->getStatusCode(), 00101 'Normal header with no message and protocol 1.x' 00102 ); 00103 00104 $this->response->header( 'HTTP/1.x 204 OK', false, 205 ); 00105 $this->assertEquals( 00106 205, 00107 $this->response->getStatusCode(), 00108 'Third parameter overrides the HTTP/... header' 00109 ); 00110 00111 $this->response->header( 'Location: http://localhost/', false, 206 ); 00112 $this->assertEquals( 00113 206, 00114 $this->response->getStatusCode(), 00115 'Third parameter with another header' 00116 ); 00117 } 00118 }