@@ -159,4 +159,72 @@ public function it_should_add_the_javascript_if_there_is_a_csrf_token()
159159 $ this ->assertTrue (file_exists ($ this ->dir .'/about_.html ' ));
160160 $ this ->assertEquals ('<html><body>STATAMIC_CSRF_TOKEN<script>js here</script></body></html> ' , file_get_contents ($ this ->dir .'/about_.html ' ));
161161 }
162+
163+ #[Test]
164+ public function excluded_pages_should_have_real_csrf_token ()
165+ {
166+ config (['statamic.static_caching.exclude ' => [
167+ 'urls ' => ['/about ' ],
168+ ]]);
169+
170+ $ this ->withFakeViews ();
171+ $ this ->viewShouldReturnRaw ('layout ' , '<html><body>{{ template_content }}</body></html> ' );
172+ $ this ->viewShouldReturnRaw ('default ' , '{{ csrf_token }} ' );
173+
174+ $ this ->createPage ('about ' );
175+
176+ $ response = $ this
177+ ->get ('/about ' )
178+ ->assertOk ();
179+
180+ // The response should have the real CSRF token, not the placeholder.
181+ $ this ->assertEquals ('<html><body> ' .csrf_token ().'</body></html> ' , $ response ->getContent ());
182+
183+ // The page should not be cached.
184+ $ this ->assertFalse (file_exists ($ this ->dir .'/about_.html ' ));
185+ }
186+
187+ #[Test]
188+ public function excluded_pages_should_have_nocache_regions_replaced ()
189+ {
190+ config (['statamic.static_caching.exclude ' => [
191+ 'urls ' => ['/about ' ],
192+ ]]);
193+
194+ app ()->instance ('example_count ' , 0 );
195+
196+ (new class extends \Statamic \Tags \Tags
197+ {
198+ public static $ handle = 'example_count ' ;
199+
200+ public function index ()
201+ {
202+ $ count = app ('example_count ' );
203+ $ count ++;
204+ app ()->instance ('example_count ' , $ count );
205+
206+ return $ count ;
207+ }
208+ })::register ();
209+
210+ $ this ->withFakeViews ();
211+ $ this ->viewShouldReturnRaw ('layout ' , '<html><body>{{ template_content }}</body></html> ' );
212+ $ this ->viewShouldReturnRaw ('default ' , '{{ example_count }} {{ nocache }}{{ example_count }}{{ /nocache }} ' );
213+
214+ $ this ->createPage ('about ' );
215+
216+ StaticCache::nocacheJs ('js here ' );
217+ StaticCache::nocachePlaceholder ('<svg>Loading...</svg> ' );
218+
219+ $ response = $ this
220+ ->get ('/about ' )
221+ ->assertOk ();
222+
223+ // The response should have the nocache regions replaced with rendered content, no placeholders or JS.
224+ $ this ->assertEquals ('<html><body>1 2</body></html> ' , $ response ->getContent ());
225+ $ this ->assertStringNotContainsString ('<script> ' , $ response ->getContent ());
226+
227+ // The page should not be cached.
228+ $ this ->assertFalse (file_exists ($ this ->dir .'/about_.html ' ));
229+ }
162230}
0 commit comments