Merge "(bug 26585) Detect CSV/array values in $_SERVER['REMOTE_ADDR']."
[lhc/web/wiklou.git] / tests / phpunit / includes / FauxResponseTest.php
1 <?php
2 /**
3 * Tests for the FauxResponse class
4 *
5 * Copyright @ 2011 Alexandre Emsenhuber
6 *
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.
11 *
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.
16 *
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
21 *
22 * @file
23 */
24
25 class FauxResponseTest extends MediaWikiTestCase {
26 var $response;
27
28 protected function setUp() {
29 parent::setUp();
30 $this->response = new FauxResponse;
31 }
32
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' );
37 }
38
39 function testHeader() {
40 $this->assertEquals( null, $this->response->getheader( 'Location' ), 'Non-existing header' );
41
42 $this->response->header( 'Location: http://localhost/' );
43 $this->assertEquals( 'http://localhost/', $this->response->getheader( 'Location' ), 'Set header' );
44
45 $this->response->header( 'Location: http://127.0.0.1/' );
46 $this->assertEquals( 'http://127.0.0.1/', $this->response->getheader( 'Location' ), 'Same header' );
47
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' );
50 }
51
52 function testResponseCode() {
53 $this->response->header( 'HTTP/1.1 200' );
54 $this->assertEquals( 200, $this->response->getStatusCode(), 'Header with no message' );
55
56 $this->response->header( 'HTTP/1.x 201' );
57 $this->assertEquals( 201, $this->response->getStatusCode(), 'Header with no message and protocol 1.x' );
58
59 $this->response->header( 'HTTP/1.1 202 OK' );
60 $this->assertEquals( 202, $this->response->getStatusCode(), 'Normal header' );
61
62 $this->response->header( 'HTTP/1.x 203 OK' );
63 $this->assertEquals( 203, $this->response->getStatusCode(), 'Normal header with no message and protocol 1.x' );
64
65 $this->response->header( 'HTTP/1.x 204 OK', false, 205 );
66 $this->assertEquals( 205, $this->response->getStatusCode(), 'Third parameter overrides the HTTP/... header' );
67
68 $this->response->header( 'Location: http://localhost/', false, 206 );
69 $this->assertEquals( 206, $this->response->getStatusCode(), 'Third parameter with another header' );
70 }
71 }