MINOR: Updated ContentController->ChildrenOf() to use new SiteTree functions, and added tests.

From: Andrew Short <andrewjshort@gmail.com>

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88498 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew Short 2009-10-11 00:07:19 +00:00 committed by Sam Minnee
parent 3a0f809387
commit 4cc56abecb
2 changed files with 23 additions and 1 deletions

View File

@ -63,7 +63,7 @@ class ContentController extends Controller {
* @return DataObjectSet
*/
public function ChildrenOf($parentRef) {
$parent = SiteTree::get_by_url($parentRef);
$parent = SiteTree::get_by_link($parentRef);
if(!$parent && is_numeric($parentRef)) {
$parent = DataObject::get_by_id('SiteTree', Convert::raw2sql($parentRef));

View File

@ -42,6 +42,28 @@ class ContentControllerTest extends FunctionalTest {
$this->assertEquals('Third Level Page', $this->get('/third-level/second-index/')->getBody());
}
/**
* Tests {@link ContentController::ChildrenOf()}
*/
public function testChildrenOf() {
$controller = new ContentController();
SiteTree::enable_nested_urls();
$this->assertEquals(1, $controller->ChildrenOf('/')->Count());
$this->assertEquals(1, $controller->ChildrenOf('/home/')->Count());
$this->assertEquals(2, $controller->ChildrenOf('/home/second-level/')->Count());
$this->assertEquals(0, $controller->ChildrenOf('/home/second-level/third-level/')->Count());
SiteTree::disable_nested_urls();
$this->assertEquals(1, $controller->ChildrenOf('/')->Count());
$this->assertEquals(1, $controller->ChildrenOf('/home/')->Count());
$this->assertEquals(2, $controller->ChildrenOf('/second-level/')->Count());
$this->assertEquals(0, $controller->ChildrenOf('/third-level/')->Count());
}
}
class ContentControllerTest_Page extends Page {