@@ -44,7 +44,7 @@ public function testAddGlobal()
4444 $ this ->assertEquals ('<title>Twig Test Site</title> ' ."\n" , $ output );
4545 }
4646
47- public function testAddCIFunctionsRunsOnlyOnce ()
47+ public function testAddFunctionsRunsOnlyOnce ()
4848 {
4949 $ obj = new Twig (['paths ' => __DIR__ . '/../templates/ ' ]);
5050
@@ -53,26 +53,55 @@ public function testAddCIFunctionsRunsOnlyOnce()
5353 ];
5454
5555 $ ref_obj = new ReflectionObject ($ obj );
56- $ ref_property = $ ref_obj ->getProperty ('add_ci_functions ' );
56+ $ ref_property = $ ref_obj ->getProperty ('functions_added ' );
5757 $ ref_property ->setAccessible (true );
58- $ add_ci_functions = $ ref_property ->getValue ($ obj );
59- $ this ->assertEquals (false , $ add_ci_functions );
58+ $ functions_added = $ ref_property ->getValue ($ obj );
59+ $ this ->assertEquals (false , $ functions_added );
6060
6161 $ output = $ obj ->render ('welcome ' , $ data );
6262
6363 $ ref_obj = new ReflectionObject ($ obj );
64- $ ref_property = $ ref_obj ->getProperty ('add_ci_functions ' );
64+ $ ref_property = $ ref_obj ->getProperty ('functions_added ' );
6565 $ ref_property ->setAccessible (true );
66- $ add_ci_functions = $ ref_property ->getValue ($ obj );
67- $ this ->assertEquals (true , $ add_ci_functions );
66+ $ functions_added = $ ref_property ->getValue ($ obj );
67+ $ this ->assertEquals (true , $ functions_added );
6868
6969 // Calls render() twice
7070 $ output = $ obj ->render ('welcome ' , $ data );
7171
7272 $ ref_obj = new ReflectionObject ($ obj );
73- $ ref_property = $ ref_obj ->getProperty ('add_ci_functions ' );
73+ $ ref_property = $ ref_obj ->getProperty ('functions_added ' );
7474 $ ref_property ->setAccessible (true );
75- $ add_ci_functions = $ ref_property ->getValue ($ obj );
76- $ this ->assertEquals (true , $ add_ci_functions );
75+ $ functions_added = $ ref_property ->getValue ($ obj );
76+ $ this ->assertEquals (true , $ functions_added );
7777 }
78+
79+ public function testFunctionAsIs ()
80+ {
81+ $ obj = new Twig ([
82+ 'paths ' => __DIR__ . '/../templates/ ' ,
83+ 'functions_asis ' => ['md5 ' ],
84+ 'cache ' => false ,
85+ ]);
86+
87+ $ output = $ obj ->render ('functions_asis ' );
88+ $ this ->assertEquals ('900150983cd24fb0d6963f7d28e17f72 ' ."\n" , $ output );
89+ }
90+
91+ public function testFunctionSafe ()
92+ {
93+ $ obj = new Twig ([
94+ 'paths ' => __DIR__ . '/../templates/ ' ,
95+ 'functions_safe ' => ['test_safe ' ],
96+ 'cache ' => false ,
97+ ]);
98+
99+ $ output = $ obj ->render ('functions_safe ' );
100+ $ this ->assertEquals ('<s>test</s> ' ."\n" , $ output );
101+ }
102+ }
103+
104+ function test_safe ()
105+ {
106+ return '<s>test</s> ' ;
78107}
0 commit comments