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)
This commit is contained in:
Ingo Schommer 2013-04-30 18:45:22 +02:00
parent 677122256e
commit 1a52a51195

View File

@ -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();