Skip to content

Instantly share code, notes, and snippets.

@robbieaverill
Created September 13, 2018 15:24
Show Gist options
  • Save robbieaverill/ee9e37eb03361dcd8a1ef5b1744e38de to your computer and use it in GitHub Desktop.
Save robbieaverill/ee9e37eb03361dcd8a1ef5b1744e38de to your computer and use it in GitHub Desktop.
diff --git a/tests/php/VersionedCascadeDeletesTest.php b/tests/php/VersionedCascadeDeletesTest.php
index 1d7bd5e..c3c3756 100644
--- a/tests/php/VersionedCascadeDeletesTest.php
+++ b/tests/php/VersionedCascadeDeletesTest.php
@@ -101,6 +101,44 @@ class VersionedCascadeDeletesTest extends SapphireTest
);
}
+ /**
+ * Test that unpublishing a versioned item with cascade_deletes on an unversioned object doesn't delete the object
+ */
+ public function testUnpublishingWithCascadeDeletesOnUnversionedObject()
+ {
+ /** @var VersionedCascadeDeletesTest\VersionedObjectWithUnversionedRelations $parent1 */
+ $parent1 = $this->objFromFixture(
+ VersionedCascadeDeletesTest\VersionedObjectWithUnversionedRelations::class,
+ 'versioned1'
+ );
+ $parent1->publishRecursive();
+
+ // Ensure the unversioned child is available in the live stage
+ $this->assertListEquals(
+ [
+ ['Title' => 'Unversioned Child 1'],
+ ],
+ Versioned::get_by_stage(VersionedCascadeDeletesTest\UnversionedObject::class, Versioned::LIVE)
+ );
+
+ $parent1->doUnpublish();
+
+ // Ensure that the unversioned child still exists in both stages
+ $this->assertListEquals(
+ [
+ ['Title' => 'Unversioned Child 1'],
+ ],
+ Versioned::get_by_stage(VersionedCascadeDeletesTest\UnversionedObject::class, Versioned::DRAFT)
+ );
+
+ $this->assertListEquals(
+ [
+ ['Title' => 'Unversioned Child 1'],
+ ],
+ Versioned::get_by_stage(VersionedCascadeDeletesTest\UnversionedObject::class, Versioned::LIVE)
+ );
+ }
+
/**
* Test that deleting from draft does not remove from live
*/
diff --git a/tests/php/VersionedCascadeDeletesTest.yml b/tests/php/VersionedCascadeDeletesTest.yml
index fd1d12d..27d1eba 100644
--- a/tests/php/VersionedCascadeDeletesTest.yml
+++ b/tests/php/VersionedCascadeDeletesTest.yml
@@ -37,3 +37,12 @@ SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest\ChildObject:
Children:
- =>SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest\GrandChildObject.grandchild2
- =>SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest\GrandChildObject.grandchild3
+
+SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest\VersionedObjectWithUnversionedRelations:
+ versioned1:
+ Title: 'Versioned Parent 1'
+
+SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest\UnversionedObject:
+ unversioned1:
+ Title: 'Unversioned Child 1'
+ Parent: =>SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest\VersionedObjectWithUnversionedRelations.versioned1
diff --git a/tests/php/VersionedCascadeDeletesTest/ChildObject.php b/tests/php/VersionedCascadeDeletesTest/ChildObject.php
index 4b46889..32db54a 100644
--- a/tests/php/VersionedCascadeDeletesTest/ChildObject.php
+++ b/tests/php/VersionedCascadeDeletesTest/ChildObject.php
@@ -5,11 +5,9 @@ namespace SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ManyManyList;
-use SilverStripe\Versioned\CascadeDeletesExtension;
use SilverStripe\Versioned\Versioned;
/**
- * @mixin CascadeDeletesExtension
* @mixin Versioned
* @method ParentObject Parent()
* @method RelatedObject Related()
diff --git a/tests/php/VersionedCascadeDeletesTest/GrandChildObject.php b/tests/php/VersionedCascadeDeletesTest/GrandChildObject.php
index cb05794..652209f 100644
--- a/tests/php/VersionedCascadeDeletesTest/GrandChildObject.php
+++ b/tests/php/VersionedCascadeDeletesTest/GrandChildObject.php
@@ -4,11 +4,9 @@ namespace SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
-use SilverStripe\Versioned\CascadeDeletesExtension;
use SilverStripe\Versioned\Versioned;
/**
- * @mixin CascadeDeletesExtension
* @mixin Versioned
*/
class GrandChildObject extends DataObject implements TestOnly
diff --git a/tests/php/VersionedCascadeDeletesTest/ParentObject.php b/tests/php/VersionedCascadeDeletesTest/ParentObject.php
index 92ea5cc..7144a0d 100644
--- a/tests/php/VersionedCascadeDeletesTest/ParentObject.php
+++ b/tests/php/VersionedCascadeDeletesTest/ParentObject.php
@@ -4,11 +4,9 @@ namespace SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
-use SilverStripe\Versioned\CascadeDeletesExtension;
use SilverStripe\Versioned\Versioned;
/**
- * @mixin CascadeDeletesExtension
* @mixin Versioned
*/
class ParentObject extends DataObject implements TestOnly
diff --git a/tests/php/VersionedCascadeDeletesTest/RelatedObject.php b/tests/php/VersionedCascadeDeletesTest/RelatedObject.php
index cd994f8..9c872a5 100644
--- a/tests/php/VersionedCascadeDeletesTest/RelatedObject.php
+++ b/tests/php/VersionedCascadeDeletesTest/RelatedObject.php
@@ -4,11 +4,9 @@ namespace SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
-use SilverStripe\Versioned\CascadeDeletesExtension;
use SilverStripe\Versioned\Versioned;
/**
- * @mixin CascadeDeletesExtension
* @mixin Versioned
*/
class RelatedObject extends DataObject implements TestOnly
diff --git a/tests/php/VersionedCascadeDeletesTest/UnversionedObject.php b/tests/php/VersionedCascadeDeletesTest/UnversionedObject.php
new file mode 100644
index 0000000..81f6f6b
--- /dev/null
+++ b/tests/php/VersionedCascadeDeletesTest/UnversionedObject.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest;
+
+use SilverStripe\ORM\DataObject;
+
+class UnversionedObject extends DataObject
+{
+ private static $table_name = 'VersionedCascadeDeletesTest_UnversionedObject';
+
+ private static $db = [
+ 'Title' => 'Varchar',
+ ];
+
+ private static $has_one = [
+ 'Parent' => VersionedObjectWithUnversionedRelations::class,
+ ];
+}
diff --git a/tests/php/VersionedCascadeDeletesTest/ParentObject.php b/tests/php/VersionedCascadeDeletesTest/VersionedObjectWithUnversionedRelations.php
similarity index 53%
copy from tests/php/VersionedCascadeDeletesTest/ParentObject.php
copy to tests/php/VersionedCascadeDeletesTest/VersionedObjectWithUnversionedRelations.php
index 92ea5cc..e5c0a05 100644
--- a/tests/php/VersionedCascadeDeletesTest/ParentObject.php
+++ b/tests/php/VersionedCascadeDeletesTest/VersionedObjectWithUnversionedRelations.php
@@ -2,36 +2,30 @@
namespace SilverStripe\Versioned\Tests\VersionedCascadeDeletesTest;
-use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
-use SilverStripe\Versioned\CascadeDeletesExtension;
use SilverStripe\Versioned\Versioned;
-/**
- * @mixin CascadeDeletesExtension
- * @mixin Versioned
- */
-class ParentObject extends DataObject implements TestOnly
+class VersionedObjectWithUnversionedRelations extends DataObject
{
private static $extensions = [
Versioned::class,
];
- private static $table_name = 'VersionedCascadeDeletesTest_ParentObject';
+ private static $table_name = 'VersionedObjectWithUnversionedRelations';
private static $db = [
'Title' => 'Varchar',
];
- private static $cascade_deletes = [
- 'Children',
+ private static $has_many = [
+ 'UnversionedObjects' => UnversionedObject::class,
];
private static $owns = [
- 'Children',
+ 'UnversionedObjects',
];
- private static $has_many = [
- 'Children' => ChildObject::class,
+ private static $cascade_deletes = [
+ 'UnversionedObjects',
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment