Merge "mw.language.convertPlural: Check if matching form exists"
[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 FauxResponse */
27 protected $response;
28
29 protected function setUp() {
30 parent::setUp();
31 $this->response = new FauxResponse;
32 }
33
34 /**
35 * @covers FauxResponse::getcookie
36 * @covers FauxResponse::setcookie
37 */
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' );
42 }
43
44 /**
45 * @covers FauxResponse::getheader
46 * @covers FauxResponse::header
47 */
48 public function testHeader() {
49 $this->assertEquals( null, $this->response->getheader( 'Location' ), 'Non-existing header' );
50
51 $this->response->header( 'Location: http://localhost/' );
52 $this->assertEquals( 'http://localhost/', $this->response->getheader( 'Location' ), 'Set header' );
53
54 $this->response->header( 'Location: http://127.0.0.1/' );
55 $this->assertEquals( 'http://127.0.0.1/', $this->response->getheader( 'Location' ), 'Same header' );
56
57 $this->response->header( 'Location: http://127.0.0.2/', false );
58 $this->assertEquals( 'http://127.0.0.1/', $this->response->getheader( 'Location' ), 'Same header with override disabled' );
59
60 $this->response->header( 'Location: http://localhost/' );
61 $this->assertEquals( 'http://localhost/', $this->response->getheader( 'LOCATION' ), 'Get header case insensitive' );
62 }
63
64 /**
65 * @covers FauxResponse::getStatusCode
66 */
67 public function testResponseCode() {
68 $this->response->header( 'HTTP/1.1 200' );
69 $this->assertEquals( 200, $this->response->getStatusCode(), 'Header with no message' );
70
71 $this->response->header( 'HTTP/1.x 201' );
72 $this->assertEquals( 201, $this->response->getStatusCode(), 'Header with no message and protocol 1.x' );
73
74 $this->response->header( 'HTTP/1.1 202 OK' );
75 $this->assertEquals( 202, $this->response->getStatusCode(), 'Normal header' );
76
77 $this->response->header( 'HTTP/1.x 203 OK' );
78 $this->assertEquals( 203, $this->response->getStatusCode(), 'Normal header with no message and protocol 1.x' );
79
80 $this->response->header( 'HTTP/1.x 204 OK', false, 205 );
81 $this->assertEquals( 205, $this->response->getStatusCode(), 'Third parameter overrides the HTTP/... header' );
82
83 $this->response->header( 'Location: http://localhost/', false, 206 );
84 $this->assertEquals( 206, $this->response->getStatusCode(), 'Third parameter with another header' );
85 }
86 }