function testDeletingOrphanedVersions()
 {
     $obj = new VersionedTest_Subclass();
     $obj->ExtraField = 'Foo';
     // ensure that child version table gets written
     $obj->write();
     $obj->publish('Stage', 'Live');
     $obj->ExtraField = 'Bar';
     // ensure that child version table gets written
     $obj->write();
     $obj->publish('Stage', 'Live');
     $versions = DB::query("SELECT COUNT(*) FROM \"VersionedTest_Subclass_versions\" WHERE \"RecordID\" = '{$obj->ID}'")->value();
     $this->assertGreaterThan(0, $versions, 'At least 1 version exists in the history of the page');
     // Force orphaning of all versions created earlier, only on parent record.
     // The child versiones table should still have the correct relationship
     DB::query("DELETE FROM \"VersionedTest_DataObject_versions\" WHERE \"RecordID\" = {$obj->ID}");
     // insert a record with no primary key (ID)
     DB::query("INSERT INTO \"VersionedTest_DataObject_versions\" (\"RecordID\") VALUES ({$obj->ID})");
     // run the script which should clean that up
     $obj->augmentDatabase();
     $versions = DB::query("SELECT COUNT(*) FROM \"VersionedTest_Subclass_versions\" WHERE \"RecordID\" = '{$obj->ID}'")->value();
     $this->assertEquals(0, $versions, 'Orphaned versions on child tables are removed');
     // test that it doesn't delete records that we need
     $obj->write();
     $obj->publish('Stage', 'Live');
     $count = DB::query("SELECT COUNT(*) FROM \"VersionedTest_Subclass_versions\" WHERE \"RecordID\" = '{$obj->ID}'")->value();
     $obj->augmentDatabase();
     $count2 = DB::query("SELECT COUNT(*) FROM \"VersionedTest_Subclass_versions\" WHERE \"RecordID\" = '{$obj->ID}'")->value();
     $this->assertEquals($count, $count2);
 }
Example #2
0
 public function testDuplicate()
 {
     $obj1 = new VersionedTest_Subclass();
     $obj1->ExtraField = 'Foo';
     $obj1->write();
     // version 1
     $obj1->publish('Stage', 'Live');
     $obj1->ExtraField = 'Foo2';
     $obj1->write();
     // version 2
     // Make duplicate
     $obj2 = $obj1->duplicate();
     // Check records differ
     $this->assertNotEquals($obj1->ID, $obj2->ID);
     $this->assertEquals(2, $obj1->Version);
     $this->assertEquals(1, $obj2->Version);
 }