empty.test 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. "empty" test
  3. --TEMPLATE--
  4. {{ foo is empty ? 'ok' : 'ko' }}
  5. {{ bar is empty ? 'ok' : 'ko' }}
  6. {{ foobar is empty ? 'ok' : 'ko' }}
  7. {{ array is empty ? 'ok' : 'ko' }}
  8. {{ zero is empty ? 'ok' : 'ko' }}
  9. {{ string is empty ? 'ok' : 'ko' }}
  10. {{ countable_empty is empty ? 'ok' : 'ko' }}
  11. {{ countable_not_empty is empty ? 'ok' : 'ko' }}
  12. {{ markup_empty is empty ? 'ok' : 'ko' }}
  13. {{ markup_not_empty is empty ? 'ok' : 'ko' }}
  14. --DATA--
  15. class CountableStub implements Countable
  16. {
  17. private $items;
  18. public function __construct(array $items)
  19. {
  20. $this->items = $items;
  21. }
  22. public function count()
  23. {
  24. return count($this->items);
  25. }
  26. }
  27. return array(
  28. 'foo' => '', 'bar' => null, 'foobar' => false, 'array' => array(), 'zero' => 0, 'string' => '0',
  29. 'countable_empty' => new CountableStub(array()), 'countable_not_empty' => new CountableStub(array(1, 2)),
  30. 'markup_empty' => new Twig_Markup('', 'UTF-8'), 'markup_not_empty' => new Twig_Markup('test', 'UTF-8'),
  31. );
  32. --EXPECT--
  33. ok
  34. ok
  35. ok
  36. ok
  37. ko
  38. ko
  39. ok
  40. ko
  41. ok
  42. ko