mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
FIX do not show HiddenClass pages in allowed children (#1555)
* FIX do not show HiddenClass pages in allowed children * Resolves #1553 * * Update SiteTreeTest to include HiddenClass checks * Refactor testAllowedChildren to use a data provider
This commit is contained in:
parent
c7b1a4ded8
commit
82e54314bf
@ -2694,7 +2694,10 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
} else {
|
||||
$subclasses = ClassInfo::subclassesFor($candidate);
|
||||
foreach($subclasses as $subclass) {
|
||||
if($subclass != "SiteTree_root") $allowedChildren[] = $subclass;
|
||||
if ($subclass == 'SiteTree_root' || singleton($subclass) instanceof HiddenClass) {
|
||||
continue;
|
||||
}
|
||||
$allowedChildren[] = $subclass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -889,40 +889,70 @@ class SiteTreeTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testAllowedChildren() {
|
||||
/**
|
||||
* Tests that core subclasses of SiteTree are included in allowedChildren() by default, but not instances of
|
||||
* HiddenClass
|
||||
*/
|
||||
public function testAllowedChildrenContainsCoreSubclassesButNotHiddenClass()
|
||||
{
|
||||
$page = new SiteTree();
|
||||
$allowedChildren = $page->allowedChildren();
|
||||
|
||||
$this->assertContains(
|
||||
'VirtualPage',
|
||||
$page->allowedChildren(),
|
||||
$allowedChildren,
|
||||
'Includes core subclasses by default'
|
||||
);
|
||||
|
||||
$classA = new SiteTreeTest_ClassA();
|
||||
$this->assertEquals(
|
||||
$this->assertNotContains(
|
||||
'SiteTreeTest_ClassE',
|
||||
$allowedChildren,
|
||||
'HiddenClass instances should not be returned'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that various types of SiteTree classes will or will not be returned from the allowedChildren method
|
||||
* @dataProvider allowedChildrenProvider
|
||||
* @param string $className
|
||||
* @param array $expected
|
||||
* @param string $assertionMessage
|
||||
*/
|
||||
public function testAllowedChildren($className, $expected, $assertionMessage)
|
||||
{
|
||||
$class = new $className;
|
||||
$this->assertEquals($expected, $class->allowedChildren(), $assertionMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function allowedChildrenProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
// Class name
|
||||
'SiteTreeTest_ClassA',
|
||||
// Expected
|
||||
array('SiteTreeTest_ClassB'),
|
||||
$classA->allowedChildren(),
|
||||
// Assertion message
|
||||
'Direct setting of allowed children'
|
||||
);
|
||||
|
||||
$classB = new SiteTreeTest_ClassB();
|
||||
$this->assertEquals(
|
||||
),
|
||||
array(
|
||||
'SiteTreeTest_ClassB',
|
||||
array('SiteTreeTest_ClassC', 'SiteTreeTest_ClassCext'),
|
||||
$classB->allowedChildren(),
|
||||
'Includes subclasses'
|
||||
);
|
||||
|
||||
$classD = new SiteTreeTest_ClassD();
|
||||
$this->assertEquals(
|
||||
array('SiteTreeTest_ClassC'),
|
||||
$classD->allowedChildren(),
|
||||
'Excludes subclasses if class is prefixed by an asterisk'
|
||||
);
|
||||
|
||||
$classC = new SiteTreeTest_ClassC();
|
||||
$this->assertEquals(
|
||||
),
|
||||
array(
|
||||
'SiteTreeTest_ClassC',
|
||||
array(),
|
||||
$classC->allowedChildren(),
|
||||
'Null setting'
|
||||
),
|
||||
array(
|
||||
'SiteTreeTest_ClassD',
|
||||
array('SiteTreeTest_ClassC'),
|
||||
'Excludes subclasses if class is prefixed by an asterisk'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -1235,6 +1265,10 @@ class SiteTreeTest_ClassD extends Page implements TestOnly {
|
||||
private static $allowed_children = array('*SiteTreeTest_ClassC');
|
||||
}
|
||||
|
||||
class SiteTreeTest_ClassE extends Page implements TestOnly, HiddenClass {
|
||||
|
||||
}
|
||||
|
||||
class SiteTreeTest_ClassCext extends SiteTreeTest_ClassC implements TestOnly {
|
||||
// Override SiteTreeTest_ClassC definitions
|
||||
private static $allowed_children = array('SiteTreeTest_ClassB');
|
||||
|
Loading…
Reference in New Issue
Block a user