Permalink
Browse files

BUGFIX: Fixed operation of the onlyDeletedFromStage parameter of Hier…

…archy::liveChildren().
  • Loading branch information...
1 parent 5a3242c commit d1a39b0b1a0aefeedc9f207e071e8bde1cb418eb @sminnee sminnee committed Feb 8, 2012
Showing with 33 additions and 2 deletions.
  1. +2 −2 model/Hierarchy.php
  2. +31 −0 tests/model/HierarchyTest.php
View
@@ -562,9 +562,9 @@ public function liveChildren($showAll = false, $onlyDeletedFromStage = false) {
$children->dataQuery()->setQueryParam('Versioned.stage', 'Live');
if($onlyDeletedFromStage) {
- // Note that this makes a second query, and could be optimised to be a joi;
+ // Note that this makes a second query, and could be optimised to be a join
$stageChildren = DataObject::get($baseClass)
- ->where("\"{$baseClass}\".\"ParentID\" = $id AND \"{$baseClass}\".\"ID\" != $id");
+ ->where("\"{$baseClass}\".\"ID\" != $id");
$stageChildren->dataQuery()->setQueryParam('Versioned.mode', 'stage');
$stageChildren->dataQuery()->setQueryParam('Versioned.stage', '');
@@ -119,6 +119,37 @@ function testLoadDescendantIDListIntoArray() {
$this->assertEquals(2, count($obj2aIdList));
}
+ /**
+ * The "only deleted from stage" argument to liveChildren() should exclude
+ * any page that has been moved to another location on the stage site
+ */
+ function testLiveChildrenOnlyDeletedFromStage() {
+ $obj1 = $this->objFromFixture('HierarchyTest_Object', 'obj1');
+ $obj2 = $this->objFromFixture('HierarchyTest_Object', 'obj2');
+ $obj2a = $this->objFromFixture('HierarchyTest_Object', 'obj2a');
+ $obj2b = $this->objFromFixture('HierarchyTest_Object', 'obj2b');
+
+ // Get a published set of objects for our fixture
+ $obj1->publish("Stage", "Live");
+ $obj2->publish("Stage", "Live");
+ $obj2a->publish("Stage", "Live");
+ $obj2b->publish("Stage", "Live");
+
+ // Then delete 2a from stage and move 2b to a sub-node of 1.
+ $obj2a->delete();
+ $obj2b->ParentID = $obj1->ID;
+ $obj2b->write();
+
+ // Get live children, excluding pages that have been moved on the stage site
+ $children = $obj2->liveChildren(true, true)->column("Title");
+
+ // 2a has been deleted from stage and should be shown
+ $this->assertContains("Obj 2a", $children);
+
+ // 2b has merely been moved to a different parent and so shouldn't be shown
+ $this->assertNotContains("Obj 2b", $children);
+ }
+
}
class HierarchyTest_Object extends DataObject implements TestOnly {

0 comments on commit d1a39b0

Please sign in to comment.