From 68fa9c9bb8e09dc184afcc84ca3772363936a035 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 9 Jan 2012 20:32:34 +0100 Subject: [PATCH] fixed the empty test and the length filter for Twig_Markup instances (closes #589) --- CHANGELOG | 1 + lib/Twig/Markup.php | 7 ++++++- test/Twig/Tests/Fixtures/filters/length.test | 4 +++- test/Twig/Tests/Fixtures/tests/empty.test | 12 ++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2bfcc4c..ca96018 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.6.0-DEV + * fixed the empty test and the length filter for Twig_Markup instances * added a date function to ease date comparison * fixed unary operators precedence diff --git a/lib/Twig/Markup.php b/lib/Twig/Markup.php index c1a1469..8a7a65f 100644 --- a/lib/Twig/Markup.php +++ b/lib/Twig/Markup.php @@ -15,7 +15,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Markup +class Twig_Markup implements Countable { protected $content; @@ -28,4 +28,9 @@ class Twig_Markup { return $this->content; } + + public function count() + { + return strlen($this->content); + } } diff --git a/test/Twig/Tests/Fixtures/filters/length.test b/test/Twig/Tests/Fixtures/filters/length.test index 0196227..56217ff 100644 --- a/test/Twig/Tests/Fixtures/filters/length.test +++ b/test/Twig/Tests/Fixtures/filters/length.test @@ -4,9 +4,11 @@ {{ array|length }} {{ string|length }} {{ number|length }} +{{ markup|length }} --DATA-- -return array('array' => array(1, 4), 'string' => 'foo', 'number' => 1000) +return array('array' => array(1, 4), 'string' => 'foo', 'number' => 1000, 'markup' => new Twig_Markup('test')) --EXPECT-- 2 3 4 +4 diff --git a/test/Twig/Tests/Fixtures/tests/empty.test b/test/Twig/Tests/Fixtures/tests/empty.test index 23d91f6..651eba7 100644 --- a/test/Twig/Tests/Fixtures/tests/empty.test +++ b/test/Twig/Tests/Fixtures/tests/empty.test @@ -9,6 +9,8 @@ {{ string is empty ? 'ok' : 'ko' }} {{ countable_empty is empty ? 'ok' : 'ko' }} {{ countable_not_empty is empty ? 'ok' : 'ko' }} +{{ markup_empty is empty ? 'ok' : 'ko' }} +{{ markup_not_empty is empty ? 'ok' : 'ko' }} --DATA-- class CountableStub implements Countable @@ -25,7 +27,11 @@ class CountableStub implements Countable return count($this->items); } } -return array('foo' => '', 'bar' => null, 'foobar' => false, 'array' => array(), 'zero' => 0, 'string' => '0', 'countable_empty' => new CountableStub(array()), 'countable_not_empty' => new CountableStub(array(1, 2))); +return array( + 'foo' => '', 'bar' => null, 'foobar' => false, 'array' => array(), 'zero' => 0, 'string' => '0', + 'countable_empty' => new CountableStub(array()), 'countable_not_empty' => new CountableStub(array(1, 2)), + 'markup_empty' => new Twig_Markup(''), 'markup_not_empty' => new Twig_Markup('test'), +); --EXPECT-- ok ok @@ -34,4 +40,6 @@ ok ko ko ok -ko \ No newline at end of file +ko +ok +ko -- 1.7.2.5