diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index 567fa37..846fb2a 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -686,6 +686,17 @@ class BlogPost extends Page 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} */ diff --git a/tests/BlogPostTest.php b/tests/BlogPostTest.php index 37e66d5..c527604 100644 --- a/tests/BlogPostTest.php +++ b/tests/BlogPostTest.php @@ -94,4 +94,17 @@ class BlogPostTest extends SapphireTest $visitor = $this->objFromFixture('Member', '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()); + } }