From 7751a6cee733610b6d8419d3a919f7885b15068d Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 16 Sep 2016 11:44:07 +1200 Subject: [PATCH 1/3] Behat test cases for site tree duplication (#995) --- tests/behat/features/duplicate-a-page.feature | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/behat/features/duplicate-a-page.feature diff --git a/tests/behat/features/duplicate-a-page.feature b/tests/behat/features/duplicate-a-page.feature new file mode 100644 index 00000000..96a3a5dc --- /dev/null +++ b/tests/behat/features/duplicate-a-page.feature @@ -0,0 +1,24 @@ +Feature: Duplicate a page + As an author + I want to duplicate a page in the CMS + So that I can grow my website + + Background: + Given I am logged in with "ADMIN" permissions + Given a "page" "Page1" + And the "page" "Page1a" is a child of the "page" "Page1" + And the "page" "Page1b" is a child of the "page" "Page1" + And the "page" "Page1b1" is a child of the "page" "Page1b" + + @javascript + Scenario: I can duplicate a page in the pages section + When I go to "/admin/pages" + And I right click on "Page1" in the tree + And I hover on "Duplicate" in the context menu + And I click on "This page and subpages" in the context menu + Then I should see a "Duplicated 'Page1' and children successfully" notice + + When I fill in "Title" with "Duplicate Page" + And I press the "Save & publish" button + Then I should see "Page1" in the tree + And I should see "Duplicate Page" in the tree From 98d95cd70708ae1f15a9bf5c5a661cd66f449f2f Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Mon, 3 Oct 2016 18:10:41 +0100 Subject: [PATCH 2/3] FIX Sort order for duplicated child pages is now retained --- code/model/SiteTree.php | 3 +++ tests/model/SiteTreeTest.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 36444e58..aa804961 100755 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -699,11 +699,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $children = $this->AllChildren(); if($children) { + $sort = 0; foreach($children as $child) { $childClone = method_exists($child, 'duplicateWithChildren') ? $child->duplicateWithChildren() : $child->duplicate(); $childClone->ParentID = $clone->ID; + //retain sort order by manually setting sort values + $childClone->Sort = ++$sort; $childClone->write(); } } diff --git a/tests/model/SiteTreeTest.php b/tests/model/SiteTreeTest.php index fd65ecae..93ad7157 100644 --- a/tests/model/SiteTreeTest.php +++ b/tests/model/SiteTreeTest.php @@ -342,6 +342,39 @@ class SiteTreeTest extends SapphireTest { $this->assertStringEndsWith('changed-on-live/my-staff/?stage=Live', $child->getAbsoluteLiveLink()); } + public function testDuplicateChildrenRetainSort() { + $parent = new Page(); + $parent->Title = 'Parent'; + $parent->write(); + + $child1 = new Page(); + $child1->ParentID = $parent->ID; + $child1->Title = 'Child 1'; + $child1->Sort = 2; + $child1->write(); + + $child2 = new Page(); + $child2->ParentID = $parent->ID; + $child2->Title = 'Child 2'; + $child2->Sort = 1; + $child2->write(); + + $duplicateParent = $parent->duplicateWithChildren(); + $duplicateChildren = $duplicateParent->AllChildren()->toArray(); + $this->assertCount(2, $duplicateChildren); + + $duplicateChild2 = array_shift($duplicateChildren); + $duplicateChild1 = array_shift($duplicateChildren); + + + $this->assertEquals('Child 1', $duplicateChild1->Title); + $this->assertEquals('Child 2', $duplicateChild2->Title); + + // assertGreaterThan works by having the LOWER value first + $this->assertGreaterThan($duplicateChild2->Sort, $duplicateChild1->Sort); + + } + public function testDeleteFromStageOperatesRecursively() { Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', false); $pageAbout = $this->objFromFixture('Page', 'about'); From ae83b7b5ef28df5f5b3f752435f3b36b078f619a Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Fri, 7 Oct 2016 16:33:03 +0100 Subject: [PATCH 3/3] FIX History controller now shows right comparison versions --- code/controllers/CMSPageHistoryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/controllers/CMSPageHistoryController.php b/code/controllers/CMSPageHistoryController.php index f079b3b5..fa02580a 100644 --- a/code/controllers/CMSPageHistoryController.php +++ b/code/controllers/CMSPageHistoryController.php @@ -394,7 +394,7 @@ class CMSPageHistoryController extends CMSMain { } if(isset($record)) { - $form = $this->getEditForm($id, null, null, true); + $form = $this->getEditForm($id, null, $fromVersion, $toVersion); $form->setActions(new FieldList()); $form->addExtraClass('compare');