Skip to content

Commit

Permalink
REMOVED: Unnecessary publish actions from test cases
Browse files Browse the repository at this point in the history
ADDED: Test case for get_all_versions
  • Loading branch information
tractorcow committed Aug 20, 2012
1 parent 0f09305 commit 56fe7f8
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions tests/model/VersionedTest.php
Expand Up @@ -276,21 +276,18 @@ public function testArchiveVersion() {
$testPage->Content = 'This is the content from 2005';
$testPage->ExtraField = '2005';
$testPage->write();
$testPage->publish('Stage', 'Live');

// 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();
$testPage->publish('Stage', 'Live');

// 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();
$testPage->publish('Stage', 'Live');

// End mock, back to the present day:)
SS_Datetime::clear_mock_now();
Expand Down Expand Up @@ -319,6 +316,45 @@ public function testArchiveVersion() {
$this->assertEquals("2009", $testPageCurrent->ExtraField);
$this->assertEquals("I'm enjoying 2009", $testPageCurrent->Content);
}

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

// 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, 'All versions returned');
$this->assertEquals($content, array('This is the content from 2005', "It's 2007 already!", "I'm enjoying 2009"), 'Version fields returned');
$this->assertEquals($extraFields, array('2005', '2007', '2009'), 'Version fields returned');
}
}

class VersionedTest_DataObject extends DataObject implements TestOnly {
Expand Down

0 comments on commit 56fe7f8

Please sign in to comment.