BUGFIX Fixed Group->collateAncestorIDs() handling of orphans (fixes #6413)

This commit is contained in:
Ingo Schommer 2011-02-22 00:19:23 +13:00
parent 23e342ce03
commit 662c5259e5
2 changed files with 27 additions and 1 deletions

View File

@ -278,7 +278,7 @@ class Group extends DataObject {
*/
public function collateAncestorIDs() {
$parent = $this;
while(isset($parent)) {
while(isset($parent) && $parent instanceof Group) {
$items[] = $parent->ID;
$parent = $parent->Parent;
}

View File

@ -84,6 +84,32 @@ class GroupTest extends FunctionalTest {
$this->assertNull(DataObject::get('Group', "\"ID\"={$adminGroup->ID}"), 'Group is removed');
$this->assertNull(DataObject::get('Permission',"\"GroupID\"={$adminGroup->ID}"), 'Permissions removed along with the group');
}
function testCollateAncestorIDs() {
$parentGroup = $this->objFromFixture('Group', 'parentgroup');
$childGroup = $this->objFromFixture('Group', 'childgroup');
$orphanGroup = new Group();
$orphanGroup->ParentID = 99999;
$orphanGroup->write();
$this->assertEquals(
array($parentGroup->ID),
$parentGroup->collateAncestorIDs(),
'Root node only contains itself'
);
$this->assertEquals(
array($childGroup->ID, $parentGroup->ID),
$childGroup->collateAncestorIDs(),
'Contains parent nodes, with child node first'
);
$this->assertEquals(
array($orphanGroup->ID),
$orphanGroup->collateAncestorIDs(),
'Orphaned nodes dont contain invalid parent IDs'
);
}
}
class GroupTest_Member extends Member implements TestOnly {