diff --git a/core/control/ContentController.php b/core/control/ContentController.php index 6e0d9ed0a..6a8e7e103 100755 --- a/core/control/ContentController.php +++ b/core/control/ContentController.php @@ -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)); diff --git a/tests/control/ContentControllerTest.php b/tests/control/ContentControllerTest.php index 071eef3af..d8ae9cfb2 100755 --- a/tests/control/ContentControllerTest.php +++ b/tests/control/ContentControllerTest.php @@ -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 {