From fb43e59b0024ee5dea3b64447d1075ec151ac11c Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Wed, 4 Nov 2015 10:17:04 +0000 Subject: [PATCH] FIX: Setting hide_ancestor=true causes a random page type to be hidden --- code/model/SiteTree.php | 8 +++++--- tests/model/SiteTreeTest.php | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index e79219fb..6d18ee84 100755 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -392,7 +392,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * * @return array */ - static public function page_type_classes() { + public static function page_type_classes() { $classes = ClassInfo::getValidSubClasses(); $baseClassIndex = array_search('SiteTree', $classes); @@ -417,8 +417,10 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $kill_ancestors = array_unique($kill_ancestors); foreach($kill_ancestors as $mark) { // unset from $classes - $idx = array_search($mark, $classes); - unset($classes[$idx]); + $idx = array_search($mark, $classes, true); + if ($idx !== false) { + unset($classes[$idx]); + } } } diff --git a/tests/model/SiteTreeTest.php b/tests/model/SiteTreeTest.php index 88049d5b..cd5ea92b 100644 --- a/tests/model/SiteTreeTest.php +++ b/tests/model/SiteTreeTest.php @@ -871,6 +871,15 @@ class SiteTreeTest extends SapphireTest { $classes = SiteTree::page_type_classes(); $this->assertNotContains('SiteTree', $classes, 'Page types do not include base class'); $this->assertContains('Page', $classes, 'Page types do contain subclasses'); + + // Testing what happens in an incorrect config value is set - hide_ancestor should be a string + Config::inst()->update('SiteTreeTest_ClassA', 'hide_ancestor', true); + $newClasses = SiteTree::page_type_classes(); + $this->assertEquals( + $classes, + $newClasses, + 'Setting hide_ancestor to a boolean (incorrect) value caused a page class to be hidden' + ); } public function testAllowedChildren() {