@@ -235,6 +235,80 @@ public function testRelativeIncludeFailOtherDir()
235235 $ this ->fail ('Exception for unknown relative filepath has not been raised. ' );
236236 }
237237
238+ /**
239+ *
240+ * @run InSeparateProcess
241+ * @preserveGlobalState disabled
242+ *
243+ */
244+ public function testRelativeFetch ()
245+ {
246+ $ this ->smarty ->setTemplateDir (array (
247+ dirname (__FILE__ ) . '/does-not-exist/ ' ,
248+ dirname (__FILE__ ) . '/templates/sub/ ' ,
249+ ));
250+ $ this ->smarty ->security_policy = null ;
251+ $ this ->assertEquals ('hello world ' , $ this ->smarty ->fetch ('./relative.tpl ' ));
252+ }
253+
254+ /**
255+ *
256+ * @run InSeparateProcess
257+ * @preserveGlobalState disabled
258+ *
259+ */
260+ public function testRelativeFetch2 ()
261+ {
262+ $ this ->smarty ->setTemplateDir (array (
263+ dirname (__FILE__ ) . '/does-not-exist/ ' ,
264+ dirname (__FILE__ ) . '/templates/sub/ ' ,
265+ ));
266+ $ this ->smarty ->security_policy = null ;
267+ $ this ->assertEquals ('hello world ' , $ this ->smarty ->fetch ('../helloworld.tpl ' ));
268+ }
269+
270+ /**
271+ *
272+ * @run InSeparateProcess
273+ * @preserveGlobalState disabled
274+ *
275+ */
276+ public function testRelativeFetchCwd ()
277+ {
278+ $ cwd = getcwd ();
279+ chdir (dirname (__FILE__ ) . '/templates/sub/ ' );
280+ $ dn = dirname (__FILE__ );
281+ $ this ->smarty ->setCompileDir ($ dn . '/templates_c/ ' );
282+ $ this ->smarty ->setCacheDir ($ dn . '/cache/ ' );
283+ $ this ->smarty ->setTemplateDir (array (
284+ dirname (__FILE__ ) . '/does-not-exist/ ' ,
285+ ));
286+ $ this ->smarty ->security_policy = null ;
287+ $ this ->assertEquals ('hello world ' , $ this ->smarty ->fetch ('./relative.tpl ' ));
288+ chdir ($ cwd );
289+ }
290+
291+ /**
292+ *
293+ * @run InSeparateProcess
294+ * @preserveGlobalState disabled
295+ *
296+ */
297+ public function testRelativeFetchCwd2 ()
298+ {
299+ $ cwd = getcwd ();
300+ chdir (dirname (__FILE__ ) . '/templates/sub/ ' );
301+ $ dn = dirname (__FILE__ );
302+ $ this ->smarty ->setCompileDir ($ dn . '/templates_c/ ' );
303+ $ this ->smarty ->setCacheDir ($ dn . '/cache/ ' );
304+ $ this ->smarty ->setTemplateDir (array (
305+ dirname (__FILE__ ) . '/does-not-exist/ ' ,
306+ ));
307+ $ this ->smarty ->security_policy = null ;
308+ $ this ->assertEquals ('hello world ' , $ this ->smarty ->fetch ('../helloworld.tpl ' ));
309+ chdir ($ cwd );
310+ }
311+
238312 protected function _relativeMap ($ map , $ cwd = null )
239313 {
240314 foreach ($ map as $ file => $ result ) {
@@ -274,4 +348,203 @@ protected function _relativeMap($map, $cwd = null)
274348 chdir ($ cwd );
275349 }
276350 }
351+
352+ public function testRelativity ()
353+ {
354+ $ this ->smarty ->security_policy = null ;
355+
356+ $ cwd = getcwd ();
357+ $ dn = dirname (__FILE__ );
358+ $ this ->smarty ->setCompileDir ($ dn . '/templates_c/ ' );
359+ $ this ->smarty ->setCacheDir ($ dn . '/cache/ ' );
360+ $ this ->smarty ->setTemplateDir (array (
361+ $ dn . '/templates/relativity/theory/ ' ,
362+ ));
363+
364+ $ map = array (
365+ 'foo.tpl ' => 'theory ' ,
366+ './foo.tpl ' => 'theory ' ,
367+ '././foo.tpl ' => 'theory ' ,
368+ '../foo.tpl ' => 'relativity ' ,
369+ '.././foo.tpl ' => 'relativity ' ,
370+ './../foo.tpl ' => 'relativity ' ,
371+ 'einstein/foo.tpl ' => 'einstein ' ,
372+ './einstein/foo.tpl ' => 'einstein ' ,
373+ '../theory/einstein/foo.tpl ' => 'einstein ' ,
374+ 'templates/relativity/relativity.tpl ' => 'relativity ' ,
375+ './templates/relativity/relativity.tpl ' => 'relativity ' ,
376+ );
377+
378+ $ this ->_relativeMap ($ map );
379+
380+ $ this ->smarty ->setTemplateDir (array (
381+ 'templates/relativity/theory/ ' ,
382+ ));
383+
384+ $ map = array (
385+ 'foo.tpl ' => 'theory ' ,
386+ './foo.tpl ' => 'theory ' ,
387+ '././foo.tpl ' => 'theory ' ,
388+ '../foo.tpl ' => 'relativity ' ,
389+ '.././foo.tpl ' => 'relativity ' ,
390+ './../foo.tpl ' => 'relativity ' ,
391+ 'einstein/foo.tpl ' => 'einstein ' ,
392+ './einstein/foo.tpl ' => 'einstein ' ,
393+ '../theory/einstein/foo.tpl ' => 'einstein ' ,
394+ 'templates/relativity/relativity.tpl ' => 'relativity ' ,
395+ './templates/relativity/relativity.tpl ' => 'relativity ' ,
396+ );
397+
398+ $ this ->_relativeMap ($ map );
399+ }
400+
401+ public function testRelativityCwd ()
402+ {
403+ $ this ->smarty ->security_policy = null ;
404+
405+ $ cwd = getcwd ();
406+ $ dn = dirname (__FILE__ );
407+
408+ $ this ->smarty ->setCompileDir ($ dn . '/templates_c/ ' );
409+ $ this ->smarty ->setCacheDir ($ dn . '/cache/ ' );
410+ $ this ->smarty ->setTemplateDir (array (
411+ $ dn . '/templates/ ' ,
412+ ));
413+ chdir ($ dn . '/templates/relativity/theory/ ' );
414+
415+ $ map = array (
416+ 'foo.tpl ' => 'theory ' ,
417+ './foo.tpl ' => 'theory ' ,
418+ '././foo.tpl ' => 'theory ' ,
419+ '../foo.tpl ' => 'relativity ' ,
420+ '.././foo.tpl ' => 'relativity ' ,
421+ './../foo.tpl ' => 'relativity ' ,
422+ 'einstein/foo.tpl ' => 'einstein ' ,
423+ './einstein/foo.tpl ' => 'einstein ' ,
424+ '../theory/einstein/foo.tpl ' => 'einstein ' ,
425+ );
426+
427+ $ this ->_relativeMap ($ map , $ cwd );
428+ }
429+
430+ public function testRelativityPrecedence ()
431+ {
432+ $ this ->smarty ->security_policy = null ;
433+
434+ $ cwd = getcwd ();
435+ $ dn = dirname (__FILE__ );
436+
437+ $ this ->smarty ->setCompileDir ($ dn . '/templates_c/ ' );
438+ $ this ->smarty ->setCacheDir ($ dn . '/cache/ ' );
439+ $ this ->smarty ->setTemplateDir (array (
440+ $ dn . '/templates/relativity/theory/einstein/ ' ,
441+ ));
442+
443+ $ map = array (
444+ 'foo.tpl ' => 'einstein ' ,
445+ './foo.tpl ' => 'einstein ' ,
446+ '././foo.tpl ' => 'einstein ' ,
447+ '../foo.tpl ' => 'theory ' ,
448+ '.././foo.tpl ' => 'theory ' ,
449+ './../foo.tpl ' => 'theory ' ,
450+ '../../foo.tpl ' => 'relativity ' ,
451+ );
452+
453+ chdir ($ dn . '/templates/relativity/theory/ ' );
454+ $ this ->_relativeMap ($ map , $ cwd );
455+
456+ $ map = array (
457+ '../theory.tpl ' => 'theory ' ,
458+ './theory.tpl ' => 'theory ' ,
459+ '../../relativity.tpl ' => 'relativity ' ,
460+ '../relativity.tpl ' => 'relativity ' ,
461+ './einstein.tpl ' => 'einstein ' ,
462+ 'einstein/einstein.tpl ' => 'einstein ' ,
463+ './einstein/einstein.tpl ' => 'einstein ' ,
464+ );
465+
466+ chdir ($ dn . '/templates/relativity/theory/ ' );
467+ $ this ->_relativeMap ($ map , $ cwd );
468+ }
469+
470+ public function testRelativityRelRel ()
471+ {
472+ $ this ->smarty ->security_policy = null ;
473+
474+ $ cwd = getcwd ();
475+ $ dn = dirname (__FILE__ );
476+
477+ $ this ->smarty ->setCompileDir ($ dn . '/templates_c/ ' );
478+ $ this ->smarty ->setCacheDir ($ dn . '/cache/ ' );
479+ $ this ->smarty ->setTemplateDir (array (
480+ '../.. ' ,
481+ ));
482+
483+ $ map = array (
484+ 'foo.tpl ' => 'relativity ' ,
485+ './foo.tpl ' => 'relativity ' ,
486+ '././foo.tpl ' => 'relativity ' ,
487+ );
488+
489+ chdir ($ dn . '/templates/relativity/theory/einstein ' );
490+ $ this ->_relativeMap ($ map , $ cwd );
491+
492+ $ map = array (
493+ 'relativity.tpl ' => 'relativity ' ,
494+ './relativity.tpl ' => 'relativity ' ,
495+ 'theory/theory.tpl ' => 'theory ' ,
496+ './theory/theory.tpl ' => 'theory ' ,
497+ );
498+
499+ chdir ($ dn . '/templates/relativity/theory/einstein/ ' );
500+ $ this ->_relativeMap ($ map , $ cwd );
501+
502+ $ map = array (
503+ 'foo.tpl ' => 'theory ' ,
504+ './foo.tpl ' => 'theory ' ,
505+ 'theory.tpl ' => 'theory ' ,
506+ './theory.tpl ' => 'theory ' ,
507+ 'einstein/einstein.tpl ' => 'einstein ' ,
508+ './einstein/einstein.tpl ' => 'einstein ' ,
509+ '../theory/einstein/einstein.tpl ' => 'einstein ' ,
510+ '../relativity.tpl ' => 'relativity ' ,
511+ './../relativity.tpl ' => 'relativity ' ,
512+ '.././relativity.tpl ' => 'relativity ' ,
513+ );
514+
515+ $ this ->smarty ->setTemplateDir (array (
516+ '.. ' ,
517+ ));
518+ chdir ($ dn . '/templates/relativity/theory/einstein/ ' );
519+ $ this ->_relativeMap ($ map , $ cwd );
520+ }
521+
522+ public function testRelativityRelRel1 ()
523+ {
524+ $ this ->smarty ->security_policy = null ;
525+
526+ $ cwd = getcwd ();
527+ $ dn = dirname (__FILE__ );
528+ $ this ->smarty ->setCompileDir ($ dn . '/templates_c/ ' );
529+ $ this ->smarty ->setCacheDir ($ dn . '/cache/ ' );
530+ $ this ->smarty ->setTemplateDir (array (
531+ '.. ' ,
532+ ));
533+
534+ $ map = array (
535+ 'foo.tpl ' => 'theory ' ,
536+ './foo.tpl ' => 'theory ' ,
537+ 'theory.tpl ' => 'theory ' ,
538+ './theory.tpl ' => 'theory ' ,
539+ 'einstein/einstein.tpl ' => 'einstein ' ,
540+ './einstein/einstein.tpl ' => 'einstein ' ,
541+ '../theory/einstein/einstein.tpl ' => 'einstein ' ,
542+ '../relativity.tpl ' => 'relativity ' ,
543+ './../relativity.tpl ' => 'relativity ' ,
544+ '.././relativity.tpl ' => 'relativity ' ,
545+ );
546+
547+ chdir ($ dn . '/templates/relativity/theory/einstein/ ' );
548+ $ this ->_relativeMap ($ map , $ cwd );
549+ }
277550}
0 commit comments