diff --git a/.travis.yml b/.travis.yml index afc5d776..54e9c369 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ env: matrix: include: - php: 5.6 - env: DB=MYSQL RECIPE_VERSION=1.0.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1 + env: DB=MYSQL RECIPE_VERSION=1.1.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1 #- php: 7.0 # env: DB=PGSQL PHPUNIT_TEST=1 - php: 7.0 diff --git a/composer.json b/composer.json index 370d0801..255f05ce 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "silverstripe/cms": "^4.0@dev", + "silverstripe/cms": "^4.1", "symbiote/silverstripe-gridfieldextensions": "^3.1", "silverstripe/vendor-plugin": "^1.0" }, diff --git a/src/Extensions/ElementalDuplicationExtension.php b/src/Extensions/ElementalDuplicationExtension.php index cd164044..47f8b98c 100644 --- a/src/Extensions/ElementalDuplicationExtension.php +++ b/src/Extensions/ElementalDuplicationExtension.php @@ -2,12 +2,16 @@ namespace DNADesign\Elemental\Extensions; +use SilverStripe\Core\Config\Config; use SilverStripe\ORM\DataExtension; -use SilverStripe\Core\Config; +/** + * @deprecated 2.1..3.0 This extension is not implemented by default, and will be removed + * in 3.0.0. Please use the `$owns` API with `$cascade_duplicates` instead. + * See {@link ElementalPageExtension} for an example of this. + */ class ElementalDuplicationExtension extends DataExtension { - /** * Duplicate items * diff --git a/src/Extensions/ElementalPageExtension.php b/src/Extensions/ElementalPageExtension.php index 174d6d45..e33273ef 100644 --- a/src/Extensions/ElementalPageExtension.php +++ b/src/Extensions/ElementalPageExtension.php @@ -8,18 +8,16 @@ class ElementalPageExtension extends ElementalAreasExtension { - /** - * @var array - */ private static $has_one = [ - 'ElementalArea' => ElementalArea::class + 'ElementalArea' => ElementalArea::class, ]; - /** - * @var array - */ private static $owns = [ - 'ElementalArea' + 'ElementalArea', + ]; + + private static $cascade_duplicates = [ + 'ElementalArea', ]; /** diff --git a/src/Models/ElementalArea.php b/src/Models/ElementalArea.php index 3397e56a..f0f03fa1 100644 --- a/src/Models/ElementalArea.php +++ b/src/Models/ElementalArea.php @@ -24,51 +24,34 @@ */ class ElementalArea extends DataObject { - /** - * @var array $db - */ private static $db = [ 'OwnerClassName' => 'Varchar(255)', ]; - /** - * @var array $has_many - */ private static $has_many = [ - 'Elements' => BaseElement::class + 'Elements' => BaseElement::class, ]; - /** - * @var array - */ private static $extensions = [ - Versioned::class + Versioned::class, ]; - /** - * @var array - */ private static $owns = [ - 'Elements' + 'Elements', ]; - /** - * @var array - */ private static $cascade_deletes = [ - 'Elements' + 'Elements', + ]; + + private static $cascade_duplicates = [ + 'Elements', ]; - /** - * @var array - */ private static $summary_fields = [ - 'Title' => 'Title' + 'Title' => 'Title', ]; - /** - * @var string - */ private static $table_name = 'ElementalArea'; /** diff --git a/tests/ElementalAreaTest.php b/tests/ElementalAreaTest.php index 53babaea..d6c0edcc 100644 --- a/tests/ElementalAreaTest.php +++ b/tests/ElementalAreaTest.php @@ -58,4 +58,17 @@ public function testCanBePublished() $element = $this->objFromFixture(TestElement::class, 'element1'); $this->assertTrue($element->canPublish($member)); } + + public function testDuplicate() + { + /** @var ElementalArea $area */ + $area = $this->objFromFixture(ElementalArea::class, 'area1'); + $areaIds = $area->Elements()->column('ID'); + $this->assertCount(2, $areaIds); + + $duplicatedArea = $area->duplicate(true); + $duplicatedAreaIds = $duplicatedArea->Elements()->column('ID'); + $this->assertCount(2, $duplicatedAreaIds); + $this->assertNotEquals($areaIds, $duplicatedAreaIds); + } } diff --git a/tests/ElementalPageExtensionTest.php b/tests/ElementalPageExtensionTest.php index 48924b14..b046bcb0 100644 --- a/tests/ElementalPageExtensionTest.php +++ b/tests/ElementalPageExtensionTest.php @@ -79,4 +79,22 @@ public function testGetElementalTypes() $this->assertEquals('A test element', $types[TestElement::class], 'Types should use their "type"'); } + + public function testDuplicatingPageDuplicatesElements() + { + /** @var TestPage $page */ + $page = $this->objFromFixture(TestPage::class, 'page_with_elements'); + $this->assertCount(2, $page->ElementalArea()->Elements()); + + /** @var TestPage $newPage */ + $newPage = $page->duplicate(); + $this->assertNotEquals($page->ElementalArea->ID, $newPage->ElementalArea->ID, 'Area is duplicated'); + $this->assertCount(2, $newPage->ElementalArea()->Elements()); + + $this->assertNotEquals( + $page->ElementalArea()->Elements()->column('ID'), + $newPage->ElementalArea()->Elements()->column('ID'), + 'Duplicated page has duplicated area and duplicated elements, i.e. not shared' + ); + } } diff --git a/tests/ElementalPageExtensionTest.yml b/tests/ElementalPageExtensionTest.yml index dd2a79c7..ef99e149 100644 --- a/tests/ElementalPageExtensionTest.yml +++ b/tests/ElementalPageExtensionTest.yml @@ -1,11 +1,23 @@ +DNADesign\Elemental\Models\ElementalArea: + area51: + Title: Area 51 + +DNADesign\Elemental\Models\ElementContent: + content1: + Title: Test Content + ParentID: =>DNADesign\Elemental\Models\ElementalArea.area51 + content2: + Title: More content + ParentID: =>DNADesign\Elemental\Models\ElementalArea.area51 + DNADesign\Elemental\Tests\Src\TestPage: elementaldemo: Title: Test Elemental + ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.area51 + page_with_elements: + Title: Page with elements + ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.area51 SilverStripe\CMS\Model\RedirectorPage: elementredirectpage: Title: Redirector Page - -DNADesign\Elemental\Models\ElementContent: - content1: - Title: Test Content