Reverted Hierarchy::extraDBFields() because it interfered with normal generation of the site hierarchy. Note that children(), stageChildren(), and liveChildren() cannot be simply labelled as relations because they are methods with a different semantic meaning. I recommend the use of something similar to to enable access to information beyond relations via the data formatters

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60442 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-08-11 23:51:45 +00:00
parent 62d90957eb
commit 8bf5c3781e
2 changed files with 24 additions and 13 deletions

View File

@ -17,16 +17,6 @@ class Hierarchy extends DataObjectDecorator {
function augmentWrite(&$manipulation) {
}
function extraDbFields() {
return array(
'has_many' => array(
'Children' => 'SiteTree',
'StageChildren' => 'SiteTree',
'LiveChildren' => 'SiteTree',
)
);
}
/**
* Returns the children of this DataObject as an XHTML UL. This will be called recursively on each child,

View File

@ -80,9 +80,30 @@ class SiteTreeTest extends SapphireTest {
$this->assertEquals("V1", $checkSiteTree->Title);
}
/**
* Test that saving changes creates a new version with the correct data in it.
*/
function testChidrenOfRootAreTopLevelPages() {
$pages = DataObject::get("SiteTree");
foreach($pages as $page) $page->publish('Stage', 'Live');
unset($pages);
/* If we create a new SiteTree object with ID = 0 */
$obj = new SiteTree();
/* Then its children should be the top-level pages */
$stageChildren = $obj->stageChildren()->toDropDownMap('ID','Title');
$liveChildren = $obj->liveChildren()->toDropDownMap('ID','Title');
$allChildren = $obj->AllChildrenIncludingDeleted()->toDropDownMap('ID','Title');
$this->assertContains('Home', $stageChildren);
$this->assertContains('Products', $stageChildren);
$this->assertNotContains('Staff', $stageChildren);
$this->assertContains('Home', $liveChildren);
$this->assertContains('Products', $liveChildren);
$this->assertNotContains('Staff', $liveChildren);
$this->assertContains('Home', $allChildren);
$this->assertContains('Products', $allChildren);
$this->assertNotContains('Staff', $allChildren);
}
}