3 * Tests for the FauxResponse class
5 * Copyright @ 2011 Alexandre Emsenhuber
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
25 class FauxResponseTest
extends MediaWikiTestCase
{
28 protected function setUp() {
30 $this->response
= new FauxResponse
;
33 function testCookie() {
34 $this->assertEquals( null, $this->response
->getcookie( 'key' ), 'Non-existing cookie' );
35 $this->response
->setcookie( 'key', 'val' );
36 $this->assertEquals( 'val', $this->response
->getcookie( 'key' ), 'Existing cookie' );
39 function testHeader() {
40 $this->assertEquals( null, $this->response
->getheader( 'Location' ), 'Non-existing header' );
42 $this->response
->header( 'Location: http://localhost/' );
43 $this->assertEquals( 'http://localhost/', $this->response
->getheader( 'Location' ), 'Set header' );
45 $this->response
->header( 'Location: http://127.0.0.1/' );
46 $this->assertEquals( 'http://127.0.0.1/', $this->response
->getheader( 'Location' ), 'Same header' );
48 $this->response
->header( 'Location: http://127.0.0.2/', false );
49 $this->assertEquals( 'http://127.0.0.1/', $this->response
->getheader( 'Location' ), 'Same header with override disabled' );
51 $this->response
->header( 'Location: http://localhost/' );
52 $this->assertEquals( 'http://localhost/', $this->response
->getheader( 'LOCATION' ), 'Get header case insensitive' );
55 function testResponseCode() {
56 $this->response
->header( 'HTTP/1.1 200' );
57 $this->assertEquals( 200, $this->response
->getStatusCode(), 'Header with no message' );
59 $this->response
->header( 'HTTP/1.x 201' );
60 $this->assertEquals( 201, $this->response
->getStatusCode(), 'Header with no message and protocol 1.x' );
62 $this->response
->header( 'HTTP/1.1 202 OK' );
63 $this->assertEquals( 202, $this->response
->getStatusCode(), 'Normal header' );
65 $this->response
->header( 'HTTP/1.x 203 OK' );
66 $this->assertEquals( 203, $this->response
->getStatusCode(), 'Normal header with no message and protocol 1.x' );
68 $this->response
->header( 'HTTP/1.x 204 OK', false, 205 );
69 $this->assertEquals( 205, $this->response
->getStatusCode(), 'Third parameter overrides the HTTP/... header' );
71 $this->response
->header( 'Location: http://localhost/', false, 206 );
72 $this->assertEquals( 206, $this->response
->getStatusCode(), 'Third parameter with another header' );