2016-01-07 07:59:10 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
namespace SilverStripe\Comments\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Comments\Extensions\CommentsExtension;
|
|
|
|
use SilverStripe\Comments\Model\Comment;
|
|
|
|
use SilverStripe\Comments\Tests\CommentTestHelper;
|
|
|
|
use SilverStripe\Comments\Tests\Stubs\CommentableItem;
|
|
|
|
use SilverStripe\Comments\Tests\Stubs\CommentableItemDisabled;
|
|
|
|
use SilverStripe\Comments\Tests\Stubs\CommentableItemEnabled;
|
|
|
|
use SilverStripe\Core\Config\Config;
|
2018-03-09 04:45:38 +01:00
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
2017-01-16 20:57:37 +01:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\View\Requirements;
|
|
|
|
|
2018-03-09 04:45:38 +01:00
|
|
|
class CommentsExtensionTest extends FunctionalTest
|
2016-02-19 01:48:25 +01:00
|
|
|
{
|
2017-09-18 04:16:24 +02:00
|
|
|
protected static $fixture_file = 'CommentsTest.yml';
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2018-03-09 04:45:38 +01:00
|
|
|
protected static $disable_themes = true;
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
protected static $extra_dataobjects = [
|
2017-01-16 20:57:37 +01:00
|
|
|
CommentableItem::class,
|
|
|
|
CommentableItemEnabled::class,
|
2017-10-09 06:26:07 +02:00
|
|
|
CommentableItemDisabled::class,
|
|
|
|
];
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
protected static $required_extensions = [
|
|
|
|
CommentableItem::class => [
|
|
|
|
CommentsExtension::class,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
protected function setUp()
|
2016-02-19 01:48:25 +01:00
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// Set good default values
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentsExtension::class, 'comments', [
|
2016-01-07 07:59:10 +01:00
|
|
|
'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,
|
2017-10-09 06:26:07 +02:00
|
|
|
]);
|
2016-01-07 07:59:10 +01:00
|
|
|
|
|
|
|
// Configure this dataobject
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', [
|
2016-01-07 07:59:10 +01:00
|
|
|
'enabled_cms' => true
|
2017-10-09 06:26:07 +02:00
|
|
|
]);
|
2016-01-07 07:59:10 +01:00
|
|
|
}
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
|
|
|
|
public function testGetCommentsOption()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', [
|
2017-09-18 04:16:24 +02:00
|
|
|
'comments_holder_id' => 'some-option'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
|
|
|
$this->assertEquals('some-option', $item->getCommentsOption('comments_holder_id'));
|
|
|
|
}
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testPopulateDefaults()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
$this->markTestSkipped('TODO');
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testUpdateSettingsFields()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->markTestSkipped('This needs SiteTree installed');
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetModerationRequired()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
|
|
|
|
// the 3 options take precedence in this order, executed if true
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2016-01-07 07:59:10 +01:00
|
|
|
'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
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2016-01-07 07:59:10 +01:00
|
|
|
$item->ModerationRequired = 'None';
|
2017-09-14 01:12:07 +02:00
|
|
|
$item->write();
|
|
|
|
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertEquals('None', $item->getModerationRequired());
|
|
|
|
$item->ModerationRequired = 'Required';
|
2017-09-14 01:12:07 +02:00
|
|
|
$item->write();
|
|
|
|
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertEquals('Required', $item->getModerationRequired());
|
2017-09-14 01:12:07 +02:00
|
|
|
|
2016-01-07 07:59:10 +01:00
|
|
|
$item->ModerationRequired = 'NonMembersOnly';
|
2017-09-14 01:12:07 +02:00
|
|
|
$item->write();
|
|
|
|
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertEquals('NonMembersOnly', $item->getModerationRequired());
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2016-01-07 07:59:10 +01:00
|
|
|
'require_moderation_cms' => false,
|
|
|
|
'require_moderation' => true,
|
|
|
|
'require_moderation_nonmembers' => true
|
|
|
|
));
|
|
|
|
$this->assertEquals('Required', $item->getModerationRequired());
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2016-01-07 07:59:10 +01:00
|
|
|
'require_moderation_cms' => false,
|
|
|
|
'require_moderation' => false,
|
|
|
|
'require_moderation_nonmembers' => true
|
|
|
|
));
|
|
|
|
$this->assertEquals('NonMembersOnly', $item->getModerationRequired());
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2016-01-07 07:59:10 +01:00
|
|
|
'require_moderation_cms' => false,
|
|
|
|
'require_moderation' => false,
|
|
|
|
'require_moderation_nonmembers' => false
|
|
|
|
));
|
|
|
|
$this->assertEquals('None', $item->getModerationRequired());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetCommentsRequireLogin()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2016-01-07 07:59:10 +01:00
|
|
|
'require_login_cms' => true
|
|
|
|
));
|
|
|
|
|
|
|
|
// With require moderation CMS set to true, the value of the field
|
|
|
|
// 'ModerationRequired' is returned
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2016-01-07 07:59:10 +01:00
|
|
|
$item->CommentsRequireLogin = true;
|
|
|
|
$this->assertTrue($item->getCommentsRequireLogin());
|
|
|
|
$item->CommentsRequireLogin = false;
|
|
|
|
$this->assertFalse($item->getCommentsRequireLogin());
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2016-01-07 07:59:10 +01:00
|
|
|
'require_login_cms' => false,
|
|
|
|
'require_login' => false
|
|
|
|
));
|
|
|
|
$this->assertFalse($item->getCommentsRequireLogin());
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2016-01-07 07:59:10 +01:00
|
|
|
'require_login_cms' => false,
|
|
|
|
'require_login' => true
|
|
|
|
));
|
|
|
|
$this->assertTrue($item->getCommentsRequireLogin());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testAllComments()
|
|
|
|
{
|
2017-09-14 01:12:07 +02:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2017-09-18 04:16:24 +02:00
|
|
|
$this->assertEquals(4, $item->AllComments()->count());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testAllVisibleComments()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
$this->logOut();
|
2017-09-14 01:12:07 +02:00
|
|
|
|
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'second');
|
2017-10-09 06:26:07 +02:00
|
|
|
$this->assertEquals(2, $item->AllVisibleComments()->count());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testComments()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2017-09-14 01:12:07 +02:00
|
|
|
'nested_comments' => false
|
|
|
|
));
|
|
|
|
|
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2017-09-18 04:16:24 +02:00
|
|
|
$this->assertEquals(4, $item->Comments()->count());
|
2017-09-14 01:12:07 +02:00
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2017-09-14 01:12:07 +02:00
|
|
|
'nested_comments' => true
|
|
|
|
));
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
$this->assertEquals(1, $item->Comments()->count());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetCommentsEnabled()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2017-09-14 01:12:07 +02:00
|
|
|
'enabled_cms' => true
|
|
|
|
));
|
|
|
|
|
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
|
|
|
$this->assertTrue($item->getCommentsEnabled());
|
|
|
|
|
|
|
|
$item->ProvideComments = 0;
|
|
|
|
$this->assertFalse($item->getCommentsEnabled());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetCommentHolderID()
|
|
|
|
{
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2017-09-18 04:16:24 +02:00
|
|
|
'comments_holder_id' => 'commentid_test1',
|
2016-01-07 07:59:10 +01:00
|
|
|
));
|
|
|
|
$this->assertEquals('commentid_test1', $item->getCommentHolderID());
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2016-01-07 07:59:10 +01:00
|
|
|
'comments_holder_id' => 'commtentid_test_another',
|
|
|
|
));
|
|
|
|
$this->assertEquals('commtentid_test_another', $item->getCommentHolderID());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetPostingRequiredPermission()
|
|
|
|
{
|
|
|
|
$this->markTestSkipped('TODO');
|
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testCanModerateComments()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
// ensure nobody logged in
|
2016-02-19 01:48:25 +01:00
|
|
|
if (Member::currentUser()) {
|
|
|
|
Member::currentUser()->logOut();
|
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertFalse($item->canModerateComments());
|
|
|
|
|
|
|
|
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
|
|
|
$this->assertTrue($item->canModerateComments());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetCommentRSSLink()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local');
|
2017-01-17 05:33:39 +01:00
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2016-02-19 01:48:25 +01:00
|
|
|
$link = $item->getCommentRSSLink();
|
2017-01-17 05:33:39 +01:00
|
|
|
$this->assertEquals('http://unittesting.local/comments/rss', $link);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetCommentRSSLinkPage()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local');
|
2017-01-17 05:33:39 +01:00
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2016-01-07 07:59:10 +01:00
|
|
|
$page = $item->getCommentRSSLinkPage();
|
|
|
|
$this->assertEquals(
|
2017-01-17 05:33:39 +01:00
|
|
|
'http://unittesting.local/comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/' . $item->ID,
|
2016-01-07 07:59:10 +01:00
|
|
|
$page
|
|
|
|
);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testCommentsForm()
|
|
|
|
{
|
2018-03-09 04:45:38 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(CommentableItem::class, 'comments', array(
|
2017-09-14 01:12:07 +02:00
|
|
|
'include_js' => false,
|
|
|
|
'comments_holder_id' => 'comments-holder',
|
|
|
|
));
|
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2016-01-07 07:59:10 +01:00
|
|
|
|
|
|
|
// The comments form is HTML to do assertions by contains
|
|
|
|
$cf = $item->CommentsForm();
|
2017-10-09 22:26:17 +02:00
|
|
|
$expected = '/comments/CommentsForm/" method="post" enctype="application/x-www-form-urlencoded">';
|
2017-09-14 01:12:07 +02:00
|
|
|
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
$this->assertContains('<h4>Post your comment</h4>', $cf);
|
|
|
|
// check the comments form exists
|
2017-09-18 04:16:24 +02:00
|
|
|
$expected = '<input type="text" name="Name"';
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
$expected = '<input type="email" name="Email"';
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
$expected = '<input type="text" name="URL"';
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
$expected = '<input type="hidden" name="ParentID"';
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
$expected = '<textarea name="Comment"';
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
2017-09-14 01:12:07 +02:00
|
|
|
$expected = '<input type="submit" name="action_doPostComment" value="Post" class="action" id="comments-holder_action_doPostComment"';
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
2017-10-09 22:26:17 +02:00
|
|
|
$expected = '/comments/spam/';
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
|
|
|
$expected = '<p>Reply to firstComA 1</p>';
|
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
2017-10-09 22:26:17 +02:00
|
|
|
$expected = '/comments/delete';
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
|
|
|
$expected = '<p>Reply to firstComA 2</p>';
|
|
|
|
$this->assertContains($expected, $cf);
|
|
|
|
|
|
|
|
$expected = '<p>Reply to firstComA 3</p>';
|
|
|
|
$this->assertContains($expected, $cf);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testAttachedToSiteTree()
|
|
|
|
{
|
|
|
|
$this->markTestSkipped('TODO');
|
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testPagedComments()
|
|
|
|
{
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2016-01-07 07:59:10 +01:00
|
|
|
// Ensure Created times are set, as order not guaranteed if all set to 0
|
|
|
|
$comments = $item->PagedComments()->sort('ID');
|
|
|
|
$ctr = 0;
|
|
|
|
$timeBase = time()-10000;
|
|
|
|
foreach ($comments as $comment) {
|
|
|
|
$comment->Created = $timeBase + $ctr * 1000;
|
|
|
|
$comment->write();
|
|
|
|
$ctr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = $item->PagedComments()->toArray();
|
|
|
|
|
|
|
|
foreach ($results as $result) {
|
2016-02-19 01:48:25 +01:00
|
|
|
$result->sourceQueryParams = null;
|
2016-01-07 07:59:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2017-01-16 20:57:37 +01:00
|
|
|
$this->objFromFixture(Comment::class, 'firstComA')->Comment,
|
2016-01-07 07:59:10 +01:00
|
|
|
$results[3]->Comment
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2017-01-16 20:57:37 +01:00
|
|
|
$this->objFromFixture(Comment::class, 'firstComAChild1')->Comment,
|
2016-01-07 07:59:10 +01:00
|
|
|
$results[2]->Comment
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2017-01-16 20:57:37 +01:00
|
|
|
$this->objFromFixture(Comment::class, 'firstComAChild2')->Comment,
|
2016-01-07 07:59:10 +01:00
|
|
|
$results[1]->Comment
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2017-01-16 20:57:37 +01:00
|
|
|
$this->objFromFixture(Comment::class, 'firstComAChild3')->Comment,
|
2016-01-07 07:59:10 +01:00
|
|
|
$results[0]->Comment
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(4, sizeof($results));
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testUpdateModerationFields()
|
|
|
|
{
|
|
|
|
$this->markTestSkipped('TODO');
|
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testUpdateCMSFields()
|
|
|
|
{
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(
|
2017-01-16 20:57:37 +01:00
|
|
|
CommentableItem::class,
|
|
|
|
'comments',
|
|
|
|
array(
|
|
|
|
'require_login_cms' => false
|
2016-01-07 07:59:10 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->logInWithPermission('ADMIN');
|
2017-01-16 20:57:37 +01:00
|
|
|
$item = $this->objFromFixture(CommentableItem::class, 'first');
|
2016-01-07 07:59:10 +01:00
|
|
|
$item->ProvideComments = true;
|
|
|
|
$item->write();
|
|
|
|
$fields = $item->getCMSFields();
|
2017-10-09 06:26:07 +02:00
|
|
|
// print_r($item->getCMSFields());
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
CommentTestHelper::assertFieldsForTab(
|
|
|
|
$this,
|
2017-10-09 06:26:07 +02:00
|
|
|
'Root.Comments.CommentsNewCommentsTab',
|
2016-01-07 07:59:10 +01:00
|
|
|
array('NewComments'),
|
|
|
|
$fields
|
|
|
|
);
|
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
CommentTestHelper::assertFieldsForTab(
|
|
|
|
$this,
|
2017-10-09 06:26:07 +02:00
|
|
|
'Root.Comments.CommentsCommentsTab',
|
2016-01-07 07:59:10 +01:00
|
|
|
array('ApprovedComments'),
|
|
|
|
$fields
|
|
|
|
);
|
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
CommentTestHelper::assertFieldsForTab(
|
|
|
|
$this,
|
2017-10-09 06:26:07 +02:00
|
|
|
'Root.Comments.CommentsSpamCommentsTab',
|
2016-01-07 07:59:10 +01:00
|
|
|
array('SpamComments'),
|
|
|
|
$fields
|
|
|
|
);
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(
|
2017-01-16 20:57:37 +01:00
|
|
|
CommentableItem::class,
|
|
|
|
'comments',
|
|
|
|
array(
|
|
|
|
'require_login_cms' => true
|
2016-01-07 07:59:10 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$fields = $item->getCMSFields();
|
|
|
|
CommentTestHelper::assertFieldsForTab($this, 'Root.Settings', array('Comments'), $fields);
|
|
|
|
$settingsTab = $fields->findOrMakeTab('Root.Settings');
|
|
|
|
$settingsChildren = $settingsTab->getChildren();
|
|
|
|
$this->assertEquals(1, $settingsChildren->count());
|
|
|
|
$fieldGroup = $settingsChildren->first();
|
|
|
|
$fields = $fieldGroup->getChildren();
|
|
|
|
CommentTestHelper::assertFieldNames(
|
|
|
|
$this,
|
|
|
|
array('ProvideComments', 'CommentsRequireLogin'),
|
|
|
|
$fields
|
|
|
|
);
|
|
|
|
|
2017-10-09 06:26:07 +02:00
|
|
|
Config::modify()->merge(
|
2017-01-16 20:57:37 +01:00
|
|
|
CommentableItem::class,
|
|
|
|
'comments',
|
|
|
|
array(
|
|
|
|
'require_login_cms' => true,
|
|
|
|
'require_moderation_cms' => true
|
2016-01-07 07:59:10 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$fields = $item->getCMSFields();
|
|
|
|
CommentTestHelper::assertFieldsForTab(
|
|
|
|
$this,
|
|
|
|
'Root.Settings',
|
2017-01-16 20:57:37 +01:00
|
|
|
array('Comments', 'ModerationRequired'),
|
|
|
|
$fields
|
2016-01-07 07:59:10 +01:00
|
|
|
);
|
|
|
|
$settingsTab = $fields->findOrMakeTab('Root.Settings');
|
|
|
|
$settingsChildren = $settingsTab->getChildren();
|
|
|
|
$this->assertEquals(2, $settingsChildren->count());
|
|
|
|
$fieldGroup = $settingsChildren->first();
|
|
|
|
$fields = $fieldGroup->getChildren();
|
|
|
|
CommentTestHelper::assertFieldNames(
|
|
|
|
$this,
|
|
|
|
array('ProvideComments', 'CommentsRequireLogin'),
|
|
|
|
$fields
|
|
|
|
);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
}
|