set(CommentsExtension::class, 'comments', array( 'enabled' => true, 'enabled_cms' => false, 'require_login' => false, 'require_login_cms' => false, 'required_permission' => false, 'require_moderation_nonmembers' => false, 'require_moderation' => false, 'require_moderation_cms' => false, 'frontend_moderation' => false, 'Member' => false, )); $this->requiredExtensions = array( 'CommentableItem' => CommentsExtension::class ); // Configure this dataobject Config::modify()->set(CommentableItem::class, 'comments', array( 'enabled_cms' => true )); } public function tearDown() { Config::unnest(); parent::tearDown(); } public function testGetCommentsOption() { Config::modify()->set(CommentableItem::class, 'comments', [ 'comments_holder_id' => 'some-option' ]); $item = $this->objFromFixture(CommentableItem::class, 'first'); $this->assertEquals('some-option', $item->getCommentsOption('comments_holder_id')); } public function testPopulateDefaults() { Config::modify()->set(CommentableItem::class, 'comments', array( 'require_moderation_cms' => true, 'require_moderation' => true, 'require_moderation_nonmembers' => true )); $item = $this->objFromFixture(CommentableItem::class, 'first'); $item->populateDefaults(); $this->assertTrue($item->CommentsRequireLogin); Config::modify()->set(CommentableItem::class, 'comments', array( 'require_moderation_cms' => true, 'require_moderation' => true, 'require_moderation_nonmembers' => true )); $item = $this->objFromFixture(CommentableItem::class, 'first'); $item->populateDefaults(); $this->assertFalse($item->CommentsRequireLogin); } public function testUpdateSettingsFields() { $this->markTestSkipped('This needs SiteTree installed'); } public function testGetModerationRequired() { // the 3 options take precedence in this order, executed if true Config::modify()->set(CommentableItem::class, 'comments', array( 'require_moderation_cms' => true, 'require_moderation' => true, 'require_moderation_nonmembers' => true )); // With require moderation CMS set to true, the value of the field // 'ModerationRequired' is returned $item = $this->objFromFixture(CommentableItem::class, 'first'); $item->ModerationRequired = 'None'; $item->write(); $this->assertEquals('None', $item->getModerationRequired()); $item->ModerationRequired = 'Required'; $item->write(); $this->assertEquals('Required', $item->getModerationRequired()); $item->ModerationRequired = 'NonMembersOnly'; $item->write(); $this->assertEquals('NonMembersOnly', $item->getModerationRequired()); Config::modify()->set(CommentableItem::class, 'comments', array( 'require_moderation_cms' => false, 'require_moderation' => true, 'require_moderation_nonmembers' => true )); $this->assertEquals('Required', $item->getModerationRequired()); Config::modify()->set(CommentableItem::class, 'comments', array( 'require_moderation_cms' => false, 'require_moderation' => false, 'require_moderation_nonmembers' => true )); $this->assertEquals('NonMembersOnly', $item->getModerationRequired()); Config::modify()->set(CommentableItem::class, 'comments', array( 'require_moderation_cms' => false, 'require_moderation' => false, 'require_moderation_nonmembers' => false )); $this->assertEquals('None', $item->getModerationRequired()); } public function testGetCommentsRequireLogin() { Config::modify()->set(CommentableItem::class, 'comments', array( 'require_login_cms' => true )); // With require moderation CMS set to true, the value of the field // 'ModerationRequired' is returned $item = $this->objFromFixture(CommentableItem::class, 'first'); $item->CommentsRequireLogin = true; $this->assertTrue($item->getCommentsRequireLogin()); $item->CommentsRequireLogin = false; $this->assertFalse($item->getCommentsRequireLogin()); Config::modify()->set(CommentableItem::class, 'comments', array( 'require_login_cms' => false, 'require_login' => false )); $this->assertFalse($item->getCommentsRequireLogin()); Config::modify()->set(CommentableItem::class, 'comments', array( 'require_login_cms' => false, 'require_login' => true )); $this->assertTrue($item->getCommentsRequireLogin()); } public function testAllComments() { $item = $this->objFromFixture(CommentableItem::class, 'first'); $this->assertEquals(4, $item->AllComments()->count()); } public function testAllVisibleComments() { if (Member::currentUser()) { Member::currentUser()->logOut(); } $item = $this->objFromFixture(CommentableItem::class, 'second'); $this->assertEquals(4, $item->AllVisibleComments()->count()); } public function testComments() { Config::modify()->set(CommentableItem::class, 'comments', array( 'nested_comments' => false )); $item = $this->objFromFixture(CommentableItem::class, 'first'); $this->assertEquals(4, $item->Comments()->count()); Config::modify()->set(CommentableItem::class, 'comments', array( 'nested_comments' => true )); $this->assertEquals(1, $item->Comments()->count()); } public function testGetCommentsEnabled() { Config::modify()->set(CommentableItem::class, 'comments', array( 'enabled_cms' => true )); $item = $this->objFromFixture(CommentableItem::class, 'first'); $this->assertTrue($item->getCommentsEnabled()); $item->ProvideComments = 0; $this->assertFalse($item->getCommentsEnabled()); } public function testGetCommentHolderID() { $item = $this->objFromFixture(CommentableItem::class, 'first'); Config::modify()->set(CommentableItem::class, 'comments', array( 'comments_holder_id' => 'commentid_test1', )); $this->assertEquals('commentid_test1', $item->getCommentHolderID()); Config::modify()->set(CommentableItem::class, 'comments', array( 'comments_holder_id' => 'commtentid_test_another', )); $this->assertEquals('commtentid_test_another', $item->getCommentHolderID()); } public function testGetPostingRequiredPermission() { $this->markTestSkipped('TODO'); } public function testCanModerateComments() { // ensure nobody logged in if (Member::currentUser()) { Member::currentUser()->logOut(); } $item = $this->objFromFixture(CommentableItem::class, 'first'); $this->assertFalse($item->canModerateComments()); $this->logInWithPermission('CMS_ACCESS_CommentAdmin'); $this->assertTrue($item->canModerateComments()); } public function testGetCommentRSSLink() { Config::modify()->set('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local'); $item = $this->objFromFixture(CommentableItem::class, 'first'); $link = $item->getCommentRSSLink(); $this->assertEquals('http://unittesting.local/comments/rss', $link); } public function testGetCommentRSSLinkPage() { Config::modify()->set('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local'); $item = $this->objFromFixture(CommentableItem::class, 'first'); $page = $item->getCommentRSSLinkPage(); $this->assertEquals( 'http://unittesting.local/comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/' . $item->ID, $page ); } public function testCommentsForm() { Config::modify()->set(CommentableItem::class, 'comments', array( 'include_js' => false, 'comments_holder_id' => 'comments-holder', )); $item = $this->objFromFixture(CommentableItem::class, 'first'); // The comments form is HTML to do assertions by contains $cf = $item->CommentsForm(); $expected = '
'; $this->assertContains($expected, $cf); $this->assertContains('

Post your comment

', $cf); // check the comments form exists $expected = 'assertContains($expected, $cf); $expected = 'assertContains($expected, $cf); $expected = 'assertContains($expected, $cf); $expected = 'assertContains($expected, $cf); $expected = '