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

@ -6,11 +6,15 @@
*/
class BlogEntryTest extends SapphireTest {
static $fixture_file = 'blog/tests/BlogTest.yml';
/**
* 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,43 +25,42 @@ 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();
}
/**
* Tests BBCode functionality
*/
public function testBBCodeContent() {
$tmpFlag = BlogEntry::$allow_wysiwyg_editing;
BlogEntry::$allow_wysiwyg_editing = false;
$tmpFlag = BlogEntry::$allow_wysiwyg_editing;
BlogEntry::$allow_wysiwyg_editing = false;
$entry = $this->objFromFixture('BlogEntry', 'testpost');
$entry->Content = "[url=admin]the CMS[/url]";
$this->assertEquals('<p><a href="admin">the CMS</a></p>', $entry->Content()->value);
BlogEntry::$allow_wysiwyg_editing = $tmpFlag;
BlogEntry::$allow_wysiwyg_editing = $tmpFlag;
}
/**
* Tests BlogEntry::Content method
*/
public function testContent() {
$tmpFlag = BlogEntry::$allow_wysiwyg_editing;
BlogEntry::$allow_wysiwyg_editing = true;
$tmpFlag = BlogEntry::$allow_wysiwyg_editing;
BlogEntry::$allow_wysiwyg_editing = true;
$entry = $this->objFromFixture('BlogEntry', 'testpost');
$entry->Content = '<a href="admin">the CMS</a>';
$this->assertEquals('<a href="admin">the CMS</a>', $entry->Content());
BlogEntry::$allow_wysiwyg_editing = $tmpFlag;
BlogEntry::$allow_wysiwyg_editing = $tmpFlag;
}
/**
* Tests TagCollection parsing of tags
*/
@ -66,7 +69,7 @@ class BlogEntryTest extends SapphireTest {
$entry->Tags = 'damian,Bob, andrew , multiple words, thing,tag,item , Andrew';
$tags = $entry->TagNames();
ksort($tags);
$this->assertEquals(array(
'andrew' => 'Andrew',
'bob' => 'Bob',
@ -77,5 +80,5 @@ class BlogEntryTest extends SapphireTest {
'thing' => 'thing'
), $tags);
}
}