Fixing fragile BlogEntryTest

We can control the time in tests using `mock_now`, so this is being used
to guarantee the date is populated correctly.
This commit is contained in:
Daniel Hensby 2014-10-24 14:09:08 +01:00
parent 611865f88f
commit fdf9317b29

View File

@ -11,6 +11,10 @@ class BlogEntryTest extends SapphireTest {
* Tests that the blog entry populate defaults works
*/
public function testPopulateDefaults() {
// We cant test by the second, as that will most likely fail
SS_Datetime::set_mock_now(SS_Datetime::now());
$member = $this->objFromFixture("Member", "blogOwner1");
$member->logIn();
@ -21,13 +25,12 @@ class BlogEntryTest extends SapphireTest {
$entry->URLSegment = "test-post";
$entry->Tags = "tag1,tag2";
// We cant test by the second, as that will most likely fail
$now = date('Y-m-d', strtotime('now'));
$this->assertContains($now, $entry->Date);
$this->assertEquals(SS_Datetime::now()->Rfc2822(), $entry->dbObject('Date')->Rfc2822());
$this->assertEquals($member->getName(), $entry->Author);
$member->logOut();
SS_Datetime::clear_mock_now();
}
/**