From 299944fd1fa5f637a65f4bb8a339907a6545169e Mon Sep 17 00:00:00 2001 From: micmania1 Date: Tue, 31 May 2016 14:23:45 +1200 Subject: [PATCH] FIX #394 add getDate to proxy publish date in rss template --- code/model/BlogPost.php | 11 +++++++++++ tests/BlogPostTest.php | 13 +++++++++++++ 2 files changed, 24 insertions(+) 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()); + } }