From 6c173973229acc198cb467ee369bab5af96b7f13 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 24 Aug 2015 15:16:09 +1200 Subject: [PATCH] BUG block adding children from archived pages Fixes #1260 --- code/model/SiteTree.php | 5 +++++ tests/model/SiteTreeTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 3717f0ca..c7e298a8 100755 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -862,6 +862,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * @return bool True if the current user can add children */ public function canAddChildren($member = null) { + // Disable adding children to archived pages + if($this->getIsDeletedFromStage()) { + return false; + } + if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) { $member = Member::currentUserID(); } diff --git a/tests/model/SiteTreeTest.php b/tests/model/SiteTreeTest.php index 2bd4b377..f9cebf89 100644 --- a/tests/model/SiteTreeTest.php +++ b/tests/model/SiteTreeTest.php @@ -1148,6 +1148,30 @@ class SiteTreeTest extends SapphireTest { } + /** + * Test archived page behaviour + */ + public function testArchivedPages() { + $this->logInWithPermission('ADMIN'); + + $page = $this->objFromFixture('Page', 'home'); + $this->assertTrue($page->canAddChildren()); + $this->assertFalse($page->getIsDeletedFromStage()); + $this->assertFalse($page->isPublished()); + + // Publish + $page->doPublish(); + $this->assertTrue($page->canAddChildren()); + $this->assertFalse($page->getIsDeletedFromStage()); + $this->assertTrue($page->isPublished()); + + // Archive + $page->doArchive(); + $this->assertFalse($page->canAddChildren()); + $this->assertTrue($page->getIsDeletedFromStage()); + $this->assertFalse($page->isPublished()); + } + } /**#@+