FIX Remove reliance on translations in fieldLabels test, run textcollector, remove deprecated code from CommentsTest

This commit is contained in:
Robbie Averill 2019-05-10 09:33:18 +12:00
parent 74a317ab46
commit f65f5b5697
2 changed files with 160 additions and 172 deletions

View File

@ -18,10 +18,10 @@ en:
CommentsInterface_pendingcomment_ss: CommentsInterface_pendingcomment_ss:
AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.' AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.'
CommentsInterface_singlecomment_ss: CommentsInterface_singlecomment_ss:
APPROVE: 'approve it' APPROVE: 'Approve it'
ISNTSPAM: 'not spam' ISNTSPAM: 'Not spam'
ISSPAM: 'spam it' ISSPAM: 'Spam it'
REMCOM: 'reject it' REMCOM: 'Reject it'
REPLYTO: 'Reply to' REPLYTO: 'Reply to'
CommentsInterface_ss: CommentsInterface_ss:
AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.' AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.'
@ -50,9 +50,17 @@ en:
COMMENTAPPROVED: 'Comment approved.' COMMENTAPPROVED: 'Comment approved.'
COMMENTMARKEDSPAM: 'Comment marked as spam.' COMMENTMARKEDSPAM: 'Comment marked as spam.'
SPAM: Spam SPAM: Spam
SilverStripe\Comments\Admin\CommentsGridFieldApproveAction:
APPROVE: Approve
COMMENTAPPROVED: 'Comment approved.'
SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\CommentHandler:
CHANGES_APPLIED: 'Changes applied'
SilverStripe\Comments\Admin\CommentsGridFieldConfig: SilverStripe\Comments\Admin\CommentsGridFieldConfig:
APPROVE: Approve APPROVE: Approve
SPAM: Spam SPAM: Spam
SilverStripe\Comments\Admin\CommentsGridFieldSpamAction:
COMMENTMARKEDSPAM: 'Comment marked as spam.'
SPAM: Spam
SilverStripe\Comments\Controllers\CommentingController: SilverStripe\Comments\Controllers\CommentingController:
COMMENTS: Comments COMMENTS: Comments
EMAILADDRESS: 'Your email address (will not be published)' EMAILADDRESS: 'Your email address (will not be published)'
@ -67,14 +75,14 @@ en:
MODERATIONREQUIRED_NONMEMBERSONLY: 'Only moderate non-members' MODERATIONREQUIRED_NONMEMBERSONLY: 'Only moderate non-members'
MODERATIONREQUIRED_REQUIRED: 'Moderate all comments' MODERATIONREQUIRED_REQUIRED: 'Moderate all comments'
SilverStripe\Comments\Model\Comment: SilverStripe\Comments\Model\Comment:
ALLOWCOMMENTS: 'Allow Comments' ALLOWCOMMENTS: 'Allow comments'
COMMENT: Comment COMMENT: Comment
COMMENTBY: 'Comment by %s' COMMENTBY: 'Comment by %s'
CREATED: 'Date posted' CREATED: 'Date posted'
EMAIL: Email EMAIL: Email
ISSPAM: 'Spam?' ISSPAM: 'Spam?'
MODERATED: 'Moderated?' MODERATED: 'Moderated?'
NAME: 'Author Name' NAME: 'Author name'
'ON': 'on' 'ON': 'on'
OPTIONS: Options OPTIONS: Options
OPTION_DESCRIPTION: 'Unmoderated and spam comments will not be displayed until approved' OPTION_DESCRIPTION: 'Unmoderated and spam comments will not be displayed until approved'

View File

@ -2,101 +2,94 @@
namespace SilverStripe\Comments\Tests; namespace SilverStripe\Comments\Tests;
use HTMLPurifier_Config;
use HTMLPurifier; use HTMLPurifier;
use HTMLPurifier_Config;
use ReflectionClass; use ReflectionClass;
use SilverStripe\Comments\Extensions\CommentsExtension; use SilverStripe\Comments\Extensions\CommentsExtension;
use SilverStripe\Comments\Model\Comment; use SilverStripe\Comments\Model\Comment;
use SilverStripe\Comments\Tests\Stubs\CommentableItem; use SilverStripe\Comments\Tests\Stubs\CommentableItem;
use SilverStripe\Comments\Tests\Stubs\CommentableItemDisabled; use SilverStripe\Comments\Tests\Stubs\CommentableItemDisabled;
use SilverStripe\Comments\Tests\Stubs\CommentableItemEnabled; use SilverStripe\Comments\Tests\Stubs\CommentableItemEnabled;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Email\Email;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\Security\Permission;
class CommentsTest extends FunctionalTest class CommentsTest extends FunctionalTest
{ {
protected static $fixture_file = 'CommentsTest.yml'; protected static $fixture_file = 'CommentsTest.yml';
protected static $extra_dataobjects = array( protected static $extra_dataobjects = [
CommentableItem::class, CommentableItem::class,
CommentableItemEnabled::class, CommentableItemEnabled::class,
CommentableItemDisabled::class CommentableItemDisabled::class,
); ];
public function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
// Set good default values // Set good default values
Config::modify()->merge(CommentsExtension::class, 'comments', array( Config::modify()->merge(CommentsExtension::class, 'comments', [
'enabled' => true, 'enabled' => true,
'comment_permalink_prefix' => 'comment-' 'comment_permalink_prefix' => 'comment-',
)); ]);
} }
public function testCommentsList() public function testCommentsList()
{ {
// comments don't require moderation so unmoderated comments can be // comments don't require moderation so unmoderated comments can be
// shown but not spam posts // shown but not spam posts
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'require_moderation_nonmembers' => false, 'require_moderation_nonmembers' => false,
'require_moderation' => false, 'require_moderation' => false,
'require_moderation_cms' => false, 'require_moderation_cms' => false,
)); ]);
$item = $this->objFromFixture(CommentableItem::class, 'spammed'); $item = $this->objFromFixture(CommentableItem::class, 'spammed');
$this->assertDOSEquals(array( $this->assertListEquals([
array('Name' => 'Comment 1'), ['Name' => 'Comment 1'],
array('Name' => 'Comment 3') ['Name' => 'Comment 3']
), $item->Comments(), 'Only 2 non spam posts should be shown'); ], $item->Comments(), 'Only 2 non spam posts should be shown');
// when moderated, only moderated, non spam posts should be shown. // when moderated, only moderated, non spam posts should be shown.
Config::modify()->merge(CommentableItem::class, 'comments', array('require_moderation_nonmembers' => true)); Config::modify()->merge(CommentableItem::class, 'comments', ['require_moderation_nonmembers' => true]);
// Check that require_moderation overrides this option // Check that require_moderation overrides this option
Config::modify()->merge(CommentableItem::class, 'comments', array('require_moderation' => true)); Config::modify()->merge(CommentableItem::class, 'comments', ['require_moderation' => true]);
$this->assertDOSEquals(array( $this->assertListEquals(array(
array('Name' => 'Comment 3') array('Name' => 'Comment 3')
), $item->Comments(), 'Only 1 non spam, moderated post should be shown'); ), $item->Comments(), 'Only 1 non spam, moderated post should be shown');
$this->assertEquals(1, $item->Comments()->Count()); $this->assertEquals(1, $item->Comments()->Count());
// require_moderation_nonmembers still filters out unmoderated comments // require_moderation_nonmembers still filters out unmoderated comments
Config::modify()->merge(CommentableItem::class, 'comments', array('require_moderation' => false)); Config::modify()->merge(CommentableItem::class, 'comments', ['require_moderation' => false]);
$this->assertEquals(1, $item->Comments()->Count()); $this->assertEquals(1, $item->Comments()->Count());
Config::modify()->merge(CommentableItem::class, 'comments', array('require_moderation_nonmembers' => false)); Config::modify()->merge(CommentableItem::class, 'comments', ['require_moderation_nonmembers' => false]);
$this->assertEquals(2, $item->Comments()->Count()); $this->assertEquals(2, $item->Comments()->Count());
// With unmoderated comments set to display in frontend // With unmoderated comments set to display in frontend
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'require_moderation' => true, 'require_moderation' => true,
'frontend_moderation' => true 'frontend_moderation' => true,
)); ]);
$this->assertEquals(1, $item->Comments()->Count()); $this->assertEquals(1, $item->Comments()->Count());
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$this->assertEquals(2, $item->Comments()->Count()); $this->assertEquals(2, $item->Comments()->Count());
// With spam comments set to display in frontend // With spam comments set to display in frontend
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'require_moderation' => true, 'require_moderation' => true,
'frontend_moderation' => false, 'frontend_moderation' => false,
'frontend_spam' => true, 'frontend_spam' => true,
)); ]);
if ($member = Member::currentUser()) {
$member->logOut(); $this->logOut();
}
$this->assertEquals(1, $item->Comments()->Count()); $this->assertEquals(1, $item->Comments()->Count());
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
@ -104,14 +97,13 @@ class CommentsTest extends FunctionalTest
// With spam and unmoderated comments set to display in frontend // With spam and unmoderated comments set to display in frontend
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'require_moderation' => true, 'require_moderation' => true,
'frontend_moderation' => true, 'frontend_moderation' => true,
'frontend_spam' => true, 'frontend_spam' => true,
)); ]);
if ($member = Member::currentUser()) {
$member->logOut(); $this->logOut();
}
$this->assertEquals(1, $item->Comments()->Count()); $this->assertEquals(1, $item->Comments()->Count());
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
@ -123,19 +115,19 @@ class CommentsTest extends FunctionalTest
*/ */
public function testCommentCMSModerationList() public function testCommentCMSModerationList()
{ {
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'require_moderation' => true, 'require_moderation' => true,
'require_moderation_cms' => true, 'require_moderation_cms' => true,
)); ]);
$item = $this->objFromFixture(CommentableItem::class, 'spammed'); $item = $this->objFromFixture(CommentableItem::class, 'spammed');
$this->assertEquals('None', $item->getModerationRequired()); $this->assertEquals('None', $item->getModerationRequired());
$this->assertDOSEquals(array( $this->assertListEquals([
array('Name' => 'Comment 1'), ['Name' => 'Comment 1'],
array('Name' => 'Comment 3') ['Name' => 'Comment 3']
), $item->Comments(), 'Only 2 non spam posts should be shown'); ], $item->Comments(), 'Only 2 non spam posts should be shown');
// when moderated, only moderated, non spam posts should be shown. // when moderated, only moderated, non spam posts should be shown.
$item->ModerationRequired = 'NonMembersOnly'; $item->ModerationRequired = 'NonMembersOnly';
@ -148,9 +140,9 @@ class CommentsTest extends FunctionalTest
$item->write(); $item->write();
$this->assertEquals('Required', $item->getModerationRequired()); $this->assertEquals('Required', $item->getModerationRequired());
$this->assertDOSEquals(array( $this->assertListEquals([
array('Name' => 'Comment 3') ['Name' => 'Comment 3']
), $item->Comments(), 'Only 1 non spam, moderated post should be shown'); ], $item->Comments(), 'Only 1 non spam, moderated post should be shown');
$this->assertEquals(1, $item->Comments()->Count()); $this->assertEquals(1, $item->Comments()->Count());
// require_moderation_nonmembers still filters out unmoderated comments // require_moderation_nonmembers still filters out unmoderated comments
@ -165,26 +157,26 @@ class CommentsTest extends FunctionalTest
public function testCanPostComment() public function testCanPostComment()
{ {
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'require_login' => false, 'require_login' => false,
'require_login_cms' => false, 'require_login_cms' => false,
'required_permission' => false, 'required_permission' => false,
)); ]);
/** @var CommentableItem&CommentsExtension $item */
$item = $this->objFromFixture(CommentableItem::class, 'first'); $item = $this->objFromFixture(CommentableItem::class, 'first');
/** @var CommentableItem&CommentsExtension $item2 */
$item2 = $this->objFromFixture(CommentableItem::class, 'second'); $item2 = $this->objFromFixture(CommentableItem::class, 'second');
// Test restriction free commenting // Test restriction free commenting
if ($member = Member::currentUser()) { $this->logOut();
$member->logOut();
}
$this->assertFalse($item->CommentsRequireLogin); $this->assertFalse($item->CommentsRequireLogin);
$this->assertTrue($item->canPostComment()); $this->assertTrue($item->canPostComment());
// Test permission required to post // Test permission required to post
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'require_login' => true, 'require_login' => true,
'required_permission' => 'POSTING_PERMISSION', 'required_permission' => 'POSTING_PERMISSION',
)); ]);
$this->assertTrue($item->CommentsRequireLogin); $this->assertTrue($item->CommentsRequireLogin);
$this->assertFalse($item->canPostComment()); $this->assertFalse($item->canPostComment());
$this->logInWithPermission('WRONG_ONE'); $this->logInWithPermission('WRONG_ONE');
@ -195,27 +187,25 @@ class CommentsTest extends FunctionalTest
$this->assertTrue($item->canPostComment()); $this->assertTrue($item->canPostComment());
// Test require login to post, but not any permissions // Test require login to post, but not any permissions
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'required_permission' => false, 'required_permission' => false,
)); ]);
$this->assertTrue($item->CommentsRequireLogin); $this->assertTrue($item->CommentsRequireLogin);
if ($member = Member::currentUser()) {
$member->logOut(); $this->logOut();
}
$this->assertFalse($item->canPostComment()); $this->assertFalse($item->canPostComment());
$this->logInWithPermission('ANY_PERMISSION'); $this->logInWithPermission('ANY_PERMISSION');
$this->assertTrue($item->canPostComment()); $this->assertTrue($item->canPostComment());
// Test options set via CMS // Test options set via CMS
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'require_login' => true, 'require_login' => true,
'require_login_cms' => true, 'require_login_cms' => true,
)); ]);
$this->assertFalse($item->CommentsRequireLogin); $this->assertFalse($item->CommentsRequireLogin);
$this->assertTrue($item2->CommentsRequireLogin); $this->assertTrue($item2->CommentsRequireLogin);
if ($member = Member::currentUser()) {
$member->logOut(); $this->logOut();
}
$this->assertTrue($item->canPostComment()); $this->assertTrue($item->canPostComment());
$this->assertFalse($item2->canPostComment()); $this->assertFalse($item2->canPostComment());
@ -227,9 +217,7 @@ class CommentsTest extends FunctionalTest
public function testDeleteComment() public function testDeleteComment()
{ {
// Test anonymous user // Test anonymous user
if ($member = Member::currentUser()) { $this->logOut();
$member->logOut();
}
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$commentID = $comment->ID; $commentID = $comment->ID;
$this->assertNull($comment->DeleteLink(), 'No permission to see delete link'); $this->assertNull($comment->DeleteLink(), 'No permission to see delete link');
@ -269,9 +257,7 @@ class CommentsTest extends FunctionalTest
public function testSpamComment() public function testSpamComment()
{ {
// Test anonymous user // Test anonymous user
if ($member = Member::currentUser()) { $this->logOut();
$member->logOut();
}
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$commentID = $comment->ID; $commentID = $comment->ID;
$this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link'); $this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link');
@ -314,9 +300,7 @@ class CommentsTest extends FunctionalTest
public function testHamComment() public function testHamComment()
{ {
// Test anonymous user // Test anonymous user
if ($member = Member::currentUser()) { $this->logOut();
$member->logOut();
}
$comment = $this->objFromFixture(Comment::class, 'secondComC'); $comment = $this->objFromFixture(Comment::class, 'secondComC');
$commentID = $comment->ID; $commentID = $comment->ID;
$this->assertNull($comment->HamLink(), 'No permission to see mark as ham link'); $this->assertNull($comment->HamLink(), 'No permission to see mark as ham link');
@ -359,9 +343,7 @@ class CommentsTest extends FunctionalTest
public function testApproveComment() public function testApproveComment()
{ {
// Test anonymous user // Test anonymous user
if ($member = Member::currentUser()) { $this->logOut();
$member->logOut();
}
$comment = $this->objFromFixture(Comment::class, 'secondComB'); $comment = $this->objFromFixture(Comment::class, 'secondComB');
$commentID = $comment->ID; $commentID = $comment->ID;
$this->assertNull($comment->ApproveLink(), 'No permission to see approve link'); $this->assertNull($comment->ApproveLink(), 'No permission to see approve link');
@ -406,10 +388,10 @@ class CommentsTest extends FunctionalTest
$comment = new Comment(); $comment = new Comment();
// We only care about the CommenterURL, so only set that // We only care about the CommenterURL, so only set that
// Check a http and https URL. Add more test urls here as needed. // Check a http and https URL. Add more test urls here as needed.
$protocols = array( $protocols = [
'Http', 'Http',
'Https', 'Https',
); ];
$url = '://example.com'; $url = '://example.com';
foreach ($protocols as $protocol) { foreach ($protocols as $protocol) {
@ -424,14 +406,13 @@ class CommentsTest extends FunctionalTest
{ {
if (!class_exists('\\HTMLPurifier')) { if (!class_exists('\\HTMLPurifier')) {
$this->markTestSkipped('HTMLPurifier class not found'); $this->markTestSkipped('HTMLPurifier class not found');
return;
} }
// Add p for paragraph // Add p for paragraph
// NOTE: The config method appears to append to the existing array // NOTE: The config method appears to append to the existing array
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'html_allowed_elements' => array('p'), 'html_allowed_elements' => ['p'],
)); ]);
// Without HTML allowed // Without HTML allowed
$comment1 = new Comment(); $comment1 = new Comment();
@ -465,9 +446,9 @@ class CommentsTest extends FunctionalTest
$this->markTestSkipped('HTMLPurifier class not found'); $this->markTestSkipped('HTMLPurifier class not found');
} }
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'html_allowed_elements' => array('p'), 'html_allowed_elements' => ['p'],
)); ]);
$item = new CommentableItem(); $item = new CommentableItem();
$item->write(); $item->write();
@ -480,7 +461,7 @@ class CommentsTest extends FunctionalTest
$comment->ParentClass = CommentableItem::class; $comment->ParentClass = CommentableItem::class;
$comment->write(); $comment->write();
$html = $item->customise(array('CommentsEnabled' => true))->renderWith('CommentsInterface'); $html = $item->customise(['CommentsEnabled' => true])->renderWith('CommentsInterface');
$this->assertContains( $this->assertContains(
'<p>my comment</p>', '<p>my comment</p>',
$html $html
@ -488,7 +469,7 @@ class CommentsTest extends FunctionalTest
$comment->AllowHtml = true; $comment->AllowHtml = true;
$comment->write(); $comment->write();
$html = $item->customise(array('CommentsEnabled' => true))->renderWith('CommentsInterface'); $html = $item->customise(['CommentsEnabled' => true])->renderWith('CommentsInterface');
$this->assertContains( $this->assertContains(
'<p>my comment</p>', '<p>my comment</p>',
$html $html
@ -501,11 +482,11 @@ class CommentsTest extends FunctionalTest
*/ */
public function testDefaultEnabled() public function testDefaultEnabled()
{ {
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'enabled_cms' => true, 'enabled_cms' => true,
'require_moderation_cms' => true, 'require_moderation_cms' => true,
'require_login_cms' => true 'require_login_cms' => true,
)); ]);
// With default = true // With default = true
$obj = new CommentableItem(); $obj = new CommentableItem();
@ -526,11 +507,11 @@ class CommentsTest extends FunctionalTest
// With default = false // With default = false
// Because of config rules about falsey values, apply config to object directly // Because of config rules about falsey values, apply config to object directly
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'enabled' => false, 'enabled' => false,
'require_login' => true, 'require_login' => true,
'require_moderation' => true 'require_moderation' => true,
)); ]);
$obj = new CommentableItem(); $obj = new CommentableItem();
@ -601,7 +582,7 @@ class CommentsTest extends FunctionalTest
} }
/** /**
* Test field labels in 2 languages * Test field labels are defined
*/ */
public function testFieldLabels() public function testFieldLabels()
{ {
@ -609,18 +590,18 @@ class CommentsTest extends FunctionalTest
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$labels = $comment->FieldLabels(); $labels = $comment->FieldLabels();
$expected = array( $expected = [
'Name' => 'Author name', 'Name',
'Comment' => 'Comment', 'Comment',
'Email' => 'Email', 'Email',
'URL' => 'URL', 'URL',
'IsSpam' => 'Spam?', 'IsSpam',
'Moderated' => 'Moderated?', 'Moderated',
'ParentTitle' => 'Parent', 'ParentTitle',
'Created' => 'Date posted', 'Created',
); ];
foreach ($expected as $key => $value) { foreach ($expected as $key) {
$this->assertEquals($value, $labels[$key]); $this->assertArrayHasKey($key, $labels);
} }
} }
@ -869,18 +850,18 @@ class CommentsTest extends FunctionalTest
{ {
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$fields = $comment->getCMSFields(); $fields = $comment->getCMSFields();
$names = array(); $names = [];
foreach ($fields as $field) { foreach ($fields as $field) {
$names[] = $field->getName(); $names[] = $field->getName();
} }
$expected = array( $expected = [
'Created', 'Created',
'Name', 'Name',
'Comment', 'Comment',
'Email', 'Email',
'URL', 'URL',
'Options' 'Options',
); ];
$this->assertEquals($expected, $names); $this->assertEquals($expected, $names);
} }
@ -892,19 +873,19 @@ class CommentsTest extends FunctionalTest
$comment->write(); $comment->write();
$fields = $comment->getCMSFields(); $fields = $comment->getCMSFields();
$names = array(); $names = [];
foreach ($fields as $field) { foreach ($fields as $field) {
$names[] = $field->getName(); $names[] = $field->getName();
} }
$expected = array( $expected = [
'Created', 'Created',
'Name', 'Name',
'AuthorMember', 'AuthorMember',
'Comment', 'Comment',
'Email', 'Email',
'URL', 'URL',
'Options' 'Options',
); ];
$this->assertEquals($expected, $names); $this->assertEquals($expected, $names);
} }
@ -919,11 +900,11 @@ class CommentsTest extends FunctionalTest
$child->write(); $child->write();
$fields = $child->getCMSFields(); $fields = $child->getCMSFields();
$names = array(); $names = [];
foreach ($fields as $field) { foreach ($fields as $field) {
$names[] = $field->getName(); $names[] = $field->getName();
} }
$expected = array( $expected = [
'Created', 'Created',
'Name', 'Name',
'Comment', 'Comment',
@ -933,8 +914,8 @@ class CommentsTest extends FunctionalTest
'ParentComment_Title', 'ParentComment_Title',
'ParentComment_Created', 'ParentComment_Created',
'ParentComment_AuthorName', 'ParentComment_AuthorName',
'ParentComment_EscapedComment' 'ParentComment_EscapedComment',
); ];
$this->assertEquals($expected, $names); $this->assertEquals($expected, $names);
} }
@ -942,7 +923,6 @@ class CommentsTest extends FunctionalTest
{ {
if (!class_exists(HTMLPurifier_Config::class)) { if (!class_exists(HTMLPurifier_Config::class)) {
$this->markTestSkipped('HTMLPurifier class not found'); $this->markTestSkipped('HTMLPurifier class not found');
return;
} }
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
@ -957,12 +937,12 @@ class CommentsTest extends FunctionalTest
public function testGravatar() public function testGravatar()
{ {
// Turn gravatars on // Turn gravatars on
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'use_gravatar' => true, 'use_gravatar' => true,
'gravatar_size' => 80, 'gravatar_size' => 80,
'gravatar_default' => 'identicon', 'gravatar_default' => 'identicon',
'gravatar_rating' => 'g' 'gravatar_rating' => 'g',
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
@ -973,9 +953,9 @@ class CommentsTest extends FunctionalTest
); );
// Turn gravatars off // Turn gravatars off
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'use_gravatar' => false 'use_gravatar' => false,
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
@ -987,17 +967,17 @@ class CommentsTest extends FunctionalTest
public function testGetRepliesEnabled() public function testGetRepliesEnabled()
{ {
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => false 'nested_comments' => false,
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertFalse($comment->getRepliesEnabled()); $this->assertFalse($comment->getRepliesEnabled());
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4,
)); ]);
$this->assertTrue($comment->getRepliesEnabled()); $this->assertTrue($comment->getRepliesEnabled());
@ -1006,10 +986,10 @@ class CommentsTest extends FunctionalTest
// 0 indicates no limit for nested_depth // 0 indicates no limit for nested_depth
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 0 'nested_depth' => 0,
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$comment->Depth = 234; $comment->Depth = 234;
@ -1026,10 +1006,10 @@ class CommentsTest extends FunctionalTest
public function testAllReplies() public function testAllReplies()
{ {
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4,
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
@ -1052,9 +1032,9 @@ class CommentsTest extends FunctionalTest
$comment->allReplies()->count() $comment->allReplies()->count()
); );
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => false 'nested_comments' => false,
)); ]);
$this->assertEquals(0, $comment->allReplies()->count()); $this->assertEquals(0, $comment->allReplies()->count());
} }
@ -1063,10 +1043,10 @@ class CommentsTest extends FunctionalTest
{ {
CommentableItem::add_extension(CommentsExtension::class); CommentableItem::add_extension(CommentsExtension::class);
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4,
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertEquals( $this->assertEquals(
3, 3,
@ -1101,11 +1081,11 @@ class CommentsTest extends FunctionalTest
$item->ModerationRequired = 'Required'; $item->ModerationRequired = 'Required';
$item->write(); $item->write();
Config::modify()->merge(CommentableItemDisabled::class, 'comments', array( Config::modify()->merge(CommentableItemDisabled::class, 'comments', [
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4, 'nested_depth' => 4,
'frontend_moderation' => true 'frontend_moderation' => true,
)); ]);
$comment = DataObject::get_by_id(Comment::class, $comment->ID); $comment = DataObject::get_by_id(Comment::class, $comment->ID);
@ -1115,9 +1095,9 @@ class CommentsTest extends FunctionalTest
); );
// Turn off nesting, empty array should be returned // Turn off nesting, empty array should be returned
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => false 'nested_comments' => false,
)); ]);
$this->assertEquals( $this->assertEquals(
0, 0,
@ -1129,11 +1109,11 @@ class CommentsTest extends FunctionalTest
public function testPagedReplies() public function testPagedReplies()
{ {
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4, 'nested_depth' => 4,
'comments_per_page' => 2 'comments_per_page' => 2,
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$pagedList = $comment->pagedReplies(); $pagedList = $comment->pagedReplies();
@ -1148,19 +1128,19 @@ class CommentsTest extends FunctionalTest
$pagedList->getTotalItems() $pagedList->getTotalItems()
); );
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => false 'nested_comments' => false,
)); ]);
$this->assertEquals(0, $comment->PagedReplies()->count()); $this->assertEquals(0, $comment->PagedReplies()->count());
} }
public function testReplyForm() public function testReplyForm()
{ {
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => false, 'nested_comments' => false,
'nested_depth' => 4 'nested_depth' => 4,
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
@ -1169,13 +1149,13 @@ class CommentsTest extends FunctionalTest
$this->assertNull($form); $this->assertNull($form);
// parent item so show form // parent item so show form
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4,
)); ]);
$form = $comment->ReplyForm(); $form = $comment->ReplyForm();
$this->assertNotNull($form); $this->assertNotNull($form);
$names = array(); $names = [];
foreach ($form->Fields() as $field) { foreach ($form->Fields() as $field) {
array_push($names, $field->getName()); array_push($names, $field->getName());
@ -1198,10 +1178,10 @@ class CommentsTest extends FunctionalTest
public function testUpdateDepth() public function testUpdateDepth()
{ {
Config::modify()->merge(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4,
)); ]);
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$children = $comment->allReplies()->toArray(); $children = $comment->allReplies()->toArray();