mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge branch '3.1' into 3.2
This commit is contained in:
commit
80aca3a511
@ -1634,7 +1634,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
// No need to check for subclasses or instanceof, as allowedChildren() already
|
// No need to check for subclasses or instanceof, as allowedChildren() already
|
||||||
// deconstructs any inheritance trees already.
|
// deconstructs any inheritance trees already.
|
||||||
$allowed = $parent->allowedChildren();
|
$allowed = $parent->allowedChildren();
|
||||||
$subject = ($this instanceof VirtualPage) ? $this->CopyContentFrom() : $this;
|
$subject = ($this instanceof VirtualPage && $this->CopyContentFromID) ? $this->CopyContentFrom() : $this;
|
||||||
if(!in_array($subject->ClassName, $allowed)) {
|
if(!in_array($subject->ClassName, $allowed)) {
|
||||||
|
|
||||||
$result->error(
|
$result->error(
|
||||||
|
@ -7,6 +7,7 @@ class VirtualPageTest extends SapphireTest {
|
|||||||
'VirtualPageTest_ClassA',
|
'VirtualPageTest_ClassA',
|
||||||
'VirtualPageTest_ClassB',
|
'VirtualPageTest_ClassB',
|
||||||
'VirtualPageTest_VirtualPageSub',
|
'VirtualPageTest_VirtualPageSub',
|
||||||
|
'VirtualPageTest_PageWithAllowedChildren'
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $illegalExtensions = array(
|
protected $illegalExtensions = array(
|
||||||
@ -604,6 +605,45 @@ class VirtualPageTest extends SapphireTest {
|
|||||||
$this->assertEquals('SOME CONTENT', $virtual->obj('CastingTest')->forTemplate());
|
$this->assertEquals('SOME CONTENT', $virtual->obj('CastingTest')->forTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testVirtualPageAsAnAllowedChild() {
|
||||||
|
$parentPage = new VirtualPageTest_PageWithAllowedChildren();
|
||||||
|
$parentPage->write();
|
||||||
|
|
||||||
|
$childPage = new VirtualPageTest_ClassA();
|
||||||
|
$childPage->ParentID = $parentPage->ID;
|
||||||
|
$childPage->write();
|
||||||
|
|
||||||
|
// Check we're allowed to create a VirtualPage without linking it to a page yet
|
||||||
|
$childVirtualPage = new VirtualPage();
|
||||||
|
$childVirtualPage->ParentID = $parentPage->ID;
|
||||||
|
try {
|
||||||
|
$childVirtualPage->write();
|
||||||
|
} catch(ValidationException $e) {
|
||||||
|
$this->fail('Failed to write VirtualPage when it is an allowed child');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that we can link a VirtualPage to a page type that's an allowed child
|
||||||
|
$childVirtualPage->CopyContentFromID = $childPage->ID;
|
||||||
|
try {
|
||||||
|
$childVirtualPage->write();
|
||||||
|
} catch(ValidationException $e) {
|
||||||
|
$this->fail('Failed to write VirtualPage when it is linked to an allowed child');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that we CAN'T link a VirtualPage to a page that is NOT an allowed child
|
||||||
|
$disallowedChild = new VirtualPageTest_ClassB();
|
||||||
|
$disallowedChild->write();
|
||||||
|
$childVirtualPage->CopyContentFromID = $disallowedChild->ID;
|
||||||
|
$isDetected = false;
|
||||||
|
try {
|
||||||
|
$childVirtualPage->write();
|
||||||
|
} catch(ValidationException $e) {
|
||||||
|
$this->assertContains('not allowed as child of this parent page', $e->getMessage());
|
||||||
|
$isDetected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$isDetected) $this->fail("Shouldn't be allowed to write a VirtualPage that links to a disallowed child");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VirtualPageTest_ClassA extends Page implements TestOnly {
|
class VirtualPageTest_ClassA extends Page implements TestOnly {
|
||||||
@ -652,3 +692,10 @@ class VirtualPageTest_PageExtension extends DataExtension implements TestOnly {
|
|||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class VirtualPageTest_PageWithAllowedChildren extends Page implements TestOnly {
|
||||||
|
private static $allowed_children = array(
|
||||||
|
'VirtualPageTest_ClassA',
|
||||||
|
'VirtualPage'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user