Merge branch '3'

This commit is contained in:
Daniel Hensby 2016-11-03 15:32:47 +00:00
commit 5bd7662cb4
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
4 changed files with 61 additions and 1 deletions

View File

@ -423,7 +423,7 @@ class CMSPageHistoryController extends CMSMain {
if(!$record) {
return null;
}
$form = $this->getEditForm($id, null, null, true);
$form = $this->getEditForm($id, null, $fromVersion, $toVersion);
$form->setActions(new FieldList());
$form->addExtraClass('compare');

View File

@ -720,9 +720,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($children) {
/** @var SiteTree $child */
$sort = 0;
foreach($children as $child) {
$childClone = $child->duplicateWithChildren();
$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

@ -390,6 +390,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('SilverStripe\\CMS\\Model\\SiteTree', 'enforce_strict_hierarchy', false);
$pageAbout = $this->objFromFixture('Page', 'about');