-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding tests for versioning updates through relation changes that should pass (but don't) #196
Closed
ScopeyNZ
wants to merge
2
commits into
silverstripe:1.3
from
creative-commoners:pulls/1.3/relation-changes-tests
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
namespace SilverStripe\Versioned\Tests; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Versioned\Tests\VersionedRelationsTest\ChildContainerObject; | ||
use SilverStripe\Versioned\Tests\VersionedRelationsTest\ChildObject; | ||
use SilverStripe\Versioned\Tests\VersionedRelationsTest\ParentObject; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
/** | ||
* This test suite is intended to test various interactions between versioned object that are related to one another | ||
* usually using the "owns" configuration | ||
*/ | ||
class VersionedRelationsTest extends SapphireTest | ||
{ | ||
protected $usesDatabase = true; | ||
|
||
protected static $extra_dataobjects = [ | ||
ParentObject::class, | ||
ChildContainerObject::class, | ||
ChildObject::class, | ||
]; | ||
|
||
public function testChildDraftVersionPropagateToParent() | ||
{ | ||
$parent = ParentObject::create(); | ||
$parent->Name = 'Parent'; | ||
$parent->write(); | ||
|
||
$this->assertCount( | ||
1, | ||
Versioned::get_all_versions(ParentObject::class, $parent->ID), | ||
'There is not exactly 1 version of the child container' | ||
); | ||
|
||
$parent->ChildContainer->write(); | ||
|
||
$this->assertCount( | ||
2, | ||
Versioned::get_all_versions(ParentObject::class, $parent->ID), | ||
'Writing (creating) an owned relation did not create a new version of the parent object' | ||
); | ||
|
||
$parent->ChildContainer->Text = 'Something'; | ||
$parent->ChildContainer->write(); | ||
|
||
$this->assertCount( | ||
3, | ||
Versioned::get_all_versions(ParentObject::class, $parent->ID), | ||
'Writing (updating) an owned relation did not create a new version of the parent object' | ||
); | ||
|
||
$child = ChildObject::create(); | ||
$child->Name = 'Child'; | ||
|
||
$parent->ChildContainer->Children->add($child); | ||
|
||
$this->assertCount( | ||
4, | ||
Versioned::get_all_versions(ParentObject::class, $parent->ID), | ||
'Adding an relation to an object that owns that relation that is a relation owned by the parent object did ' | ||
. 'not create a new version' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
namespace SilverStripe\Versioned\Tests\VersionedRelationsTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\ORM\HasManyList; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
/** | ||
* @property HasManyList Children | ||
* @property string Text | ||
*/ | ||
class ChildContainerObject extends DataObject implements TestOnly | ||
{ | ||
private static $table_name = 'VersionRelationsTest_ChildContainerObject'; | ||
|
||
private static $db = [ | ||
'Text' => 'Varchar', | ||
]; | ||
|
||
private static $has_many = [ | ||
'Children' => ChildObject::class, | ||
]; | ||
|
||
private static $owns = [ | ||
'Children' | ||
]; | ||
|
||
private static $extensions = [ | ||
Versioned::class, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
namespace SilverStripe\Versioned\Tests\VersionedRelationsTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
class ChildObject extends DataObject implements TestOnly | ||
{ | ||
private static $table_name = 'VersionRelationsTest_ChildObject'; | ||
|
||
private static $db = [ | ||
'Name' => 'Varchar', | ||
]; | ||
|
||
private static $extensions = [ | ||
Versioned::class, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
namespace SilverStripe\Versioned\Tests\VersionedRelationsTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
/** | ||
* @property ChildContainerObject ChildContainer | ||
*/ | ||
class ParentObject extends DataObject implements TestOnly | ||
{ | ||
private static $table_name = 'VersionRelationsTest_ParentObject'; | ||
|
||
private static $db = [ | ||
'Name' => 'Varchar', | ||
]; | ||
|
||
private static $has_one = [ | ||
'ChildContainer' => ChildContainerObject::class, | ||
]; | ||
|
||
private static $owns = [ | ||
'ChildContainer' | ||
]; | ||
|
||
private static $extensions = [ | ||
Versioned::class, | ||
]; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was hard to describe in a message 😂