MNT Unit test for add_default_author config

This commit is contained in:
Steve Boyd 2022-03-09 15:51:28 +13:00
parent e9507b7377
commit f74c32a61e

View File

@ -4,9 +4,11 @@ namespace SilverStripe\Blog\Tests;
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 @@ class BlogPostTest extends SapphireTest
$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());
}
}