@@ -262,4 +262,66 @@ public function testCacheDirectory()
262
262
self ::assertSame ($ expectedCount , $ success + $ errors , 'Each .pug file in the directory to cache should generate a success or an error. ' );
263
263
self ::assertSame ($ success , $ filesCount , 'Each file successfully cached should be in the cache directory. ' );
264
264
}
265
+
266
+ /**
267
+ * @group i
268
+ */
269
+ public function testCacheOnExtendsChange ()
270
+ {
271
+ $ directory = sys_get_temp_dir ().'/pug ' .mt_rand (0 , 99999999 );
272
+ $ templateDirectory = sys_get_temp_dir ().'/pug ' .mt_rand (0 , 99999999 );
273
+ $ this ->emptyDirectory ($ directory );
274
+ $ this ->emptyDirectory ($ templateDirectory );
275
+ if (!file_exists ($ directory )) {
276
+ mkdir ($ directory );
277
+ }
278
+ if (!file_exists ($ templateDirectory )) {
279
+ mkdir ($ templateDirectory );
280
+ }
281
+ $ renderer = new Pug ([
282
+ 'basedir ' => $ templateDirectory ,
283
+ 'cache_dir ' => $ directory ,
284
+ ]);
285
+ $ base = $ templateDirectory .DIRECTORY_SEPARATOR .'base.pug ' ;
286
+ file_put_contents ($ base , implode ("\n" , [
287
+ 'p in base ' ,
288
+ 'block content ' ,
289
+ ]));
290
+ $ child = $ templateDirectory .DIRECTORY_SEPARATOR .'child.pug ' ;
291
+ file_put_contents ($ child , implode ("\n" , [
292
+ 'extends base ' ,
293
+ 'block content ' ,
294
+ ' p in child ' ,
295
+ ]));
296
+
297
+ $ render = function ($ path ) use ($ renderer ) {
298
+ ob_start ();
299
+ $ renderer ->displayFile ($ path );
300
+ $ contents = ob_get_contents ();
301
+ ob_end_clean ();
302
+
303
+ return $ contents ;
304
+ };
305
+
306
+ self ::assertSame ('<p>in base</p><p>in child</p> ' , $ render ($ child ));
307
+
308
+ file_put_contents ($ base , implode ("\n" , [
309
+ 'p in base updated! ' ,
310
+ 'block content ' ,
311
+ ]));
312
+ touch ($ base , time () - 3600 );
313
+ touch ($ child , time () - 3600 );
314
+ clearstatcache ();
315
+
316
+ $ html = $ render ($ child );
317
+ self ::assertSame ('<p>in base</p><p>in child</p> ' , $ html );
318
+
319
+ touch ($ base , time () + 3600 );
320
+ clearstatcache ();
321
+
322
+ self ::assertSame ('<p>in base updated!</p><p>in child</p> ' , $ render ($ child ));
323
+
324
+ $ this ->emptyDirectory ($ directory );
325
+ $ this ->emptyDirectory ($ templateDirectory );
326
+ }
265
327
}
0 commit comments