Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / FauxResponseTest.php
blob4a974ba2db6225ab20843caf5a0b484ac8abd75a
1 <?php
2 /**
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
22 * @file
25 class FauxResponseTest extends MediaWikiTestCase {
26 /** @var FauxResponse */
27 protected $response;
29 protected function setUp() {
30 parent::setUp();
31 $this->response = new FauxResponse;
34 /**
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' );
44 /**
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/' );
52 $this->assertEquals(
53 'http://localhost/',
54 $this->response->getheader( 'Location' ),
55 'Set header'
58 $this->response->header( 'Location: http://127.0.0.1/' );
59 $this->assertEquals(
60 'http://127.0.0.1/',
61 $this->response->getheader( 'Location' ),
62 'Same header'
65 $this->response->header( 'Location: http://127.0.0.2/', false );
66 $this->assertEquals(
67 'http://127.0.0.1/',
68 $this->response->getheader( 'Location' ),
69 'Same header with override disabled'
72 $this->response->header( 'Location: http://localhost/' );
73 $this->assertEquals(
74 'http://localhost/',
75 $this->response->getheader( 'LOCATION' ),
76 'Get header case insensitive'
80 /**
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' );
88 $this->assertEquals(
89 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' );
98 $this->assertEquals(
99 203,
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 );
105 $this->assertEquals(
106 205,
107 $this->response->getStatusCode(),
108 'Third parameter overrides the HTTP/... header'
111 $this->response->header( 'Location: http://localhost/', false, 206 );
112 $this->assertEquals(
113 206,
114 $this->response->getStatusCode(),
115 'Third parameter with another header'