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
{
26 /** @var FauxResponse */
29 protected function setUp() {
31 $this->response
= new FauxResponse
;
35 * @covers FauxResponse::getcookie
36 * @covers FauxResponse::setcookie
38 public function testCookie() {
39 $this->assertEquals( null, $this->response
->getcookie( 'key' ), 'Non-existing cookie' );
40 $this->response
->setcookie( 'key', 'val' );
41 $this->assertEquals( 'val', $this->response
->getcookie( 'key' ), 'Existing cookie' );
45 * @covers FauxResponse::getheader
46 * @covers FauxResponse::header
48 public function testHeader() {
49 $this->assertEquals( null, $this->response
->getheader( 'Location' ), 'Non-existing header' );
51 $this->response
->header( 'Location: http://localhost/' );
54 $this->response
->getheader( 'Location' ),
58 $this->response
->header( 'Location: http://127.0.0.1/' );
61 $this->response
->getheader( 'Location' ),
65 $this->response
->header( 'Location: http://127.0.0.2/', false );
68 $this->response
->getheader( 'Location' ),
69 'Same header with override disabled'
72 $this->response
->header( 'Location: http://localhost/' );
75 $this->response
->getheader( 'LOCATION' ),
76 'Get header case insensitive'
81 * @covers FauxResponse::getStatusCode
83 public function testResponseCode() {
84 $this->response
->header( 'HTTP/1.1 200' );
85 $this->assertEquals( 200, $this->response
->getStatusCode(), 'Header with no message' );
87 $this->response
->header( 'HTTP/1.x 201' );
90 $this->response
->getStatusCode(),
91 'Header with no message and protocol 1.x'
94 $this->response
->header( 'HTTP/1.1 202 OK' );
95 $this->assertEquals( 202, $this->response
->getStatusCode(), 'Normal header' );
97 $this->response
->header( 'HTTP/1.x 203 OK' );
100 $this->response
->getStatusCode(),
101 'Normal header with no message and protocol 1.x'
104 $this->response
->header( 'HTTP/1.x 204 OK', false, 205 );
107 $this->response
->getStatusCode(),
108 'Third parameter overrides the HTTP/... header'
111 $this->response
->header( 'Location: http://localhost/', false, 206 );
114 $this->response
->getStatusCode(),
115 'Third parameter with another header'