public function testAllVersions()
 {
     // In 2005 this file was created
     SS_Datetime::set_mock_now('2005-01-01 00:00:00');
     $testPage = new VersionedTest_Subclass();
     $testPage->Title = 'Archived page';
     $testPage->Content = 'This is the content from 2005';
     $testPage->ExtraField = '2005';
     $testPage->write();
     // In 2007 we updated it
     SS_Datetime::set_mock_now('2007-01-01 00:00:00');
     $testPage->Content = "It's 2007 already!";
     $testPage->ExtraField = '2007';
     $testPage->write();
     // Check both versions are returned
     $versions = Versioned::get_all_versions('VersionedTest_Subclass', $testPage->ID);
     $content = array();
     $extraFields = array();
     foreach ($versions as $version) {
         $content[] = $version->Content;
         $extraFields[] = $version->ExtraField;
     }
     $this->assertEquals($versions->Count(), 2, 'All versions returned');
     $this->assertEquals($content, array('This is the content from 2005', "It's 2007 already!"), 'Version fields returned');
     $this->assertEquals($extraFields, array('2005', '2007'), 'Version fields returned');
     // In 2009 we updated it again
     SS_Datetime::set_mock_now('2009-01-01 00:00:00');
     $testPage->Content = "I'm enjoying 2009";
     $testPage->ExtraField = '2009';
     $testPage->write();
     // End mock, back to the present day:)
     SS_Datetime::clear_mock_now();
     $versions = Versioned::get_all_versions('VersionedTest_Subclass', $testPage->ID);
     $content = array();
     $extraFields = array();
     foreach ($versions as $version) {
         $content[] = $version->Content;
         $extraFields[] = $version->ExtraField;
     }
     $this->assertEquals($versions->Count(), 3, 'Additional all versions returned');
     $this->assertEquals($content, array('This is the content from 2005', "It's 2007 already!", "I'm enjoying 2009"), 'Additional version fields returned');
     $this->assertEquals($extraFields, array('2005', '2007', '2009'), 'Additional version fields returned');
 }
 public function testLazyLoadedFieldsOnVersionedRecords()
 {
     // Save another record, sanity check that we're getting the right one
     $obj2 = new VersionedTest_Subclass();
     $obj2->Name = "test2";
     $obj2->ExtraField = "foo2";
     $obj2->write();
     // Save the actual inspected record
     $obj1 = new VersionedTest_Subclass();
     $obj1->Name = "test";
     $obj1->ExtraField = "foo";
     $obj1->write();
     $version1 = $obj1->Version;
     $obj1->Name = "test2";
     $obj1->ExtraField = "baz";
     $obj1->write();
     $version2 = $obj1->Version;
     $reloaded = Versioned::get_version('VersionedTest_Subclass', $obj1->ID, $version1);
     $this->assertEquals($reloaded->Name, 'test');
     $this->assertEquals($reloaded->ExtraField, 'foo');
     $reloaded = Versioned::get_version('VersionedTest_Subclass', $obj1->ID, $version2);
     $this->assertEquals($reloaded->Name, 'test2');
     $this->assertEquals($reloaded->ExtraField, 'baz');
     $reloaded = Versioned::get_latest_version('VersionedTest_Subclass', $obj1->ID);
     $this->assertEquals($reloaded->Version, $version2);
     $this->assertEquals($reloaded->Name, 'test2');
     $this->assertEquals($reloaded->ExtraField, 'baz');
     $allVersions = Versioned::get_all_versions('VersionedTest_Subclass', $obj1->ID);
     $this->assertEquals(2, $allVersions->Count());
     $this->assertEquals($allVersions->First()->Version, $version1);
     $this->assertEquals($allVersions->First()->Name, 'test');
     $this->assertEquals($allVersions->First()->ExtraField, 'foo');
     $this->assertEquals($allVersions->Last()->Version, $version2);
     $this->assertEquals($allVersions->Last()->Name, 'test2');
     $this->assertEquals($allVersions->Last()->ExtraField, 'baz');
     $obj1->delete();
 }