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

FIX Regression from #8009 #8132

Merged
Merged
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
21 changes: 17 additions & 4 deletions tests/model/DataObjectDuplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public function testDuplicateManyManyClasses() {
$two = DataObject::get_by_id("DataObjectDuplicateTestClass2", $two->ID);
$three = DataObject::get_by_id("DataObjectDuplicateTestClass3", $three->ID);

$this->assertCount(1, $one->twos(),
"Many-to-one relation not copied (has_many)");
$this->assertCount(1, $one->threes(),
"Object has the correct number of relations");
$this->assertCount(1, $three->ones(),
"Object has the correct number of relations");

//test duplication
$oneCopy = $one->duplicate();
$twoCopy = $two->duplicate();
Expand All @@ -100,16 +107,16 @@ public function testDuplicateManyManyClasses() {
$this->assertEquals($text2, $twoCopy->text);
$this->assertEquals($text3, $threeCopy->text);

$this->assertNotEquals($one->twos()->Count(), $oneCopy->twos()->Count(),
$this->assertCount(0, $oneCopy->twos(),
"Many-to-one relation not copied (has_many)");
$this->assertEquals($one->threes()->Count(), $oneCopy->threes()->Count(),
$this->assertCount(2, $oneCopy->threes(),
"Object has the correct number of relations");
$this->assertEquals($three->ones()->Count(), $threeCopy->ones()->Count(),
$this->assertCount(2, $threeCopy->ones(),
"Object has the correct number of relations");

$this->assertEquals($one->ID, $twoCopy->one()->ID,
"Match between relation of copy and the original");
$this->assertEquals(0, $oneCopy->twos()->Count(),
$this->assertCount(0, $oneCopy->twos(),
"Many-to-one relation not copied (has_many)");
$this->assertEquals($three->ID, $oneCopy->threes()->First()->ID,
"Match between relation of copy and the original");
Expand Down Expand Up @@ -142,6 +149,8 @@ class DataObjectDuplicateTestClass1 extends DataObject implements TestOnly {
'TestExtra' => 'Varchar'
)
);

private static $default_sort = '"ID" ASC';
}

class DataObjectDuplicateTestClass2 extends DataObject implements TestOnly {
Expand All @@ -154,6 +163,8 @@ class DataObjectDuplicateTestClass2 extends DataObject implements TestOnly {
'one' => 'DataObjectDuplicateTestClass1'
);

private static $default_sort = '"ID" ASC';

}

class DataObjectDuplicateTestClass3 extends DataObject implements TestOnly {
Expand All @@ -165,6 +176,8 @@ class DataObjectDuplicateTestClass3 extends DataObject implements TestOnly {
private static $belongs_many_many = array(
'ones' => 'DataObjectDuplicateTestClass1'
);

private static $default_sort = '"ID" ASC';
}