diff --git a/core/model/Hierarchy.php b/core/model/Hierarchy.php index 35b59cb05..44a5a999b 100644 --- a/core/model/Hierarchy.php +++ b/core/model/Hierarchy.php @@ -354,7 +354,7 @@ class Hierarchy extends DataObjectDecorator { continue; } $idList[] = $child->ID; - $child->loadDescendantIDListInto($idList); + $child->getExtensionInstance('Hierarchy')->loadDescendantIDListInto($idList); } } } @@ -403,7 +403,7 @@ class Hierarchy extends DataObjectDecorator { // Cache the allChildren data, so that future requests will return the references to the same // object. This allows the mark..() system to work appropriately. if(!$this->allChildren) { - $this->allChildren = $this->owner->stageChildren(true); + $this->allChildren = $this->owner ? $this->owner->stageChildren(true) : null; } return $this->allChildren; diff --git a/tests/model/HierarchyTest.php b/tests/model/HierarchyTest.php index 9d8da92b7..bed077d27 100644 --- a/tests/model/HierarchyTest.php +++ b/tests/model/HierarchyTest.php @@ -51,7 +51,27 @@ class HierarchyTest extends SapphireTest { $this->assertEquals(array('Page 2', 'Page 3', 'Page 2a', 'Page 2b'), $marked); $this->assertEquals(array('Page 2', 'Page 2a', 'Page 2b'), $expanded); + } + + function testLoadDescendantIDListInto() { + $page2 = $this->objFromFixture('Page', 'page2'); + $page2a = $this->objFromFixture('Page', 'page2a'); + $page2b = $this->objFromFixture('Page', 'page2b'); + $page2aa = $this->objFromFixture('Page', 'page2aa'); + $page2ab = $this->objFromFixture('Page', 'page2ab'); - } - + $page2IdList = $page2->getDescendantIDList(); + $page2aIdList = $page2a->getDescendantIDList(); + + $this->assertContains($page2a->ID, $page2IdList); + $this->assertContains($page2b->ID, $page2IdList); + $this->assertContains($page2aa->ID, $page2IdList); + $this->assertContains($page2ab->ID, $page2IdList); + $this->assertEquals(4, count($page2IdList)); + + $this->assertContains($page2aa->ID, $page2aIdList); + $this->assertContains($page2ab->ID, $page2aIdList); + $this->assertEquals(2, count($page2aIdList)); + } + } \ No newline at end of file diff --git a/tests/model/HierarchyTest.yml b/tests/model/HierarchyTest.yml index 74d94eb70..3254d8db9 100644 --- a/tests/model/HierarchyTest.yml +++ b/tests/model/HierarchyTest.yml @@ -17,3 +17,15 @@ Page: page3b: Parent: =>Page.page3 Title: Page 3b + page2aa: + Parent: =>Page.page2a + Title: Page 2aa + page2ab: + Parent: =>Page.page2a + Title: Page 2ab + page3aa: + Parent: =>Page.page3a + Title: Page 3aa + page3ab: + Parent: =>Page.page3a + Title: Page 3ab \ No newline at end of file