Skip to content

Commit

Permalink
Add tests for grouping by objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dpolac committed May 8, 2016
1 parent f6cd996 commit dac631d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Tests/Fixtures/filters/group_by_object.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
"groupBy" filter can group by object
--TEMPLATE--
{% for category, articles in array|group_by(=> _.category) %}
= {{ category.name }}
{% for article in articles %}
* {{ article.name }}
{% endfor %}
{% endfor %}
--DATA--
$category = [];
foreach (['A', 'B', 'C'] as $name) {
$category[$name] = new \StdClass;
$category[$name]->name = $name;
}

return [ 'array' => [
[ 'name' => 'foo', 'category' => $category['A'] ],
[ 'name' => 'bar', 'category' => $category['B'] ],
[ 'name' => 'tet', 'category' => $category['C'] ],
[ 'name' => 'tet 2', 'category' => $category['C'] ],
[ 'name' => 'buzz', 'category' => $category['A'] ],
] ];
--EXPECT--
= A
* foo
* buzz
= B
* bar
= C
* tet
* tet 2

0 comments on commit dac631d

Please sign in to comment.