From 1a52a51195c212b2a2400c60c01058df66a4a55c Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 30 Apr 2013 18:45:22 +0200 Subject: [PATCH] DataObject->duplicate() test Advanced relationship copying is already tested further down, but doesn't cover the same basics. Triggered by a CMS bug which turned out to be unrelated (https://github.com/silverstripe/silverstripe-cms/issues/689) --- tests/model/DataObjectDuplicationTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/model/DataObjectDuplicationTest.php b/tests/model/DataObjectDuplicationTest.php index 953eaa0b4..5d61b7a85 100644 --- a/tests/model/DataObjectDuplicationTest.php +++ b/tests/model/DataObjectDuplicationTest.php @@ -8,6 +8,26 @@ class DataObjectDuplicationTest extends SapphireTest { 'DataObjectDuplicateTestClass3' ); + public function testDuplicate() { + $orig = new DataObjectDuplicateTestClass1(); + $orig->text = 'foo'; + $orig->write(); + + $duplicate = $orig->duplicate(); + $this->assertInstanceOf('DataObjectDuplicateTestClass1', $duplicate, + 'Creates the correct type' + ); + $this->assertNotEquals($duplicate->ID, $orig->ID, + 'Creates a unique record' + ); + $this->assertEquals('foo', $duplicate->text, + 'Copies fields' + ); + $this->assertEquals(2, DataObjectDuplicateTestClass1::get()->Count(), + 'Only creates a single duplicate' + ); + } + public function testDuplicateManyManyClasses() { //create new test classes below $one = new DataObjectDuplicateTestClass1();