Merge "Revert "Add executable rights for executable (bash) files""
[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(
53 'http://localhost/',
54 $this->response->getheader( 'Location' ),
55 'Set header'
56 );
57
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'
63 );
64
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'
70 );
71
72 $this->response->header( 'Location: http://localhost/' );
73 $this->assertEquals(
74 'http://localhost/',
75 $this->response->getheader( 'LOCATION' ),
76 'Get header case insensitive'
77 );
78 }
79
80 /**
81 * @covers FauxResponse::getStatusCode
82 */
83 public function testResponseCode() {
84 $this->response->header( 'HTTP/1.1 200' );
85 $this->assertEquals( 200, $this->response->getStatusCode(), 'Header with no message' );
86
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'
92 );
93
94 $this->response->header( 'HTTP/1.1 202 OK' );
95 $this->assertEquals( 202, $this->response->getStatusCode(), 'Normal header' );
96
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'
102 );
103
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'
109 );
110
111 $this->response->statusHeader( 210 );
112 $this->assertEquals(
113 210,
114 $this->response->getStatusCode(),
115 'Handle statusHeader method'
116 );
117
118 $this->response->header( 'Location: http://localhost/', false, 206 );
119 $this->assertEquals(
120 206,
121 $this->response->getStatusCode(),
122 'Third parameter with another header'
123 );
124 }
125 }