Merge pull request #403 from micmania1/fix-blog-rss-date

FIX #394 add getDate to proxy publish date in rss template
This commit is contained in:
Daniel Hensby 2016-06-06 12:44:28 +01:00
commit 09bdf60aa4
2 changed files with 24 additions and 0 deletions

View File

@ -686,6 +686,17 @@ class BlogPost extends Page
return $labels; return $labels;
} }
/**
* Proxy method for displaying the publish date in rss feeds.
* @see https://github.com/silverstripe/silverstripe-blog/issues/394
*
* @return string|null
*/
public function getDate()
{
return !empty($this->PublishDate) ? $this->PublishDate : null;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -94,4 +94,17 @@ class BlogPostTest extends SapphireTest
$visitor = $this->objFromFixture('Member', 'Visitor'); $visitor = $this->objFromFixture('Member', 'Visitor');
$this->assertFalse($blogPost->canView($visitor)); $this->assertFalse($blogPost->canView($visitor));
} }
/**
* The purpose of getDate() is to act as a proxy for PublishDate in the default RSS
* template, rather than copying the entire template.
*/
public function testGetDate()
{
$blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate');
$this->assertNull($blogPost->getDate());
$blogPost = $this->objFromFixture('BlogPost', 'PostA');
$this->assertEquals('2012-01-09 15:00:00', $blogPost->getDate());
}
} }