Merge pull request #671 from creative-commoners/pulls/3/unittest

MNT Unit test for add_default_author config
This commit is contained in:
Michal Kleiner 2022-03-09 22:03:32 +13:00 committed by GitHub
commit 183c659318
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,9 +4,11 @@ namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
class BlogPostTest extends SapphireTest class BlogPostTest extends SapphireTest
@ -184,4 +186,23 @@ class BlogPostTest extends SapphireTest
$this->assertStringContainsString('archive/', $archiveLink); $this->assertStringContainsString('archive/', $archiveLink);
$this->assertStringEndsWith('/2013', $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());
}
} }