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
{
29 $this->response
= new FauxResponse
;
32 function testCookie() {
33 $this->assertEquals( null, $this->response
->getcookie( 'key' ), 'Non-existing cookie' );
34 $this->response
->setcookie( 'key', 'val' );
35 $this->assertEquals( 'val', $this->response
->getcookie( 'key' ), 'Existing cookie' );
38 function testHeader() {
39 $this->assertEquals( null, $this->response
->getheader( 'Location' ), 'Non-existing header' );
41 $this->response
->header( 'Location: http://localhost/' );
42 $this->assertEquals( 'http://localhost/', $this->response
->getheader( 'Location' ), 'Set header' );
44 $this->response
->header( 'Location: http://127.0.0.1/' );
45 $this->assertEquals( 'http://127.0.0.1/', $this->response
->getheader( 'Location' ), 'Same header' );
47 $this->response
->header( 'Location: http://127.0.0.2/', false );
48 $this->assertEquals( 'http://127.0.0.1/', $this->response
->getheader( 'Location' ), 'Same header with override disabled' );
51 function testResponseCode() {
52 $this->response
->header( 'HTTP/1.1 200' );
53 $this->assertEquals( 200, $this->response
->getStatusCode(), 'Header with no message' );
55 $this->response
->header( 'HTTP/1.x 201' );
56 $this->assertEquals( 201, $this->response
->getStatusCode(), 'Header with no message and protocol 1.x' );
58 $this->response
->header( 'HTTP/1.1 202 OK' );
59 $this->assertEquals( 202, $this->response
->getStatusCode(), 'Normal header' );
61 $this->response
->header( 'HTTP/1.x 203 OK' );
62 $this->assertEquals( 203, $this->response
->getStatusCode(), 'Normal header with no message and protocol 1.x' );
64 $this->response
->header( 'HTTP/1.x 204 OK', false, 205 );
65 $this->assertEquals( 205, $this->response
->getStatusCode(), 'Third parameter overrides the HTTP/... header' );
67 $this->response
->header( 'Location: http://localhost/', false, 206 );
68 $this->assertEquals( 206, $this->response
->getStatusCode(), 'Third parameter with another header' );