@@ -249,6 +249,14 @@ public function testCacheControlMerging(array $expects, array $master, array $su
249
249
250
250
foreach ($ config as $ key => $ value ) {
251
251
switch ($ key ) {
252
+ case 'age ' :
253
+ $ response ->headers ->set ('Age ' , $ value );
254
+ break ;
255
+
256
+ case 'expires ' :
257
+ $ response ->setExpires ((clone $ response ->getDate ())->modify ('+ ' .$ value .' seconds ' ));
258
+ break ;
259
+
252
260
case 'max-age ' :
253
261
$ response ->setMaxAge ($ value );
254
262
break ;
@@ -281,12 +289,19 @@ public function testCacheControlMerging(array $expects, array $master, array $su
281
289
$ cacheStrategy ->update ($ response );
282
290
283
291
foreach ($ expects as $ key => $ value ) {
284
- if (true === $ value ) {
292
+ if ($ key === 'expires ' ) {
293
+ $ this ->assertSame ($ value , $ response ->getExpires ()->format ('U ' ) - $ response ->getDate ()->format ('U ' ));
294
+ } else if ($ key === 'age ' ) {
295
+ $ this ->assertSame ($ value , $ response ->getAge ());
296
+ } elseif (true === $ value ) {
285
297
$ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ($ key ), sprintf ('Cache-Control header must have "%s" flag ' , $ key ));
286
298
} elseif (false === $ value ) {
287
- $ this ->assertFalse ($ response ->headers ->hasCacheControlDirective ($ key ), sprintf ('Cache-Control header must NOT have "%s" flag ' , $ key ));
299
+ $ this ->assertFalse (
300
+ $ response ->headers ->hasCacheControlDirective ($ key ),
301
+ sprintf ('Cache-Control header must NOT have "%s" flag ' , $ key )
302
+ );
288
303
} else {
289
- $ this ->assertEquals ($ value , $ response ->headers ->getCacheControlDirective ($ key ), sprintf ('Cache-Control flag "%s" should be "%s" ' , $ key , $ value ));
304
+ $ this ->assertSame ($ value , $ response ->headers ->getCacheControlDirective ($ key ), sprintf ('Cache-Control flag "%s" should be "%s" ' , $ key , $ value ));
290
305
}
291
306
}
292
307
}
@@ -334,15 +349,15 @@ public function cacheControlMergingProvider()
334
349
);
335
350
336
351
yield 'resolve to lowest possible max-age ' => array (
337
- array ('public ' => false , 'private ' => true , 's-maxage ' => false , 'max-age ' => 60 ),
352
+ array ('public ' => false , 'private ' => true , 's-maxage ' => false , 'max-age ' => ' 60 ' ),
338
353
array ('public ' => true , 'max-age ' => 3600 ),
339
354
array (
340
355
array ('private ' => true , 'max-age ' => 60 ),
341
356
),
342
357
);
343
358
344
359
yield 'resolves multiple max-age ' => array (
345
- array ('public ' => false , 'private ' => true , 's-maxage ' => false , 'max-age ' => 60 ),
360
+ array ('public ' => false , 'private ' => true , 's-maxage ' => false , 'max-age ' => ' 60 ' ),
346
361
array ('private ' => true , 'max-age ' => 100 ),
347
362
array (
348
363
array ('private ' => true , 'max-age ' => 3600 ),
@@ -352,7 +367,7 @@ public function cacheControlMergingProvider()
352
367
);
353
368
354
369
yield 'merge max-age and s-maxage ' => array (
355
- array ('public ' => true , 's-maxage ' => 60 , 'max-age ' => null ),
370
+ array ('public ' => true , 's-maxage ' => ' 60 ' , 'max-age ' => null ),
356
371
array ('public ' => true , 's-maxage ' => 3600 ),
357
372
array (
358
373
array ('public ' => true , 'max-age ' => 60 ),
@@ -368,13 +383,85 @@ public function cacheControlMergingProvider()
368
383
);
369
384
370
385
yield 'result can have s-maxage and max-age ' => array (
371
- array ('public ' => true , 'private ' => false , 's-maxage ' => 60 , 'max-age ' => 30 ),
386
+ array ('public ' => true , 'private ' => false , 's-maxage ' => ' 60 ' , 'max-age ' => ' 30 ' ),
372
387
array ('s-maxage ' => 100 , 'max-age ' => 2000 ),
373
388
array (
374
389
array ('s-maxage ' => 1000 , 'max-age ' => 30 ),
375
390
array ('s-maxage ' => 500 , 'max-age ' => 500 ),
376
391
array ('s-maxage ' => 60 , 'max-age ' => 1000 ),
377
392
),
378
393
);
394
+
395
+ yield 'does not set headers without value ' => array (
396
+ array ('max-age ' => null , 's-maxage ' => null , 'public ' => null ),
397
+ array ('private ' => true ),
398
+ array (
399
+ array ('private ' => true ),
400
+ ),
401
+ );
402
+
403
+ yield 'max-age 0 is sent to the client ' => array (
404
+ array ('private ' => true , 'max-age ' => '0 ' ),
405
+ array ('max-age ' => 0 , 'private ' => true ),
406
+ array (
407
+ array ('max-age ' => 60 , 'private ' => true ),
408
+ ),
409
+ );
410
+
411
+ yield 'max-age is relative to age ' => array (
412
+ array ('max-age ' => '240 ' , 'age ' => 60 ),
413
+ array ('max-age ' => 180 ),
414
+ array (
415
+ array ('max-age ' => 600 , 'age ' => 60 ),
416
+ ),
417
+ );
418
+
419
+ yield 'retains lowest age of all responses ' => array (
420
+ array ('max-age ' => '160 ' , 'age ' => 60 ),
421
+ array ('max-age ' => 600 , 'age ' => 60 ),
422
+ array (
423
+ array ('max-age ' => 120 , 'age ' => 20 ),
424
+ ),
425
+ );
426
+
427
+ yield 'max-age can be less than age, essentially expiring the response ' => array (
428
+ array ('age ' => 120 , 'max-age ' => '90 ' ),
429
+ array ('max-age ' => 90 , 'age ' => 120 ),
430
+ array (
431
+ array ('max-age ' => 120 , 'age ' => 60 ),
432
+ ),
433
+ );
434
+
435
+ yield 'max-age is 0 regardless of age ' => array (
436
+ array ('max-age ' => '0 ' ),
437
+ array ('max-age ' => 60 ),
438
+ array (
439
+ array ('max-age ' => 0 , 'age ' => 60 ),
440
+ ),
441
+ );
442
+
443
+ yield 'max-age is not negative ' => array (
444
+ array ('max-age ' => '0 ' ),
445
+ array ('max-age ' => 0 ),
446
+ array (
447
+ array ('max-age ' => 0 , 'age ' => 60 ),
448
+ ),
449
+ );
450
+
451
+ yield 'calculates lowest Expires header ' => array (
452
+ array ('expires ' => 60 ),
453
+ array ('expires ' => 60 ),
454
+ array (
455
+ array ('expires ' => 120 ),
456
+ ),
457
+ );
458
+
459
+ yield 'calculates Expires header relative to age ' => array (
460
+ array ('expires ' => 210 , 'age ' => 120 ),
461
+ array ('expires ' => 90 ),
462
+ array (
463
+ array ('expires ' => 600 , 'age ' => '120 ' ),
464
+ ),
465
+ );
379
466
}
380
467
}
0 commit comments