14 use PHPUnit\Framework\TestCase;
30 $this->assertEquals($expected, $bag->allPreserveCase(),
'->allPreserveCase() gets all input keys in original case');
37 array(
'fOo' =>
'BAR'),
38 array(
'fOo' => array(
'BAR'),
'Cache-Control' => array(
'no-cache, private')),
41 array(
'ETag' =>
'xyzzy'),
42 array(
'ETag' => array(
'xyzzy'),
'Cache-Control' => array(
'private, must-revalidate')),
45 array(
'Content-MD5' =>
'Q2hlY2sgSW50ZWdyaXR5IQ=='),
46 array(
'Content-MD5' => array(
'Q2hlY2sgSW50ZWdyaXR5IQ=='),
'Cache-Control' => array(
'no-cache, private')),
49 array(
'P3P' =>
'CP="CAO PSA OUR"'),
50 array(
'P3P' => array(
'CP="CAO PSA OUR"'),
'Cache-Control' => array(
'no-cache, private')),
53 array(
'WWW-Authenticate' =>
'Basic realm="WallyWorld"'),
54 array(
'WWW-Authenticate' => array(
'Basic realm="WallyWorld"'),
'Cache-Control' => array(
'no-cache, private')),
57 array(
'X-UA-Compatible' =>
'IE=edge,chrome=1'),
58 array(
'X-UA-Compatible' => array(
'IE=edge,chrome=1'),
'Cache-Control' => array(
'no-cache, private')),
61 array(
'X-XSS-Protection' =>
'1; mode=block'),
62 array(
'X-XSS-Protection' => array(
'1; mode=block'),
'Cache-Control' => array(
'no-cache, private')),
70 $this->assertEquals(
'no-cache, private', $bag->get(
'Cache-Control'));
71 $this->assertTrue($bag->hasCacheControlDirective(
'no-cache'));
74 $this->assertEquals(
'public', $bag->get(
'Cache-Control'));
75 $this->assertTrue($bag->hasCacheControlDirective(
'public'));
78 $this->assertEquals(
'private, must-revalidate', $bag->get(
'Cache-Control'));
79 $this->assertTrue($bag->hasCacheControlDirective(
'private'));
80 $this->assertTrue($bag->hasCacheControlDirective(
'must-revalidate'));
81 $this->assertFalse($bag->hasCacheControlDirective(
'max-age'));
83 $bag =
new ResponseHeaderBag(array(
'Expires' =>
'Wed, 16 Feb 2011 14:17:43 GMT'));
84 $this->assertEquals(
'private, must-revalidate', $bag->get(
'Cache-Control'));
87 'Expires' =>
'Wed, 16 Feb 2011 14:17:43 GMT',
88 'Cache-Control' =>
'max-age=3600',
90 $this->assertEquals(
'max-age=3600, private', $bag->get(
'Cache-Control'));
93 $this->assertEquals(
'private, must-revalidate', $bag->get(
'Cache-Control'));
95 $bag =
new ResponseHeaderBag(array(
'Etag' =>
'abcde',
'Last-Modified' =>
'abcde'));
96 $this->assertEquals(
'private, must-revalidate', $bag->get(
'Cache-Control'));
99 $this->assertEquals(
'max-age=100, private', $bag->get(
'Cache-Control'));
102 $this->assertEquals(
's-maxage=100', $bag->get(
'Cache-Control'));
105 $this->assertEquals(
'max-age=100, private', $bag->get(
'Cache-Control'));
108 $this->assertEquals(
'max-age=100, public', $bag->get(
'Cache-Control'));
111 $bag->set(
'Last-Modified',
'abcde');
112 $this->assertEquals(
'private, must-revalidate', $bag->get(
'Cache-Control'));
117 $headers = array(
'foo' =>
'bar');
120 $this->assertEquals($bag1->allPreserveCase(), $bag2->allPreserveCase());
126 $bag->setCookie(
new Cookie(
'foo',
'bar'));
128 $this->assertSetCookieHeader(
'foo=bar; path=/; httponly', $bag);
130 $bag->clearCookie(
'foo');
132 $this->assertSetCookieHeader(
'foo=deleted; expires='.gmdate(
'D, d-M-Y H:i:s T', time() - 31536001).
'; max-age=-31536001; path=/; httponly', $bag);
139 $bag->clearCookie(
'foo',
'/',
null,
true,
false);
141 $this->assertSetCookieHeader(
'foo=deleted; expires='.gmdate(
'D, d-M-Y H:i:s T', time() - 31536001).
'; max-age=-31536001; path=/; secure', $bag);
147 $this->assertEquals(
'no-cache, private', $bag->get(
'Cache-Control'));
148 $this->assertTrue($bag->hasCacheControlDirective(
'no-cache'));
150 $bag->replace(array(
'Cache-Control' =>
'public'));
151 $this->assertEquals(
'public', $bag->get(
'Cache-Control'));
152 $this->assertTrue($bag->hasCacheControlDirective(
'public'));
158 $this->assertEquals(
'no-cache, private', $bag->get(
'Cache-Control'));
159 $this->assertTrue($bag->hasCacheControlDirective(
'no-cache'));
161 $bag->remove(
'Cache-Control');
162 $bag->replace(array());
163 $this->assertEquals(
'no-cache, private', $bag->get(
'Cache-Control'));
164 $this->assertTrue($bag->hasCacheControlDirective(
'no-cache'));
170 $bag->setCookie(
new Cookie(
'foo',
'bar', 0,
'/path/foo',
'foo.bar'));
171 $bag->setCookie(
new Cookie(
'foo',
'bar', 0,
'/path/bar',
'foo.bar'));
172 $bag->setCookie(
new Cookie(
'foo',
'bar', 0,
'/path/bar',
'bar.foo'));
173 $bag->setCookie(
new Cookie(
'foo',
'bar'));
175 $this->assertCount(4, $bag->getCookies());
176 $this->assertEquals(
'foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag->get(
'set-cookie'));
177 $this->assertEquals(array(
178 'foo=bar; path=/path/foo; domain=foo.bar; httponly',
179 'foo=bar; path=/path/bar; domain=foo.bar; httponly',
180 'foo=bar; path=/path/bar; domain=bar.foo; httponly',
181 'foo=bar; path=/; httponly',
182 ), $bag->get(
'set-cookie',
null,
false));
184 $this->assertSetCookieHeader(
'foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag);
185 $this->assertSetCookieHeader(
'foo=bar; path=/path/bar; domain=foo.bar; httponly', $bag);
186 $this->assertSetCookieHeader(
'foo=bar; path=/path/bar; domain=bar.foo; httponly', $bag);
187 $this->assertSetCookieHeader(
'foo=bar; path=/; httponly', $bag);
191 $this->assertTrue(isset($cookies[
'foo.bar'][
'/path/foo'][
'foo']));
192 $this->assertTrue(isset($cookies[
'foo.bar'][
'/path/bar'][
'foo']));
193 $this->assertTrue(isset($cookies[
'bar.foo'][
'/path/bar'][
'foo']));
194 $this->assertTrue(isset($cookies[
''][
'/'][
'foo']));
200 $this->assertFalse($bag->has(
'set-cookie'));
202 $bag->setCookie(
new Cookie(
'foo',
'bar', 0,
'/path/foo',
'foo.bar'));
203 $bag->setCookie(
new Cookie(
'bar',
'foo', 0,
'/path/bar',
'foo.bar'));
204 $this->assertTrue($bag->has(
'set-cookie'));
207 $this->assertTrue(isset($cookies[
'foo.bar'][
'/path/foo']));
209 $bag->removeCookie(
'foo',
'/path/foo',
'foo.bar');
210 $this->assertTrue($bag->has(
'set-cookie'));
213 $this->assertFalse(isset($cookies[
'foo.bar'][
'/path/foo']));
215 $bag->removeCookie(
'bar',
'/path/bar',
'foo.bar');
216 $this->assertFalse($bag->has(
'set-cookie'));
219 $this->assertFalse(isset($cookies[
'foo.bar']));
225 $bag->setCookie(
new Cookie(
'foo',
'bar', 0));
226 $bag->setCookie(
new Cookie(
'bar',
'foo', 0));
229 $this->assertTrue(isset($cookies[
''][
'/']));
231 $bag->removeCookie(
'foo',
null);
233 $this->assertFalse(isset($cookies[
''][
'/'][
'foo']));
235 $bag->removeCookie(
'bar',
null);
237 $this->assertFalse(isset($cookies[
''][
'/'][
'bar']));
243 $bag->set(
'set-cookie',
'foo=bar');
244 $this->assertEquals(array(
new Cookie(
'foo',
'bar', 0,
'/',
null,
false,
false,
true)), $bag->getCookies());
246 $bag->set(
'set-cookie',
'foo2=bar2',
false);
247 $this->assertEquals(array(
248 new Cookie(
'foo',
'bar', 0,
'/',
null,
false,
false,
true),
249 new Cookie(
'foo2',
'bar2', 0,
'/',
null,
false,
false,
true),
250 ), $bag->getCookies());
252 $bag->remove(
'set-cookie');
253 $this->assertEquals(array(), $bag->getCookies());
263 $bag->getCookies(
'invalid_argument');
273 $headers->makeDisposition(
'invalid',
'foo.html');
283 $this->assertEquals($expected, $headers->makeDisposition($disposition, $filename, $filenameFallback));
290 $headers->set(
'Location',
'http://www.symfony.com');
291 $headers->set(
'Content-type',
'text/html');
295 $allHeaders = $headers->allPreserveCase();
296 $this->assertEquals(array(
'http://www.symfony.com'), $allHeaders[
'Location']);
297 $this->assertEquals(array(
'text/html'), $allHeaders[
'Content-type']);
303 array(
'attachment',
'foo.html',
'foo.html',
'attachment; filename="foo.html"'),
304 array(
'attachment',
'foo.html',
'',
'attachment; filename="foo.html"'),
305 array(
'attachment',
'foo bar.html',
'',
'attachment; filename="foo bar.html"'),
306 array(
'attachment',
'foo "bar".html',
'',
'attachment; filename="foo \\"bar\\".html"'),
307 array(
'attachment',
'foo%20bar.html',
'foo bar.html',
'attachment; filename="foo bar.html"; filename*=utf-8\'\'foo%2520bar.html'),
308 array(
'attachment',
'föö.html',
'foo.html',
'attachment; filename="foo.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
320 $headers->makeDisposition($disposition, $filename);
326 array(
'attachment',
'foo%20bar.html'),
327 array(
'attachment',
'foo/bar.html'),
328 array(
'attachment',
'/foo.html'),
329 array(
'attachment',
'foo\bar.html'),
330 array(
'attachment',
'\foo.html'),
331 array(
'attachment',
'föö.html'),
337 $this->assertRegExp(
'#^Set-Cookie:\s+'.preg_quote($expected,
'#').
'$#m', str_replace(
"\r\n",
"\n", (
string) $actual));