MINOR Added test case for Hierarchy::getDescendantIDList() which also tests Hierarchy::loadDescendantIDListInto() (merged from r98369)

MINOR Testing of grand-children items in HierarchyTest::testLoadDescendantIDListIntoArray() and HierarchyTest::testNumChildren() (merged from r98376)
BUGFIX #5044 Hierarchy::loadDescendantIDListInto() now uses Object::getExtensionInstance('Hierarchy') instead of going through call(), as PHP 5.3 has issues converting references to values
BUGFIX Fixed Hierarchy->loadDescendantIdList() to call setOwner() on the extension instance. This was necessary due to underlying Object/Extension changes in 2.4. (merged from r98403)
MINOR Fixed HierarchyTest assertions around including grand children counts (merged from r98403)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@98405 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-02-08 04:19:56 +00:00 committed by Sam Minnee
parent 58dc696497
commit 8698e94ae0
3 changed files with 36 additions and 4 deletions

View File

@ -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;

View File

@ -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));
}
}

View File

@ -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