mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
3a0f809387
commit
4cc56abecb
@ -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));
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user