Skip to content
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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/php/VersionedRelationsTest.php
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 '
Copy link
Contributor Author

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 😂

. 'not create a new version'
);
}
}
32 changes: 32 additions & 0 deletions tests/php/VersionedRelationsTest/ChildContainerObject.php
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,
];
}
19 changes: 19 additions & 0 deletions tests/php/VersionedRelationsTest/ChildObject.php
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,
];
}
30 changes: 30 additions & 0 deletions tests/php/VersionedRelationsTest/ParentObject.php
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,
];
}