Merge branch '3.1'

This commit is contained in:
Robbie Averill 2018-06-20 16:28:40 +12:00
commit 8bd79eac1f
4 changed files with 46 additions and 22 deletions

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Comments\Forms;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\FieldList;
@ -192,7 +193,7 @@ class CommentForm extends Form
// If commenting can only be done by logged in users, make sure the user is logged in
if (!$this->controller->getOwnerRecord()->canPostComment()) {
return Security::permissionFailure(
$this,
$this->controller,
_t(
'SilverStripe\\Comments\\Controllers\\CommentingController.PERMISSIONFAILURE',
"You're not able to post comments to this page. Please ensure you are logged in and have an "

View File

@ -2,31 +2,31 @@
namespace SilverStripe\Comments\Model;
use HTMLPurifier_Config;
use HTMLPurifier;
use HTMLPurifier_Config;
use SilverStripe\Comments\Controllers\CommentingController;
use SilverStripe\Comments\Extensions\CommentsExtension;
use SilverStripe\Comments\Model\Comment\SecurityToken;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Core\Email\Email;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\TempFolder;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\CMS\Model\SiteTree;
/**
* Represents a single comment object.
@ -104,6 +104,7 @@ class Comment extends DataObject
'AuthorName' => 'Varchar',
'RSSName' => 'Varchar',
'DeleteLink' => 'Varchar',
'Date' => 'Datetime',
'SpamLink' => 'Varchar',
'HamLink' => 'Varchar',
'ApproveLink' => 'Varchar',
@ -218,14 +219,14 @@ class Comment extends DataObject
{
$labels = parent::fieldLabels($includerelations);
$labels['Name'] = _t('SilverStripe\\Comments\\Model\\Comment.NAME', 'Author Name');
$labels['Comment'] = _t('SilverStripe\\Comments\\Model\\Comment.COMMENT', 'Comment');
$labels['Email'] = _t('SilverStripe\\Comments\\Model\\Comment.EMAIL', 'Email');
$labels['URL'] = _t('SilverStripe\\Comments\\Model\\Comment.URL', 'URL');
$labels['IsSpam'] = _t('SilverStripe\\Comments\\Model\\Comment.ISSPAM', 'Spam?');
$labels['Moderated'] = _t('SilverStripe\\Comments\\Model\\Comment.MODERATED', 'Moderated?');
$labels['ParentTitle'] = _t('SilverStripe\\Comments\\Model\\Comment.PARENTTITLE', 'Parent');
$labels['Created'] = _t('SilverStripe\\Comments\\Model\\Comment.CREATED', 'Date posted');
$labels['Name'] = _t(__CLASS__ . '.NAME', 'Author Name');
$labels['Comment'] = _t(__CLASS__ . '.COMMENT', 'Comment');
$labels['Email'] = _t(__CLASS__ . '.EMAIL', 'Email');
$labels['URL'] = _t(__CLASS__ . '.URL', 'URL');
$labels['IsSpam'] = _t(__CLASS__ . '.ISSPAM', 'Spam?');
$labels['Moderated'] = _t(__CLASS__ . '.MODERATED', 'Moderated?');
$labels['ParentTitle'] = _t(__CLASS__ . '.PARENTTITLE', 'Parent');
$labels['Created'] = _t(__CLASS__ . '.CREATED', 'Date posted');
return $labels;
}
@ -593,11 +594,11 @@ class Comment extends DataObject
*/
public function getTitle()
{
$title = sprintf(_t('SilverStripe\\Comments\\Model\\Comment.COMMENTBY', 'Comment by %s', 'Name'), $this->getAuthorName());
$title = sprintf(_t(__CLASS__ . '.COMMENTBY', 'Comment by %s', 'Name'), $this->getAuthorName());
if ($parent = $this->Parent()) {
if ($parent->Title) {
$title .= sprintf(' %s %s', _t('SilverStripe\\Comments\\Model\\Comment.ON', 'on'), $parent->Title);
$title .= sprintf(' %s %s', _t(__CLASS__ . '.ON', 'on'), $parent->Title);
}
}
@ -623,9 +624,9 @@ class Comment extends DataObject
CheckboxField::create('Moderated', $this->fieldLabel('Moderated')),
CheckboxField::create('IsSpam', $this->fieldLabel('IsSpam')),
))
->setTitle(_t('SilverStripe\\Comments\\Model\\Comment.OPTIONS', 'Options'))
->setTitle(_t(__CLASS__ . '.OPTIONS', 'Options'))
->setDescription(_t(
'SilverStripe\\Comments\\Model\\Comment.OPTION_DESCRIPTION',
__CLASS__ . '.OPTION_DESCRIPTION',
'Unmoderated and spam comments will not be displayed until approved'
))
);
@ -643,7 +644,7 @@ class Comment extends DataObject
if (($parent = $this->ParentComment()) && $parent->exists()) {
$fields->push(new HeaderField(
'ParentComment_Title',
_t('SilverStripe\\Comments\\Model\\Comment.ParentComment_Title', 'This comment is a reply to the below')
_t(__CLASS__ . '.ParentComment_Title', 'This comment is a reply to the below')
));
// Created date
// FIXME - the method setName in DatetimeField is not chainable, hence
@ -865,6 +866,14 @@ class Comment extends DataObject
return $controller->ReplyForm($this);
}
/**
* @return string
*/
public function getDate()
{
return $this->Created;
}
/**
* Refresh of this comment in the hierarchy
*/

View File

@ -2,14 +2,14 @@
namespace SilverStripe\Comments\Tests;
use SilverStripe\Akismet\AkismetSpamProtector;
use SilverStripe\Comments\Controllers\CommentingController;
use SilverStripe\Comments\Model\Comment;
use SilverStripe\Comments\Model\Comment\SecurityToken as CommentSecurityToken;
use SilverStripe\Comments\Tests\Stubs\CommentableItem;
use SilverStripe\Comments\Tests\CommentTestHelper;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Email\Email;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
@ -48,6 +48,12 @@ class CommentingControllerTest extends FunctionalTest
// We will assert against explicit responses, unless handed otherwise in a test for redirects
$this->autoFollowRedirection = false;
// Mock Akismet if it's installed
if (class_exists(AkismetSpamProtector::class)) {
$akismetMock = $this->createMock(AkismetSpamProtector::class);
Injector::inst()->registerService($akismetMock, AkismetSpamProtector::class);
}
}
public function testCommentsFormUsePreview()

View File

@ -607,7 +607,10 @@ class CommentsTest extends FunctionalTest
{
$locale = i18n::get_locale();
i18n::set_locale('fr');
/** @var Comment $comment */
$comment = $this->objFromFixture(Comment::class, 'firstComA');
$labels = $comment->FieldLabels();
$expected = array(
'Name' => 'Nom de l\'Auteur',
@ -627,7 +630,10 @@ class CommentsTest extends FunctionalTest
'Parent' => 'Parent'
);
i18n::set_locale($locale);
$this->assertEquals($expected, $labels);
foreach ($expected as $key => $value) {
$this->assertEquals($value, $labels[$key]);
}
$labels = $comment->FieldLabels();
$expected = array(
'Name' => 'Author Name',
@ -646,7 +652,9 @@ class CommentsTest extends FunctionalTest
'Created' => 'Date posted',
'Parent' => 'Parent'
);
$this->assertEquals($expected, $labels);
foreach ($expected as $key => $value) {
$this->assertEquals($value, $labels[$key]);
}
}
public function testGetParent()