Permalink
Browse files

test collections using GroupedBy method, ensure correct Count and Pos…

… on grouped items
  • Loading branch information...
1 parent 0fd7fa1 commit ee56f81dbde60802c73f8916cd18742f9c6f035c @maetl committed Mar 3, 2011
Showing with 30 additions and 0 deletions.
  1. +30 −0 tests/DataObjectSetTest.php
@@ -406,6 +406,36 @@ function testSort() {
$set->sort(array('F2'=>'ASC', 'F1'=>'DESC'));
$this->assertEquals($set->Last()->Name, 'Object1', 'Object1 should be last in the set');
}
+
+ /**
+ * Test {@link DataObjectSet->GroupedBy()}
+ */
+ function testGroupedBy() {
+ $set = new DataObjectSet(array(
+ array('Name'=>'AAA'),
+ array('Name'=>'AAA'),
+ array('Name'=>'BBB'),
+ array('Name'=>'BBB'),
+ array('Name'=>'AAA'),
+ array('Name'=>'BBB'),
+ array('Name'=>'CCC'),
+ array('Name'=>'CCC')
+ ));
+ $groupedSet = $set->GroupedBy('Name');
+ $this->assertEquals($groupedSet->Count(), 3);
+
+ $this->assertEquals($groupedSet->First()->Name, 'AAA');
+ $this->assertEquals($groupedSet->First()->Children->Count(), 3);
+ $this->assertEquals($groupedSet->Last()->Name, 'CCC');
+ $this->assertEquals($groupedSet->Last()->Children->Count(), 2);
+
+ $counter = 1;
+ foreach($groupedSet as $group) {
+ $this->assertEquals($group->Pos(), $counter);
+ $this->assertEquals($group->Name, $group->Children->First()->Name);
+ $counter++;
+ }
+ }
}
/**

0 comments on commit ee56f81

Please sign in to comment.