maintenance: Script to rename titles for Unicode uppercasing changes
[lhc/web/wiklou.git] / tests / phpunit / includes / FauxResponseTest.php
1 <?php
2 /**
3 * Copyright @ 2011 Alexandre Emsenhuber
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 class FauxResponseTest extends MediaWikiTestCase {
24 /** @var FauxResponse */
25 protected $response;
26
27 protected function setUp() {
28 parent::setUp();
29 $this->response = new FauxResponse;
30 }
31
32 /**
33 * @covers FauxResponse::setCookie
34 * @covers FauxResponse::getCookie
35 * @covers FauxResponse::getCookieData
36 * @covers FauxResponse::getCookies
37 */
38 public function testCookie() {
39 $expire = time() + 100;
40 $cookie = [
41 'value' => 'val',
42 'path' => '/path',
43 'domain' => 'domain',
44 'secure' => true,
45 'httpOnly' => false,
46 'raw' => false,
47 'expire' => $expire,
48 ];
49
50 $this->assertEquals( null, $this->response->getCookie( 'xkey' ), 'Non-existing cookie' );
51 $this->response->setCookie( 'key', 'val', $expire, [
52 'prefix' => 'x',
53 'path' => '/path',
54 'domain' => 'domain',
55 'secure' => 1,
56 'httpOnly' => 0,
57 ] );
58 $this->assertEquals( 'val', $this->response->getCookie( 'xkey' ), 'Existing cookie' );
59 $this->assertEquals( $cookie, $this->response->getCookieData( 'xkey' ),
60 'Existing cookie (data)' );
61 $this->assertEquals( [ 'xkey' => $cookie ], $this->response->getCookies(),
62 'Existing cookies' );
63 }
64
65 /**
66 * @covers FauxResponse::getheader
67 * @covers FauxResponse::header
68 */
69 public function testHeader() {
70 $this->assertEquals( null, $this->response->getHeader( 'Location' ), 'Non-existing header' );
71
72 $this->response->header( 'Location: http://localhost/' );
73 $this->assertEquals(
74 'http://localhost/',
75 $this->response->getHeader( 'Location' ),
76 'Set header'
77 );
78
79 $this->response->header( 'Location: http://127.0.0.1/' );
80 $this->assertEquals(
81 'http://127.0.0.1/',
82 $this->response->getHeader( 'Location' ),
83 'Same header'
84 );
85
86 $this->response->header( 'Location: http://127.0.0.2/', false );
87 $this->assertEquals(
88 'http://127.0.0.1/',
89 $this->response->getHeader( 'Location' ),
90 'Same header with override disabled'
91 );
92
93 $this->response->header( 'Location: http://localhost/' );
94 $this->assertEquals(
95 'http://localhost/',
96 $this->response->getHeader( 'LOCATION' ),
97 'Get header case insensitive'
98 );
99 }
100
101 /**
102 * @covers FauxResponse::getStatusCode
103 */
104 public function testResponseCode() {
105 $this->response->header( 'HTTP/1.1 200' );
106 $this->assertEquals( 200, $this->response->getStatusCode(), 'Header with no message' );
107
108 $this->response->header( 'HTTP/1.x 201' );
109 $this->assertEquals(
110 201,
111 $this->response->getStatusCode(),
112 'Header with no message and protocol 1.x'
113 );
114
115 $this->response->header( 'HTTP/1.1 202 OK' );
116 $this->assertEquals( 202, $this->response->getStatusCode(), 'Normal header' );
117
118 $this->response->header( 'HTTP/1.x 203 OK' );
119 $this->assertEquals(
120 203,
121 $this->response->getStatusCode(),
122 'Normal header with no message and protocol 1.x'
123 );
124
125 $this->response->header( 'HTTP/1.x 204 OK', false, 205 );
126 $this->assertEquals(
127 205,
128 $this->response->getStatusCode(),
129 'Third parameter overrides the HTTP/... header'
130 );
131
132 $this->response->statusHeader( 210 );
133 $this->assertEquals(
134 210,
135 $this->response->getStatusCode(),
136 'Handle statusHeader method'
137 );
138
139 $this->response->header( 'Location: http://localhost/', false, 206 );
140 $this->assertEquals(
141 206,
142 $this->response->getStatusCode(),
143 'Third parameter with another header'
144 );
145 }
146 }