diff --git a/tests/php/BlogPostTest.php b/tests/php/BlogPostTest.php index 90e6333d..39e979ed 100644 --- a/tests/php/BlogPostTest.php +++ b/tests/php/BlogPostTest.php @@ -4,9 +4,11 @@ use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Core\Config\Config; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\Security\Member; +use SilverStripe\Security\Security; use SilverStripe\Versioned\Versioned; class BlogPostTest extends SapphireTest @@ -184,4 +186,23 @@ public function testGetYearlyArchiveLink() $this->assertStringContainsString('archive/', $archiveLink); $this->assertStringEndsWith('/2013', $archiveLink); } + + public function testAddDefaultAuthor() + { + $member = Security::getCurrentUser(); + $rootPage = SiteTree::create(); + $rootPage->write(); + + $blogPost = BlogPost::create(['ParentID' => $rootPage->ID]); + $this->assertSame(0, $blogPost->Authors()->count()); + $blogPost->write(); + $this->assertSame(1, $blogPost->Authors()->count()); + $this->assertSame($member->ID, $blogPost->Authors()->first()->ID); + + BlogPost::config()->set('add_default_author', false); + $blogPost2 = BlogPost::create(['ParentID' => $rootPage->ID]); + $this->assertSame(0, $blogPost2->Authors()->count()); + $blogPost2->write(); + $this->assertSame(0, $blogPost2->Authors()->count()); + } }