|
20 | 20 | */
|
21 | 21 | class ResponseHeaderBagTest extends TestCase
|
22 | 22 | {
|
23 |
| - /** |
24 |
| - * @dataProvider provideAllPreserveCase |
25 |
| - */ |
26 |
| - public function testAllPreserveCase($headers, $expected) |
| 23 | + public function testAllPreserveCase() |
27 | 24 | {
|
| 25 | + $headers = array( |
| 26 | + 'fOo' => 'BAR', |
| 27 | + 'ETag' => 'xyzzy', |
| 28 | + 'Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ==', |
| 29 | + 'P3P' => 'CP="CAO PSA OUR"', |
| 30 | + 'WWW-Authenticate' => 'Basic realm="WallyWorld"', |
| 31 | + 'X-UA-Compatible' => 'IE=edge,chrome=1', |
| 32 | + 'X-XSS-Protection' => '1; mode=block', |
| 33 | + ); |
| 34 | + |
28 | 35 | $bag = new ResponseHeaderBag($headers);
|
| 36 | + $allPreservedCase = $bag->allPreserveCase(); |
29 | 37 |
|
30 |
| - $this->assertEquals($expected, $bag->allPreserveCase(), '->allPreserveCase() gets all input keys in original case'); |
31 |
| - } |
32 |
| - |
33 |
| - public function provideAllPreserveCase() |
34 |
| - { |
35 |
| - return array( |
36 |
| - array( |
37 |
| - array('fOo' => 'BAR'), |
38 |
| - array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache, private')), |
39 |
| - ), |
40 |
| - array( |
41 |
| - array('ETag' => 'xyzzy'), |
42 |
| - array('ETag' => array('xyzzy'), 'Cache-Control' => array('private, must-revalidate')), |
43 |
| - ), |
44 |
| - array( |
45 |
| - array('Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ=='), |
46 |
| - array('Content-MD5' => array('Q2hlY2sgSW50ZWdyaXR5IQ=='), 'Cache-Control' => array('no-cache, private')), |
47 |
| - ), |
48 |
| - array( |
49 |
| - array('P3P' => 'CP="CAO PSA OUR"'), |
50 |
| - array('P3P' => array('CP="CAO PSA OUR"'), 'Cache-Control' => array('no-cache, private')), |
51 |
| - ), |
52 |
| - array( |
53 |
| - array('WWW-Authenticate' => 'Basic realm="WallyWorld"'), |
54 |
| - array('WWW-Authenticate' => array('Basic realm="WallyWorld"'), 'Cache-Control' => array('no-cache, private')), |
55 |
| - ), |
56 |
| - array( |
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')), |
59 |
| - ), |
60 |
| - array( |
61 |
| - array('X-XSS-Protection' => '1; mode=block'), |
62 |
| - array('X-XSS-Protection' => array('1; mode=block'), 'Cache-Control' => array('no-cache, private')), |
63 |
| - ), |
64 |
| - ); |
| 38 | + foreach (array_keys($headers) as $headerName) { |
| 39 | + $this->assertArrayHasKey($headerName, $allPreservedCase, '->allPreserveCase() gets all input keys in original case'); |
| 40 | + } |
65 | 41 | }
|
66 | 42 |
|
67 | 43 | public function testCacheControlHeader()
|
@@ -332,6 +308,43 @@ public function provideMakeDispositionFail()
|
332 | 308 | );
|
333 | 309 | }
|
334 | 310 |
|
| 311 | + public function testDateHeaderAddedOnCreation() |
| 312 | + { |
| 313 | + $now = time(); |
| 314 | + |
| 315 | + $bag = new ResponseHeaderBag(); |
| 316 | + $this->assertTrue($bag->has('Date')); |
| 317 | + |
| 318 | + $this->assertEquals($now, $bag->getDate('Date')->getTimestamp()); |
| 319 | + } |
| 320 | + |
| 321 | + public function testDateHeaderCanBeSetOnCreation() |
| 322 | + { |
| 323 | + $someDate = 'Thu, 23 Mar 2017 09:15:12 GMT'; |
| 324 | + $bag = new ResponseHeaderBag(array('Date' => $someDate)); |
| 325 | + |
| 326 | + $this->assertEquals($someDate, $bag->get('Date')); |
| 327 | + } |
| 328 | + |
| 329 | + public function testDateHeaderWillBeRecreatedWhenRemoved() |
| 330 | + { |
| 331 | + $someDate = 'Thu, 23 Mar 2017 09:15:12 GMT'; |
| 332 | + $bag = new ResponseHeaderBag(array('Date' => $someDate)); |
| 333 | + $bag->remove('Date'); |
| 334 | + |
| 335 | + // a (new) Date header is still present |
| 336 | + $this->assertTrue($bag->has('Date')); |
| 337 | + $this->assertNotEquals($someDate, $bag->get('Date')); |
| 338 | + } |
| 339 | + |
| 340 | + public function testDateHeaderWillBeRecreatedWhenHeadersAreReplaced() |
| 341 | + { |
| 342 | + $bag = new ResponseHeaderBag(); |
| 343 | + $bag->replace(array()); |
| 344 | + |
| 345 | + $this->assertTrue($bag->has('Date')); |
| 346 | + } |
| 347 | + |
335 | 348 | private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
|
336 | 349 | {
|
337 | 350 | $this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
|
|
0 commit comments