From c73e97ece401fb48bbdc61387d0c0c590ed74ff7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 27 Sep 2016 10:14:29 -0700 Subject: [PATCH] added some missing tests for functions/filters as static calls --- test/Twig/Tests/Fixtures/filters/static_calls.test | 10 ++++++++++ test/Twig/Tests/Fixtures/functions/static_calls.test | 10 ++++++++++ test/Twig/Tests/IntegrationTest.php | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 test/Twig/Tests/Fixtures/filters/static_calls.test create mode 100644 test/Twig/Tests/Fixtures/functions/static_calls.test diff --git a/test/Twig/Tests/Fixtures/filters/static_calls.test b/test/Twig/Tests/Fixtures/filters/static_calls.test new file mode 100644 index 000000000..4e17b7726 --- /dev/null +++ b/test/Twig/Tests/Fixtures/filters/static_calls.test @@ -0,0 +1,10 @@ +--TEST-- +Filters as static method calls +--TEMPLATE-- +{{ 'foo'|static_call_string }} +{{ 'foo'|static_call_array }} +--DATA-- +return array('foo' => 'foo') +--EXPECT-- +*foo* +*foo* diff --git a/test/Twig/Tests/Fixtures/functions/static_calls.test b/test/Twig/Tests/Fixtures/functions/static_calls.test new file mode 100644 index 000000000..57e5be392 --- /dev/null +++ b/test/Twig/Tests/Fixtures/functions/static_calls.test @@ -0,0 +1,10 @@ +--TEST-- +Functions as static method calls +--TEMPLATE-- +{{ static_call_string('foo') }} +{{ static_call_array('foo') }} +--DATA-- +return array('foo' => 'foo') +--EXPECT-- +*foo* +*foo* diff --git a/test/Twig/Tests/IntegrationTest.php b/test/Twig/Tests/IntegrationTest.php index 1908bcdf2..7a0275a36 100644 --- a/test/Twig/Tests/IntegrationTest.php +++ b/test/Twig/Tests/IntegrationTest.php @@ -141,6 +141,8 @@ class TwigTestExtension extends Twig_Extension new Twig_SimpleFilter('nl2br', array($this, 'nl2br'), array('pre_escape' => 'html', 'is_safe' => array('html'))), new Twig_SimpleFilter('escape_something', array($this, 'escape_something'), array('is_safe' => array('something'))), new Twig_SimpleFilter('preserves_safety', array($this, 'preserves_safety'), array('preserves_safety' => array('html'))), + new Twig_SimpleFilter('static_call_string', 'TwigTestExtension::staticCall'), + new Twig_SimpleFilter('static_call_array', array('TwigTestExtension', 'staticCall')), new Twig_SimpleFilter('*_path', array($this, 'dynamic_path')), new Twig_SimpleFilter('*_foo_*_bar', array($this, 'dynamic_foo')), ); @@ -152,6 +154,8 @@ class TwigTestExtension extends Twig_Extension new Twig_SimpleFunction('§', array($this, '§Function')), new Twig_SimpleFunction('safe_br', array($this, 'br'), array('is_safe' => array('html'))), new Twig_SimpleFunction('unsafe_br', array($this, 'br')), + new Twig_SimpleFunction('static_call_string', 'TwigTestExtension::staticCall'), + new Twig_SimpleFunction('static_call_array', array('TwigTestExtension', 'staticCall')), new Twig_SimpleFunction('*_path', array($this, 'dynamic_path')), new Twig_SimpleFunction('*_foo_*_bar', array($this, 'dynamic_foo')), ); @@ -212,6 +216,11 @@ class TwigTestExtension extends Twig_Extension return strtoupper($value); } + public static function staticCall($value) + { + return "*$value*"; + } + public function br() { return '
';