Merge branch '3.4' into 3

This commit is contained in:
Daniel Hensby 2016-10-16 22:43:01 +01:00
commit ad2b2a044e
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
4 changed files with 61 additions and 1 deletions

View File

@ -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');

View File

@ -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();
}
}

View File

@ -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

View File

@ -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');