mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 04:16:28 +00:00
fixed the empty test and the length filter for Twig_Markup instances (closes #589)
This commit is contained in:
@@ -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
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user