fixed the empty test and the length filter for Twig_Markup instances (closes #589)

This commit is contained in:
Fabien Potencier
2012-01-09 20:32:34 +01:00
parent b019019485
commit 68fa9c9bb8
4 changed files with 20 additions and 4 deletions
+1
View File
@@ -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
+6 -1
View File
@@ -15,7 +15,7 @@
* @package twig
* @author Fabien Potencier <fabien@symfony.com>
*/
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);
}
}
+3 -1
View File
@@ -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
+10 -2
View File
@@ -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
ko
ok
ko