MediaWiki REL1_33
FauxResponseTest.php
Go to the documentation of this file.
1<?php
25 protected $response;
26
27 protected function setUp() {
28 parent::setUp();
29 $this->response = new FauxResponse;
30 }
31
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
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
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}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
testCookie()
FauxResponse::setCookie FauxResponse::getCookie FauxResponse::getCookieData FauxResponse::getCookies.
testHeader()
FauxResponse::getheader FauxResponse::header.
FauxResponse $response
testResponseCode()
FauxResponse::getStatusCode.