Permalink
Browse files

MINOR added enforce_strict_hierarchy option, and tests around not cas…

…cading deletions (from r98498) (from r99059)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102829 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 9c53032 commit 658e24ea45215c46ba541e2d0b536adfb4734f90 @chillu chillu committed Apr 14, 2010
Showing with 56 additions and 2 deletions.
  1. +19 −1 core/model/SiteTree.php
  2. +37 −1 tests/SiteTreeTest.php
View
@@ -194,6 +194,23 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
public static $cache_permissions = array();
/**
+ * @see SiteTree::enforce_strict_hierarchy()
+ */
+ private static $enforce_strict_hierarchy = true;
+
+ /**
+ * Getter and setter for enforce_strict_hierarchy. With no
+ * args it returns current value. Pass arg to set.
+ *
+ * @return bool
+ */
+ public static function enforce_strict_hierarchy() {
+ $args = func_get_args();
+ if (count($args)) self::$enforce_strict_hierarchy = (bool) $args[0];
+ return self::$enforce_strict_hierarchy;
+ }
+
+ /**
* Returns TRUE if nested URLs (e.g. page/sub-page/) are currently enabled on this site.
*
* @return bool
@@ -1397,7 +1414,8 @@ function onBeforeDelete() {
parent::onBeforeDelete();
// If deleting this page, delete all its children.
- if($children = $this->Children()) {
+ if(SiteTree::enforce_strict_hierarchy() && $children = $this->Children()) {
+ // if($children = $this->Children()) {
foreach($children as $child) {
$child->delete();
}
View
@@ -307,6 +307,20 @@ public function testGetByLink() {
}
function testDeleteFromStageOperatesRecursively() {
+ SiteTree::enforce_strict_hierarchy(false);
+ $pageAbout = $this->objFromFixture('Page', 'about');
+ $pageStaff = $this->objFromFixture('Page', 'staff');
+ $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
+
+ $pageAbout->delete();
+
+ $this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID));
+ $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page);
+ $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page);
+ SiteTree::enforce_strict_hierarchy(true);
+ }
+
+ function testDeleteFromStageOperatesRecursivelyStrict() {
$pageAbout = $this->objFromFixture('Page', 'about');
$pageStaff = $this->objFromFixture('Page', 'staff');
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
@@ -317,8 +331,30 @@ function testDeleteFromStageOperatesRecursively() {
$this->assertFalse(DataObject::get_by_id('Page', $pageStaff->ID));
$this->assertFalse(DataObject::get_by_id('Page', $pageStaffDuplicate->ID));
}
-
+
function testDeleteFromLiveOperatesRecursively() {
+ SiteTree::enforce_strict_hierarchy(false);
+ $this->logInWithPermssion('ADMIN');
+
+ $pageAbout = $this->objFromFixture('Page', 'about');
+ $pageAbout->doPublish();
+ $pageStaff = $this->objFromFixture('Page', 'staff');
+ $pageStaff->doPublish();
+ $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
+ $pageStaffDuplicate->doPublish();
+
+ $parentPage = $this->objFromFixture('Page', 'about');
+ $parentPage->doDeleteFromLive();
+
+ Versioned::reading_stage('Live');
+ $this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID));
+ $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page);
+ $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page);
+ Versioned::reading_stage('Stage');
+ SiteTree::enforce_strict_hierarchy(true);
+ }
+
+ function testDeleteFromLiveOperatesRecursivelyStrict() {
$this->logInWithPermssion('ADMIN');
$pageAbout = $this->objFromFixture('Page', 'about');

0 comments on commit 658e24e

Please sign in to comment.