3 * Copyright @ 2011 Alexandre Emsenhuber
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.
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.
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
23 class FauxResponseTest
extends MediaWikiTestCase
{
24 /** @var FauxResponse */
27 protected function setUp() {
29 $this->response
= new FauxResponse
;
33 * @covers FauxResponse::setCookie
34 * @covers FauxResponse::getCookie
35 * @covers FauxResponse::getCookieData
36 * @covers FauxResponse::getCookies
38 public function testCookie() {
39 $expire = time() +
100;
50 $this->assertEquals( null, $this->response
->getCookie( 'xkey' ), 'Non-existing cookie' );
51 $this->response
->setCookie( 'key', 'val', $expire, [
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(),
66 * @covers FauxResponse::getheader
67 * @covers FauxResponse::header
69 public function testHeader() {
70 $this->assertEquals( null, $this->response
->getHeader( 'Location' ), 'Non-existing header' );
72 $this->response
->header( 'Location: http://localhost/' );
75 $this->response
->getHeader( 'Location' ),
79 $this->response
->header( 'Location: http://127.0.0.1/' );
82 $this->response
->getHeader( 'Location' ),
86 $this->response
->header( 'Location: http://127.0.0.2/', false );
89 $this->response
->getHeader( 'Location' ),
90 'Same header with override disabled'
93 $this->response
->header( 'Location: http://localhost/' );
96 $this->response
->getHeader( 'LOCATION' ),
97 'Get header case insensitive'
102 * @covers FauxResponse::getStatusCode
104 public function testResponseCode() {
105 $this->response
->header( 'HTTP/1.1 200' );
106 $this->assertEquals( 200, $this->response
->getStatusCode(), 'Header with no message' );
108 $this->response
->header( 'HTTP/1.x 201' );
111 $this->response
->getStatusCode(),
112 'Header with no message and protocol 1.x'
115 $this->response
->header( 'HTTP/1.1 202 OK' );
116 $this->assertEquals( 202, $this->response
->getStatusCode(), 'Normal header' );
118 $this->response
->header( 'HTTP/1.x 203 OK' );
121 $this->response
->getStatusCode(),
122 'Normal header with no message and protocol 1.x'
125 $this->response
->header( 'HTTP/1.x 204 OK', false, 205 );
128 $this->response
->getStatusCode(),
129 'Third parameter overrides the HTTP/... header'
132 $this->response
->statusHeader( 210 );
135 $this->response
->getStatusCode(),
136 'Handle statusHeader method'
139 $this->response
->header( 'Location: http://localhost/', false, 206 );
142 $this->response
->getStatusCode(),
143 'Third parameter with another header'