TEST Prove LastEdited is updated when no changes are made

This commit is contained in:
Daniel Hensby 2017-08-16 22:26:47 +01:00
parent 69451790d6
commit 1ae07ac2a3
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E

View File

@ -357,6 +357,23 @@ class DataObjectTest extends SapphireTest {
$this->assertEquals(1, $players->limit(5, 3)->count());
}
public function testWriteNoChangesDoesntUpdateLastEdited() {
// set mock now so we can be certain of LastEdited time for our test
SS_Datetime::set_mock_now('2017-01-01 00:00:00');
$obj = new DataObjectTest_Player();
$obj->FirstName = 'Test';
$obj->Surname = 'Plater';
$obj->Email = 'test.player@example.com';
$obj->write();
$writtenObj = DataObjectTest_Player::get()->byID($obj->ID);
$this->assertEquals('2017-01-01 00:00:00', $writtenObj->LastEdited);
// set mock now so we get a new LastEdited if, for some reason, it's updated
SS_Datetime::set_mock_now('2017-02-01 00:00:00');
$writtenObj->write();
$this->assertEquals('2017-01-01 00:00:00', $writtenObj->LastEdited);
}
/**
* Test writing of database columns which don't correlate to a DBField,
* e.g. all relation fields on has_one/has_many like "ParentID".