diff options
Diffstat (limited to 'vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test')
-rw-r--r-- | vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test new file mode 100644 index 00000000..4a1ff611 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/for/objects_countable.test | |||
@@ -0,0 +1,47 @@ | |||
1 | --TEST-- | ||
2 | "for" tag iterates over iterable and countable objects | ||
3 | --TEMPLATE-- | ||
4 | {% for item in items %} | ||
5 | * {{ item }} | ||
6 | * {{ loop.index }}/{{ loop.index0 }} | ||
7 | * {{ loop.revindex }}/{{ loop.revindex0 }} | ||
8 | * {{ loop.first }}/{{ loop.last }}/{{ loop.length }} | ||
9 | |||
10 | {% endfor %} | ||
11 | |||
12 | {% for key, value in items %} | ||
13 | * {{ key }}/{{ value }} | ||
14 | {% endfor %} | ||
15 | |||
16 | {% for key in items|keys %} | ||
17 | * {{ key }} | ||
18 | {% endfor %} | ||
19 | --DATA-- | ||
20 | class ItemsIteratorCountable implements Iterator, Countable | ||
21 | { | ||
22 | protected $values = array('foo' => 'bar', 'bar' => 'foo'); | ||
23 | public function current() { return current($this->values); } | ||
24 | public function key() { return key($this->values); } | ||
25 | public function next() { return next($this->values); } | ||
26 | public function rewind() { return reset($this->values); } | ||
27 | public function valid() { return false !== current($this->values); } | ||
28 | public function count() { return count($this->values); } | ||
29 | } | ||
30 | return array('items' => new ItemsIteratorCountable()) | ||
31 | --EXPECT-- | ||
32 | * bar | ||
33 | * 1/0 | ||
34 | * 2/1 | ||
35 | * 1//2 | ||
36 | |||
37 | * foo | ||
38 | * 2/1 | ||
39 | * 1/0 | ||
40 | * /1/2 | ||
41 | |||
42 | |||
43 | * foo/bar | ||
44 | * bar/foo | ||
45 | |||
46 | * foo | ||
47 | * bar | ||