4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 // This function is defined to check that escaping strategies
13 // like html works even if a function with the same name is defined.
19 class Twig_Tests_IntegrationTest
extends Twig_Test_IntegrationTestCase
21 public function getExtensions()
23 $policy = new Twig_Sandbox_SecurityPolicy(array(), array(), array(), array(), array());
26 new Twig_Extension_Debug(),
27 new Twig_Extension_Sandbox($policy, false),
28 new Twig_Extension_StringLoader(),
29 new TwigTestExtension(),
33 public function getFixturesDir()
35 return dirname(__FILE__
).'/Fixtures/';
39 function test_foo($value = 'foo')
44 class TwigTestFoo
implements Iterator
46 const BAR_NAME
= 'bar';
49 public $array = array(1, 2);
51 public function bar($param1 = null, $param2 = null)
53 return 'bar'.($param1 ? '_'.$param1 : '').($param2 ? '-'.$param2 : '');
56 public function getFoo()
61 public function getSelf()
81 public function strToLower($value)
83 return strtolower($value);
86 public function rewind()
91 public function current()
93 return $this->array[$this->position
];
101 public function next()
106 public function valid()
108 return isset($this->array[$this->position
]);
112 class TwigTestTokenParser_§
extends Twig_TokenParser
114 public function parse(Twig_Token
$token)
116 $this->parser
->getStream()->expect(Twig_Token
::BLOCK_END_TYPE
);
118 return new Twig_Node_Print(new Twig_Node_Expression_Constant('§', -1), -1);
121 public function getTag()
127 class TwigTestExtension
extends Twig_Extension
129 public function getTokenParsers()
132 new TwigTestTokenParser_§
(),
136 public function getFilters()
139 '§' => new Twig_Filter_Method($this, '§Filter'),
140 'escape_and_nl2br' => new Twig_Filter_Method($this, 'escape_and_nl2br', array('needs_environment' => true, 'is_safe' => array('html'))),
141 'nl2br' => new Twig_Filter_Method($this, 'nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))),
142 'escape_something' => new Twig_Filter_Method($this, 'escape_something', array('is_safe' => array('something'))),
143 'preserves_safety' => new Twig_Filter_Method($this, 'preserves_safety', array('preserves_safety' => array('html'))),
144 '*_path' => new Twig_Filter_Method($this, 'dynamic_path'),
145 '*_foo_*_bar' => new Twig_Filter_Method($this, 'dynamic_foo'),
149 public function getFunctions()
152 '§' => new Twig_Function_Method($this, '§Function'),
153 'safe_br' => new Twig_Function_Method($this, 'br', array('is_safe' => array('html'))),
154 'unsafe_br' => new Twig_Function_Method($this, 'br'),
155 '*_path' => new Twig_Function_Method($this, 'dynamic_path'),
156 '*_foo_*_bar' => new Twig_Function_Method($this, 'dynamic_foo'),
160 public function §
Filter($value)
165 public function §
Function($value)
171 * nl2br which also escapes, for testing escaper filters
173 public function escape_and_nl2br($env, $value, $sep = '<br />')
175 return $this->nl2br(twig_escape_filter($env, $value, 'html'), $sep);
179 * nl2br only, for testing filters with pre_escape
181 public function nl2br($value, $sep = '<br />')
183 // not secure if $value contains html tags (not only entities)
185 return str_replace("\n", "$sep\n", $value);
188 public function dynamic_path($element, $item)
190 return $element.'/'.$item;
193 public function dynamic_foo($foo, $bar, $item)
195 return $foo.'/'.$bar.'/'.$item;
198 public function escape_something($value)
200 return strtoupper($value);
203 public function preserves_safety($value)
205 return strtoupper($value);
213 public function getName()
215 return 'integration_test';