Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…6413)
  • Loading branch information...
commit 662c5259e5fe62a426c6601e0c37f5d73fe8a5ec 1 parent 23e342c
@chillu chillu authored
Showing with 27 additions and 1 deletion.
  1. +1 −1  security/Group.php
  2. +26 −0 tests/security/GroupTest.php
View
2  security/Group.php
@@ -278,7 +278,7 @@ public function collateFamilyIDs() {
*/
public function collateAncestorIDs() {
$parent = $this;
- while(isset($parent)) {
+ while(isset($parent) && $parent instanceof Group) {
$items[] = $parent->ID;
$parent = $parent->Parent;
}
View
26 tests/security/GroupTest.php
@@ -84,6 +84,32 @@ function testDelete() {
$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 {
Please sign in to comment.
Something went wrong with that request. Please try again.