Skip to content

Commit

Permalink
Merge pull request #671 from creative-commoners/pulls/3/unittest
Browse files Browse the repository at this point in the history
MNT Unit test for add_default_author config
  • Loading branch information
michalkleiner authored Mar 9, 2022
2 parents e9507b7 + f74c32a commit 183c659
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/php/BlogPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 183c659

Please sign in to comment.