@@ -75,4 +75,66 @@ public function testSharedMaxAgeNotSetIfNotSetInMasterRequest()
75
75
76
76
$ this ->assertFalse ($ response ->headers ->hasCacheControlDirective ('s-maxage ' ));
77
77
}
78
+
79
+ public function testMasterResponseNotCacheableWhenEmbeddedResponseRequiresValidation ()
80
+ {
81
+ $ cacheStrategy = new ResponseCacheStrategy ();
82
+
83
+ $ embeddedResponse = new Response ();
84
+ $ embeddedResponse ->setLastModified (new \DateTime ());
85
+ $ cacheStrategy ->add ($ embeddedResponse );
86
+
87
+ $ masterResponse = new Response ();
88
+ $ masterResponse ->setSharedMaxAge (3600 );
89
+ $ cacheStrategy ->update ($ masterResponse );
90
+
91
+ $ this ->assertTrue ($ masterResponse ->headers ->hasCacheControlDirective ('no-cache ' ));
92
+ $ this ->assertTrue ($ masterResponse ->headers ->hasCacheControlDirective ('must-revalidate ' ));
93
+ $ this ->assertFalse ($ masterResponse ->isFresh ());
94
+ }
95
+
96
+ public function testValidationOnMasterResponseIsNotPossibleWhenItContainsEmbeddedResponses ()
97
+ {
98
+ $ cacheStrategy = new ResponseCacheStrategy ();
99
+
100
+ // This master response uses the "validation" model
101
+ $ masterResponse = new Response ();
102
+ $ masterResponse ->setLastModified (new \DateTime ());
103
+ $ masterResponse ->setEtag ('foo ' );
104
+
105
+ // Embedded response uses "expiry" model
106
+ $ embeddedResponse = new Response ();
107
+ $ masterResponse ->setSharedMaxAge (3600 );
108
+ $ cacheStrategy ->add ($ embeddedResponse );
109
+
110
+ $ cacheStrategy ->update ($ masterResponse );
111
+
112
+ $ this ->assertFalse ($ masterResponse ->isValidateable ());
113
+ $ this ->assertFalse ($ masterResponse ->headers ->has ('Last-Modified ' ));
114
+ $ this ->assertFalse ($ masterResponse ->headers ->has ('ETag ' ));
115
+ $ this ->assertTrue ($ masterResponse ->headers ->hasCacheControlDirective ('no-cache ' ));
116
+ $ this ->assertTrue ($ masterResponse ->headers ->hasCacheControlDirective ('must-revalidate ' ));
117
+ }
118
+
119
+ public function testMasterResponseWithValidationIsUnchangedWhenThereIsNoEmbeddedResponse ()
120
+ {
121
+ $ cacheStrategy = new ResponseCacheStrategy ();
122
+
123
+ $ masterResponse = new Response ();
124
+ $ masterResponse ->setLastModified (new \DateTime ());
125
+ $ cacheStrategy ->update ($ masterResponse );
126
+
127
+ $ this ->assertTrue ($ masterResponse ->isValidateable ());
128
+ }
129
+
130
+ public function testMasterResponseWithExpirationIsUnchangedWhenThereIsNoEmbeddedResponse ()
131
+ {
132
+ $ cacheStrategy = new ResponseCacheStrategy ();
133
+
134
+ $ masterResponse = new Response ();
135
+ $ masterResponse ->setSharedMaxAge (3600 );
136
+ $ cacheStrategy ->update ($ masterResponse );
137
+
138
+ $ this ->assertTrue ($ masterResponse ->isFresh ());
139
+ }
78
140
}
0 commit comments