FIX: Setting hide_ancestor=true causes a random page type to be hidden

This commit is contained in:
Loz Calver 2015-11-04 10:17:04 +00:00 committed by Loz Calver
parent 6513f8ac49
commit fb43e59b00
2 changed files with 14 additions and 3 deletions

View File

@ -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]);
}
}
}

View File

@ -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() {