mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Reformat as PSR-2
This commit is contained in:
parent
c2fee6bd33
commit
4b31713128
@ -13,7 +13,8 @@
|
||||
*
|
||||
* @package comments
|
||||
*/
|
||||
class Commenting {
|
||||
class Commenting
|
||||
{
|
||||
|
||||
/**
|
||||
* Adds commenting to a {@link DataObject}
|
||||
@ -26,12 +27,15 @@ class Commenting {
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function add($class, $settings = false) {
|
||||
public static function add($class, $settings = false)
|
||||
{
|
||||
Deprecation::notice('2.0', 'Using Commenting::add is deprecated. Please use the config API instead');
|
||||
Config::inst()->update($class, 'extensions', array('CommentsExtension'));
|
||||
|
||||
// Check if settings must be customised
|
||||
if($settings === false) return;
|
||||
if ($settings === false) {
|
||||
return;
|
||||
}
|
||||
if (!is_array($settings)) {
|
||||
throw new InvalidArgumentException('$settings needs to be an array or null');
|
||||
}
|
||||
@ -46,7 +50,8 @@ class Commenting {
|
||||
*
|
||||
* @param string $class Class to remove {@link CommentsExtension} from
|
||||
*/
|
||||
public static function remove($class) {
|
||||
public static function remove($class)
|
||||
{
|
||||
Deprecation::notice('2.0', 'Using Commenting::remove is deprecated. Please use the config API instead');
|
||||
$class::remove_extension('CommentsExtension');
|
||||
}
|
||||
@ -58,7 +63,8 @@ class Commenting {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_commenting($class) {
|
||||
public static function has_commenting($class)
|
||||
{
|
||||
Deprecation::notice('2.0', 'Using Commenting::has_commenting is deprecated. Please use the config API instead');
|
||||
return $class::has_extension('CommentsExtension');
|
||||
}
|
||||
@ -74,9 +80,12 @@ class Commenting {
|
||||
* @param string $key setting to change
|
||||
* @param mixed $value value of the setting
|
||||
*/
|
||||
public static function set_config_value($class, $key, $value = false) {
|
||||
public static function set_config_value($class, $key, $value = false)
|
||||
{
|
||||
Deprecation::notice('2.0', 'Commenting::set_config_value is deprecated. Use the config api instead');
|
||||
if($class === "all") $class = 'CommentsExtension';
|
||||
if ($class === "all") {
|
||||
$class = 'CommentsExtension';
|
||||
}
|
||||
Config::inst()->update($class, 'comments', array($key => $value));
|
||||
}
|
||||
|
||||
@ -91,7 +100,8 @@ class Commenting {
|
||||
* @throws Exception
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_config_value($class, $key) {
|
||||
public static function get_config_value($class, $key)
|
||||
{
|
||||
Deprecation::notice(
|
||||
'2.0',
|
||||
'Using Commenting::get_config_value is deprecated. Please use $parent->getCommentsOption() or '
|
||||
@ -118,9 +128,12 @@ class Commenting {
|
||||
* @param string $value Expected value
|
||||
* @return boolean
|
||||
*/
|
||||
public static function config_value_equals($class, $key, $value) {
|
||||
public static function config_value_equals($class, $key, $value)
|
||||
{
|
||||
$check = self::get_config_value($class, $key);
|
||||
if($check && ($check == $value)) return true;
|
||||
if ($check && ($check == $value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,13 +144,16 @@ class Commenting {
|
||||
* @param string $class
|
||||
* @return boolean true
|
||||
*/
|
||||
public static function can_member_post($class) {
|
||||
public static function can_member_post($class)
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use $instance->canPostComment() directly instead');
|
||||
$member = Member::currentUser();
|
||||
|
||||
// Check permission
|
||||
$permission = self::get_config_value($class, 'required_permission');
|
||||
if($permission && !Permission::check($permission)) return false;
|
||||
if ($permission && !Permission::check($permission)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check login required
|
||||
$requireLogin = self::get_config_value($class, 'require_login');
|
||||
|
@ -5,7 +5,8 @@
|
||||
*
|
||||
* @package comments
|
||||
*/
|
||||
class CommentAdmin extends LeftAndMain implements PermissionProvider {
|
||||
class CommentAdmin extends LeftAndMain implements PermissionProvider
|
||||
{
|
||||
|
||||
private static $url_segment = 'comments';
|
||||
|
||||
@ -24,7 +25,8 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider {
|
||||
'unmoderated'
|
||||
);
|
||||
|
||||
public function providePermissions() {
|
||||
public function providePermissions()
|
||||
{
|
||||
return array(
|
||||
"CMS_ACCESS_CommentAdmin" => array(
|
||||
'name' => _t('CommentAdmin.ADMIN_PERMISSION', "Access to 'Comments' section"),
|
||||
@ -36,8 +38,11 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider {
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
public function getEditForm($id = null, $fields = null) {
|
||||
if(!$id) $id = $this->currentPageID();
|
||||
public function getEditForm($id = null, $fields = null)
|
||||
{
|
||||
if (!$id) {
|
||||
$id = $this->currentPageID();
|
||||
}
|
||||
|
||||
$form = parent::getEditForm($id);
|
||||
$record = $this->getRecord($id);
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
class CommentsGridField extends GridField {
|
||||
class CommentsGridField extends GridField
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function newRow($total, $index, $record, $attributes, $content) {
|
||||
protected function newRow($total, $index, $record, $attributes, $content)
|
||||
{
|
||||
if (!isset($attributes['class'])) {
|
||||
$attributes['class'] = '';
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_ActionProvider {
|
||||
class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_ActionProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function augmentColumns($gridField, &$columns) {
|
||||
public function augmentColumns($gridField, &$columns)
|
||||
{
|
||||
if (!in_array('Actions', $columns)) {
|
||||
$columns[] = 'Actions';
|
||||
}
|
||||
@ -13,14 +15,16 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumnAttributes($gridField, $record, $columnName) {
|
||||
public function getColumnAttributes($gridField, $record, $columnName)
|
||||
{
|
||||
return array('class' => 'col-buttons');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumnMetadata($gridField, $columnName) {
|
||||
public function getColumnMetadata($gridField, $columnName)
|
||||
{
|
||||
if ($columnName == 'Actions') {
|
||||
return array('title' => '');
|
||||
}
|
||||
@ -29,15 +33,19 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumnsHandled($gridField) {
|
||||
public function getColumnsHandled($gridField)
|
||||
{
|
||||
return array('Actions');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumnContent($gridField, $record, $columnName) {
|
||||
if(!$record->canEdit()) return;
|
||||
public function getColumnContent($gridField, $record, $columnName)
|
||||
{
|
||||
if (!$record->canEdit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field = "";
|
||||
|
||||
@ -67,14 +75,16 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getActions($gridField) {
|
||||
public function getActions($gridField)
|
||||
{
|
||||
return array('spam', 'approve');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||
{
|
||||
if ($actionName == 'spam') {
|
||||
$comment = Comment::get()->byID($arguments["RecordID"]);
|
||||
$comment->markSpam();
|
||||
|
@ -3,8 +3,8 @@
|
||||
/**
|
||||
* @package comments
|
||||
*/
|
||||
class CommentsGridFieldBulkAction extends GridFieldBulkActionHandler {
|
||||
|
||||
class CommentsGridFieldBulkAction extends GridFieldBulkActionHandler
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@ -12,7 +12,8 @@ class CommentsGridFieldBulkAction extends GridFieldBulkActionHandler {
|
||||
*
|
||||
* @package comments
|
||||
*/
|
||||
class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction {
|
||||
class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction
|
||||
{
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'spam',
|
||||
@ -25,7 +26,8 @@ class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction {
|
||||
);
|
||||
|
||||
|
||||
public function spam(SS_HTTPRequest $request) {
|
||||
public function spam(SS_HTTPRequest $request)
|
||||
{
|
||||
$ids = array();
|
||||
|
||||
foreach ($this->getRecords() as $record) {
|
||||
@ -44,7 +46,8 @@ class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction {
|
||||
}
|
||||
|
||||
|
||||
public function approve(SS_HTTPRequest $request) {
|
||||
public function approve(SS_HTTPRequest $request)
|
||||
{
|
||||
$ids = array();
|
||||
|
||||
foreach ($this->getRecords() as $record) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor {
|
||||
public function __construct($itemsPerPage = 25) {
|
||||
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
|
||||
{
|
||||
public function __construct($itemsPerPage = 25)
|
||||
{
|
||||
parent::__construct($itemsPerPage);
|
||||
|
||||
// $this->addComponent(new GridFieldExportButton());
|
||||
|
@ -4,7 +4,8 @@
|
||||
* @package comments
|
||||
*/
|
||||
|
||||
class CommentingController extends Controller {
|
||||
class CommentingController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'delete',
|
||||
@ -67,7 +68,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @param string $class
|
||||
*/
|
||||
public function setBaseClass($class) {
|
||||
public function setBaseClass($class)
|
||||
{
|
||||
$this->baseClass = $class;
|
||||
}
|
||||
|
||||
@ -76,7 +78,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseClass() {
|
||||
public function getBaseClass()
|
||||
{
|
||||
return $this->baseClass;
|
||||
}
|
||||
|
||||
@ -85,7 +88,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @param DataObject $record
|
||||
*/
|
||||
public function setOwnerRecord($record) {
|
||||
public function setOwnerRecord($record)
|
||||
{
|
||||
$this->ownerRecord = $record;
|
||||
}
|
||||
|
||||
@ -94,7 +98,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @return DataObject
|
||||
*/
|
||||
public function getOwnerRecord() {
|
||||
public function getOwnerRecord()
|
||||
{
|
||||
return $this->ownerRecord;
|
||||
}
|
||||
|
||||
@ -103,7 +108,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @param Controller $controller
|
||||
*/
|
||||
public function setOwnerController($controller) {
|
||||
public function setOwnerController($controller)
|
||||
{
|
||||
$this->ownerController = $controller;
|
||||
}
|
||||
|
||||
@ -112,7 +118,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @return Controller
|
||||
*/
|
||||
public function getOwnerController() {
|
||||
public function getOwnerController()
|
||||
{
|
||||
return $this->ownerController;
|
||||
}
|
||||
|
||||
@ -122,7 +129,8 @@ class CommentingController extends Controller {
|
||||
* @param string $key
|
||||
* @return mixed Result if the setting is available, or null otherwise
|
||||
*/
|
||||
public function getOption($key) {
|
||||
public function getOption($key)
|
||||
{
|
||||
// If possible use the current record
|
||||
if ($record = $this->getOwnerRecord()) {
|
||||
return $record->getCommentsOption($key);
|
||||
@ -142,7 +150,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function Link($action = '', $id = '', $other = '') {
|
||||
public function Link($action = '', $id = '', $other = '')
|
||||
{
|
||||
return Controller::join_links(Director::baseURL(), __CLASS__, $action, $id, $other);
|
||||
}
|
||||
|
||||
@ -151,7 +160,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @return HTMLText
|
||||
*/
|
||||
public function rss() {
|
||||
public function rss()
|
||||
{
|
||||
return $this->getFeed($this->request)->outputToBrowser();
|
||||
}
|
||||
|
||||
@ -167,7 +177,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @return RSSFeed
|
||||
*/
|
||||
public function getFeed(SS_HTTPRequest $request) {
|
||||
public function getFeed(SS_HTTPRequest $request)
|
||||
{
|
||||
$link = $this->Link('rss');
|
||||
$class = $request->param('ID');
|
||||
$id = $request->param('OtherID');
|
||||
@ -216,13 +227,18 @@ class CommentingController extends Controller {
|
||||
/**
|
||||
* Deletes a given {@link Comment} via the URL.
|
||||
*/
|
||||
public function delete() {
|
||||
public function delete()
|
||||
{
|
||||
$comment = $this->getComment();
|
||||
if(!$comment) return $this->httpError(404);
|
||||
if (!$comment) {
|
||||
return $this->httpError(404);
|
||||
}
|
||||
if (!$comment->canDelete()) {
|
||||
return Security::permissionFailure($this, 'You do not have permission to delete this comment');
|
||||
}
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
if (!$comment->getSecurityToken()->checkRequest($this->request)) {
|
||||
return $this->httpError(400);
|
||||
}
|
||||
|
||||
$comment->delete();
|
||||
|
||||
@ -234,13 +250,18 @@ class CommentingController extends Controller {
|
||||
/**
|
||||
* Marks a given {@link Comment} as spam. Removes the comment from display
|
||||
*/
|
||||
public function spam() {
|
||||
public function spam()
|
||||
{
|
||||
$comment = $this->getComment();
|
||||
if(!$comment) return $this->httpError(404);
|
||||
if (!$comment) {
|
||||
return $this->httpError(404);
|
||||
}
|
||||
if (!$comment->canEdit()) {
|
||||
return Security::permissionFailure($this, 'You do not have permission to edit this comment');
|
||||
}
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
if (!$comment->getSecurityToken()->checkRequest($this->request)) {
|
||||
return $this->httpError(400);
|
||||
}
|
||||
|
||||
$comment->markSpam();
|
||||
return $this->renderChangedCommentState($comment);
|
||||
@ -249,13 +270,18 @@ class CommentingController extends Controller {
|
||||
/**
|
||||
* Marks a given {@link Comment} as ham (not spam).
|
||||
*/
|
||||
public function ham() {
|
||||
public function ham()
|
||||
{
|
||||
$comment = $this->getComment();
|
||||
if(!$comment) return $this->httpError(404);
|
||||
if (!$comment) {
|
||||
return $this->httpError(404);
|
||||
}
|
||||
if (!$comment->canEdit()) {
|
||||
return Security::permissionFailure($this, 'You do not have permission to edit this comment');
|
||||
}
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
if (!$comment->getSecurityToken()->checkRequest($this->request)) {
|
||||
return $this->httpError(400);
|
||||
}
|
||||
|
||||
$comment->markApproved();
|
||||
return $this->renderChangedCommentState($comment);
|
||||
@ -264,13 +290,18 @@ class CommentingController extends Controller {
|
||||
/**
|
||||
* Marks a given {@link Comment} as approved.
|
||||
*/
|
||||
public function approve() {
|
||||
public function approve()
|
||||
{
|
||||
$comment = $this->getComment();
|
||||
if(!$comment) return $this->httpError(404);
|
||||
if (!$comment) {
|
||||
return $this->httpError(404);
|
||||
}
|
||||
if (!$comment->canEdit()) {
|
||||
return Security::permissionFailure($this, 'You do not have permission to approve this comment');
|
||||
}
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
if (!$comment->getSecurityToken()->checkRequest($this->request)) {
|
||||
return $this->httpError(400);
|
||||
}
|
||||
|
||||
$comment->markApproved();
|
||||
return $this->renderChangedCommentState($comment);
|
||||
@ -281,7 +312,8 @@ class CommentingController extends Controller {
|
||||
* are allowed to avoid phishing. If it's an AJAX request render the
|
||||
* comment in it's new state
|
||||
*/
|
||||
private function renderChangedCommentState($comment) {
|
||||
private function renderChangedCommentState($comment)
|
||||
{
|
||||
$referer = $this->request->getHeader('Referer');
|
||||
|
||||
// Render comment using AJAX
|
||||
@ -310,7 +342,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @return Comment|false
|
||||
*/
|
||||
public function getComment() {
|
||||
public function getComment()
|
||||
{
|
||||
$id = isset($this->urlParams['ID']) ? $this->urlParams['ID'] : false;
|
||||
|
||||
if ($id) {
|
||||
@ -330,7 +363,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @param Comment $comment
|
||||
*/
|
||||
public function ReplyForm($comment) {
|
||||
public function ReplyForm($comment)
|
||||
{
|
||||
// Enables multiple forms with different names to use the same handler
|
||||
$form = $this->CommentsForm();
|
||||
$form->setName('ReplyForm_'.$comment->ID);
|
||||
@ -355,7 +389,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @param SS_HTTPRequest $request
|
||||
*/
|
||||
public function reply(SS_HTTPRequest $request) {
|
||||
public function reply(SS_HTTPRequest $request)
|
||||
{
|
||||
// Extract parent comment from reply and build this way
|
||||
if ($parentID = $request->param('ParentCommentID')) {
|
||||
$comment = DataObject::get_by_id('Comment', $parentID, true);
|
||||
@ -371,7 +406,8 @@ class CommentingController extends Controller {
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
public function CommentsForm() {
|
||||
public function CommentsForm()
|
||||
{
|
||||
$usePreview = $this->getOption('use_preview');
|
||||
|
||||
$nameRequired = _t('CommentInterface.YOURNAME_MESSAGE_REQUIRED', 'Please enter your name');
|
||||
@ -502,7 +538,8 @@ class CommentingController extends Controller {
|
||||
* @param array $data
|
||||
* @param Form $form
|
||||
*/
|
||||
public function doPostComment($data, $form) {
|
||||
public function doPostComment($data, $form)
|
||||
{
|
||||
// Load class and parent from data
|
||||
if (isset($data['BaseClass'])) {
|
||||
$this->setBaseClass($data['BaseClass']);
|
||||
@ -510,7 +547,9 @@ class CommentingController extends Controller {
|
||||
if (isset($data['ParentID']) && ($class = $this->getBaseClass())) {
|
||||
$this->setOwnerRecord($class::get()->byID($data['ParentID']));
|
||||
}
|
||||
if(!$this->getOwnerRecord()) return $this->httpError(404);
|
||||
if (!$this->getOwnerRecord()) {
|
||||
return $this->httpError(404);
|
||||
}
|
||||
|
||||
// cache users data
|
||||
Cookie::set("CommentsForm_UserData", Convert::raw2json($data));
|
||||
@ -600,13 +639,15 @@ class CommentingController extends Controller {
|
||||
return $this->redirect(Controller::join_links($url, "#{$hash}"));
|
||||
}
|
||||
|
||||
public function doPreviewComment($data, $form) {
|
||||
public function doPreviewComment($data, $form)
|
||||
{
|
||||
$data['IsPreview'] = 1;
|
||||
|
||||
return $this->doPostComment($data, $form);
|
||||
}
|
||||
|
||||
public function redirectBack() {
|
||||
public function redirectBack()
|
||||
{
|
||||
// Don't cache the redirect back ever
|
||||
HTTP::set_cache_age(0);
|
||||
|
||||
@ -625,8 +666,12 @@ class CommentingController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
if(!$url) $url = $this->fallbackReturnURL;
|
||||
if(!$url) $url = Director::baseURL();
|
||||
if (!$url) {
|
||||
$url = $this->fallbackReturnURL;
|
||||
}
|
||||
if (!$url) {
|
||||
$url = Director::baseURL();
|
||||
}
|
||||
|
||||
// absolute redirection URLs not located on this site may cause phishing
|
||||
if (Director::is_site_url($url)) {
|
||||
@ -634,6 +679,5 @@ class CommentingController extends Controller {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
*
|
||||
* @package comments
|
||||
*/
|
||||
class CommentsExtension extends DataExtension {
|
||||
class CommentsExtension extends DataExtension
|
||||
{
|
||||
/**
|
||||
* Default configuration values
|
||||
*
|
||||
@ -78,7 +79,8 @@ class CommentsExtension extends DataExtension {
|
||||
* CMS configurable options should default to the config values, but respect
|
||||
* default values specified by the object
|
||||
*/
|
||||
public function populateDefaults() {
|
||||
public function populateDefaults()
|
||||
{
|
||||
$defaults = $this->owner->config()->defaults;
|
||||
|
||||
// Set if comments should be enabled by default
|
||||
@ -117,8 +119,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @param FieldList $fields
|
||||
*/
|
||||
public function updateSettingsFields(FieldList $fields) {
|
||||
|
||||
public function updateSettingsFields(FieldList $fields)
|
||||
{
|
||||
$options = FieldGroup::create()->setTitle(_t('CommentsExtension.COMMENTOPTIONS', 'Comments'));
|
||||
|
||||
// Check if enabled setting should be cms configurable
|
||||
@ -171,7 +173,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModerationRequired() {
|
||||
public function getModerationRequired()
|
||||
{
|
||||
if ($this->owner->getCommentsOption('require_moderation_cms')) {
|
||||
return $this->owner->getField('ModerationRequired');
|
||||
} elseif ($this->owner->getCommentsOption('require_moderation')) {
|
||||
@ -188,7 +191,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCommentsRequireLogin() {
|
||||
public function getCommentsRequireLogin()
|
||||
{
|
||||
if ($this->owner->getCommentsOption('require_login_cms')) {
|
||||
return (bool) $this->owner->getField('CommentsRequireLogin');
|
||||
} else {
|
||||
@ -202,7 +206,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return CommentList
|
||||
*/
|
||||
public function AllComments() {
|
||||
public function AllComments()
|
||||
{
|
||||
$order = $this->owner->getCommentsOption('order_comments_by');
|
||||
$comments = CommentList::create($this->ownerBaseClass)
|
||||
->forForeignID($this->owner->ID)
|
||||
@ -216,7 +221,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return CommentList
|
||||
*/
|
||||
public function AllVisibleComments() {
|
||||
public function AllVisibleComments()
|
||||
{
|
||||
$list = $this->AllComments();
|
||||
|
||||
// Filter spam comments for non-administrators if configured
|
||||
@ -241,7 +247,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return CommentList
|
||||
*/
|
||||
public function Comments() {
|
||||
public function Comments()
|
||||
{
|
||||
$list = $this->AllVisibleComments();
|
||||
|
||||
// If nesting comments, only show root level
|
||||
@ -259,7 +266,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return PaginatedList
|
||||
*/
|
||||
public function PagedComments() {
|
||||
public function PagedComments()
|
||||
{
|
||||
$list = $this->Comments();
|
||||
|
||||
// Add pagination
|
||||
@ -279,7 +287,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCommentsConfigured() {
|
||||
public function getCommentsConfigured()
|
||||
{
|
||||
Deprecation::notice('2.0', 'getCommentsConfigured is deprecated. Use getCommentsEnabled instead');
|
||||
return true; // by virtue of all classes with this extension being 'configured'
|
||||
}
|
||||
@ -289,9 +298,12 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCommentsEnabled() {
|
||||
public function getCommentsEnabled()
|
||||
{
|
||||
// Don't display comments form for pseudo-pages (such as the login form)
|
||||
if(!$this->owner->exists()) return false;
|
||||
if (!$this->owner->exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine which flag should be used to determine if this is enabled
|
||||
if ($this->owner->getCommentsOption('enabled_cms')) {
|
||||
@ -306,14 +318,16 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentHolderID() {
|
||||
public function getCommentHolderID()
|
||||
{
|
||||
return $this->owner->getCommentsOption('comments_holder_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*/
|
||||
public function getPostingRequiresPermission() {
|
||||
public function getPostingRequiresPermission()
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use getPostingRequiredPermission instead');
|
||||
return $this->getPostingRequiredPermission();
|
||||
}
|
||||
@ -323,11 +337,13 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return string|array Permission or list of permissions, if required
|
||||
*/
|
||||
public function getPostingRequiredPermission() {
|
||||
public function getPostingRequiredPermission()
|
||||
{
|
||||
return $this->owner->getCommentsOption('required_permission');
|
||||
}
|
||||
|
||||
public function canPost() {
|
||||
public function canPost()
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use canPostComment instead');
|
||||
return $this->canPostComment();
|
||||
}
|
||||
@ -339,21 +355,30 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canPostComment($member = null) {
|
||||
public function canPostComment($member = null)
|
||||
{
|
||||
// Deny if not enabled for this object
|
||||
if(!$this->owner->CommentsEnabled) return false;
|
||||
if (!$this->owner->CommentsEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if member is required
|
||||
$requireLogin = $this->owner->CommentsRequireLogin;
|
||||
if(!$requireLogin) return true;
|
||||
if (!$requireLogin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check member is logged in
|
||||
$member = $member ?: Member::currentUser();
|
||||
if(!$member) return false;
|
||||
if (!$member) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If member required check permissions
|
||||
$requiredPermission = $this->owner->PostingRequiredPermission;
|
||||
if($requiredPermission && !Permission::checkMember($member, $requiredPermission)) return false;
|
||||
if ($requiredPermission && !Permission::checkMember($member, $requiredPermission)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -365,15 +390,19 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canModerateComments($member = null) {
|
||||
public function canModerateComments($member = null)
|
||||
{
|
||||
// Deny if not enabled for this object
|
||||
if(!$this->owner->CommentsEnabled) return false;
|
||||
if (!$this->owner->CommentsEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fallback to can-edit
|
||||
return $this->owner->canEdit($member);
|
||||
}
|
||||
|
||||
public function getRssLink() {
|
||||
public function getRssLink()
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use getCommentRSSLink instead');
|
||||
return $this->getCommentRSSLink();
|
||||
}
|
||||
@ -383,11 +412,13 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentRSSLink() {
|
||||
public function getCommentRSSLink()
|
||||
{
|
||||
return Controller::join_links(Director::baseURL(), 'CommentingController/rss');
|
||||
}
|
||||
|
||||
public function getRssLinkPage() {
|
||||
public function getRssLinkPage()
|
||||
{
|
||||
Deprecation::notice('2.0', 'Use getCommentRSSLinkPage instead');
|
||||
return $this->getCommentRSSLinkPage();
|
||||
}
|
||||
@ -397,7 +428,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentRSSLinkPage() {
|
||||
public function getCommentRSSLinkPage()
|
||||
{
|
||||
return Controller::join_links(
|
||||
$this->getCommentRSSLink(), $this->ownerBaseClass, $this->owner->ID
|
||||
);
|
||||
@ -414,7 +446,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @see docs/en/Extending
|
||||
*/
|
||||
public function CommentsForm() {
|
||||
public function CommentsForm()
|
||||
{
|
||||
// Check if enabled
|
||||
$enabled = $this->getCommentsEnabled();
|
||||
if ($enabled && $this->owner->getCommentsOption('include_js')) {
|
||||
@ -452,7 +485,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function attachedToSiteTree() {
|
||||
public function attachedToSiteTree()
|
||||
{
|
||||
$class = $this->ownerBaseClass;
|
||||
|
||||
return (is_subclass_of($class, 'SiteTree')) || ($class == 'SiteTree');
|
||||
@ -461,7 +495,8 @@ class CommentsExtension extends DataExtension {
|
||||
/**
|
||||
* @deprecated 1.0 Please use {@link CommentsExtension->CommentsForm()}
|
||||
*/
|
||||
public function PageComments() {
|
||||
public function PageComments()
|
||||
{
|
||||
// This method is very commonly used, don't throw a warning just yet
|
||||
Deprecation::notice('1.0', '$PageComments is deprecated. Please use $CommentsForm');
|
||||
return $this->CommentsForm();
|
||||
@ -476,15 +511,20 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @return mixed Result if the setting is available, or null otherwise
|
||||
*/
|
||||
public function getCommentsOption($key) {
|
||||
public function getCommentsOption($key)
|
||||
{
|
||||
$settings = $this->owner // In case singleton is called on the extension directly
|
||||
? $this->owner->config()->comments
|
||||
: Config::inst()->get(__CLASS__, 'comments');
|
||||
$value = null;
|
||||
if(isset($settings[$key])) $value = $settings[$key];
|
||||
if (isset($settings[$key])) {
|
||||
$value = $settings[$key];
|
||||
}
|
||||
|
||||
// To allow other extensions to customise this option
|
||||
if($this->owner) $this->owner->extend('updateCommentsOption', $key, $value);
|
||||
if ($this->owner) {
|
||||
$this->owner->extend('updateCommentsOption', $key, $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -493,7 +533,8 @@ class CommentsExtension extends DataExtension {
|
||||
*
|
||||
* @param FieldList $fields
|
||||
*/
|
||||
protected function updateModerationFields(FieldList $fields) {
|
||||
protected function updateModerationFields(FieldList $fields)
|
||||
{
|
||||
Requirements::css(COMMENTS_DIR . '/css/cms.css');
|
||||
|
||||
$newComments = $this->owner->AllComments()->filter('Moderated', 0);
|
||||
@ -548,7 +589,8 @@ class CommentsExtension extends DataExtension {
|
||||
}
|
||||
}
|
||||
|
||||
public function updateCMSFields(FieldList $fields) {
|
||||
public function updateCMSFields(FieldList $fields)
|
||||
{
|
||||
// Disable moderation if not permitted
|
||||
if ($this->owner->canModerateComments()) {
|
||||
$this->updateModerationFields($fields);
|
||||
|
@ -20,7 +20,8 @@
|
||||
* @method Comment ParentComment() Parent comment this is a reply to
|
||||
* @package comments
|
||||
*/
|
||||
class Comment extends DataObject {
|
||||
class Comment extends DataObject
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@ -89,7 +90,8 @@ class Comment extends DataObject {
|
||||
'Author' => 'Author Member',
|
||||
);
|
||||
|
||||
public function onBeforeWrite() {
|
||||
public function onBeforeWrite()
|
||||
{
|
||||
parent::onBeforeWrite();
|
||||
|
||||
// Sanitize HTML, because its expected to be passed to the template unescaped later
|
||||
@ -101,7 +103,8 @@ class Comment extends DataObject {
|
||||
$this->updateDepth();
|
||||
}
|
||||
|
||||
public function onBeforeDelete() {
|
||||
public function onBeforeDelete()
|
||||
{
|
||||
parent::onBeforeDelete();
|
||||
|
||||
// Delete all children
|
||||
@ -113,14 +116,16 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* @return Comment_SecurityToken
|
||||
*/
|
||||
public function getSecurityToken() {
|
||||
public function getSecurityToken()
|
||||
{
|
||||
return Injector::inst()->createWithArgs('Comment_SecurityToken', array($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates the old {@link PageComment} objects to {@link Comment}
|
||||
*/
|
||||
public function requireDefaultRecords() {
|
||||
public function requireDefaultRecords()
|
||||
{
|
||||
parent::requireDefaultRecords();
|
||||
|
||||
if (DB::getConn()->hasTable('PageComment')) {
|
||||
@ -135,7 +140,9 @@ class Comment extends DataObject {
|
||||
// set the variables which have changed
|
||||
$comment->BaseClass = 'SiteTree';
|
||||
$comment->URL = (isset($pageComment['CommenterURL'])) ? $pageComment['CommenterURL'] : '';
|
||||
if((int) $pageComment['NeedsModeration'] == 0) $comment->Moderated = true;
|
||||
if ((int) $pageComment['NeedsModeration'] == 0) {
|
||||
$comment->Moderated = true;
|
||||
}
|
||||
|
||||
$comment->write();
|
||||
}
|
||||
@ -153,7 +160,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string link to this comment.
|
||||
*/
|
||||
public function Link($action = '') {
|
||||
public function Link($action = '')
|
||||
{
|
||||
if ($parent = $this->getParent()) {
|
||||
return $parent->Link($action) . '#' . $this->Permalink();
|
||||
}
|
||||
@ -165,7 +173,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function Permalink() {
|
||||
public function Permalink()
|
||||
{
|
||||
$prefix = $this->getOption('comment_permalink_prefix');
|
||||
return $prefix . $this->ID;
|
||||
}
|
||||
@ -177,7 +186,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fieldLabels($includerelations = true) {
|
||||
public function fieldLabels($includerelations = true)
|
||||
{
|
||||
$labels = parent::fieldLabels($includerelations);
|
||||
|
||||
$labels['Name'] = _t('Comment.NAME', 'Author Name');
|
||||
@ -199,15 +209,15 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return mixed Result if the setting is available, or null otherwise
|
||||
*/
|
||||
public function getOption($key) {
|
||||
public function getOption($key)
|
||||
{
|
||||
// If possible use the current record
|
||||
$record = $this->getParent();
|
||||
|
||||
if (!$record && $this->BaseClass) {
|
||||
// Otherwise a singleton of that record
|
||||
$record = singleton($this->BaseClass);
|
||||
}
|
||||
else if(!$record) {
|
||||
} elseif (!$record) {
|
||||
// Otherwise just use the default options
|
||||
$record = singleton('CommentsExtension');
|
||||
}
|
||||
@ -220,7 +230,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return DataObject
|
||||
*/
|
||||
public function getParent() {
|
||||
public function getParent()
|
||||
{
|
||||
return $this->BaseClass && $this->ParentID
|
||||
? DataObject::get_by_id($this->BaseClass, $this->ParentID, true)
|
||||
: null;
|
||||
@ -232,7 +243,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getParentTitle() {
|
||||
public function getParentTitle()
|
||||
{
|
||||
if ($parent = $this->getParent()) {
|
||||
return $parent->Title ?: ($parent->ClassName . ' #' . $parent->ID);
|
||||
}
|
||||
@ -243,11 +255,13 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getParentClassName() {
|
||||
public function getParentClassName()
|
||||
{
|
||||
return $this->BaseClass;
|
||||
}
|
||||
|
||||
public function castingHelper($field) {
|
||||
public function castingHelper($field)
|
||||
{
|
||||
// Safely escape the comment
|
||||
if ($field === 'EscapedComment') {
|
||||
return $this->AllowHtml ? 'HTMLText' : 'Text';
|
||||
@ -260,7 +274,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEscapedComment() {
|
||||
public function getEscapedComment()
|
||||
{
|
||||
return $this->Comment;
|
||||
}
|
||||
|
||||
@ -269,7 +284,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isPreview() {
|
||||
public function isPreview()
|
||||
{
|
||||
return !$this->exists();
|
||||
}
|
||||
|
||||
@ -280,7 +296,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -292,7 +309,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
$member = $this->getMember($member);
|
||||
|
||||
$extended = $this->extendedCan('canView', $member);
|
||||
@ -320,7 +338,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
$member = $this->getMember($member);
|
||||
|
||||
if (!$member) {
|
||||
@ -350,7 +369,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
$member = $this->getMember($member);
|
||||
|
||||
if (!$member) {
|
||||
@ -371,7 +391,8 @@ class Comment extends DataObject {
|
||||
* @param Member|int|null $member
|
||||
* @return Member|null
|
||||
*/
|
||||
protected function getMember($member = null) {
|
||||
protected function getMember($member = null)
|
||||
{
|
||||
if (!$member) {
|
||||
$member = Member::currentUser();
|
||||
}
|
||||
@ -388,7 +409,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorName() {
|
||||
public function getAuthorName()
|
||||
{
|
||||
if ($this->Name) {
|
||||
return $this->Name;
|
||||
} elseif ($author = $this->Author()) {
|
||||
@ -404,9 +426,14 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function actionLink($action, $member = null) {
|
||||
if(!$member) $member = Member::currentUser();
|
||||
if(!$member) return false;
|
||||
protected function actionLink($action, $member = null)
|
||||
{
|
||||
if (!$member) {
|
||||
$member = Member::currentUser();
|
||||
}
|
||||
if (!$member) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = Controller::join_links(
|
||||
Director::baseURL(),
|
||||
@ -427,7 +454,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function DeleteLink($member = null) {
|
||||
public function DeleteLink($member = null)
|
||||
{
|
||||
if ($this->canDelete($member)) {
|
||||
return $this->actionLink('delete', $member);
|
||||
}
|
||||
@ -440,7 +468,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function SpamLink($member = null) {
|
||||
public function SpamLink($member = null)
|
||||
{
|
||||
if ($this->canEdit($member) && !$this->IsSpam) {
|
||||
return $this->actionLink('spam', $member);
|
||||
}
|
||||
@ -453,7 +482,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function HamLink($member = null) {
|
||||
public function HamLink($member = null)
|
||||
{
|
||||
if ($this->canEdit($member) && $this->IsSpam) {
|
||||
return $this->actionLink('ham', $member);
|
||||
}
|
||||
@ -466,7 +496,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ApproveLink($member = null) {
|
||||
public function ApproveLink($member = null)
|
||||
{
|
||||
if ($this->canEdit($member) && !$this->Moderated) {
|
||||
return $this->actionLink('approve', $member);
|
||||
}
|
||||
@ -475,7 +506,8 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* Mark this comment as spam
|
||||
*/
|
||||
public function markSpam() {
|
||||
public function markSpam()
|
||||
{
|
||||
$this->IsSpam = true;
|
||||
$this->Moderated = true;
|
||||
$this->write();
|
||||
@ -485,7 +517,8 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* Mark this comment as approved
|
||||
*/
|
||||
public function markApproved() {
|
||||
public function markApproved()
|
||||
{
|
||||
$this->IsSpam = false;
|
||||
$this->Moderated = true;
|
||||
$this->write();
|
||||
@ -495,7 +528,8 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* Mark this comment as unapproved
|
||||
*/
|
||||
public function markUnapproved() {
|
||||
public function markUnapproved()
|
||||
{
|
||||
$this->Moderated = false;
|
||||
$this->write();
|
||||
$this->extend('afterMarkUnapproved');
|
||||
@ -504,7 +538,8 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function SpamClass() {
|
||||
public function SpamClass()
|
||||
{
|
||||
if ($this->IsSpam) {
|
||||
return 'spam';
|
||||
} elseif (!$this->Moderated) {
|
||||
@ -517,7 +552,8 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
public function getTitle()
|
||||
{
|
||||
$title = sprintf(_t('Comment.COMMENTBY', 'Comment by %s', 'Name'), $this->getAuthorName());
|
||||
|
||||
if ($parent = $this->getParent()) {
|
||||
@ -532,7 +568,8 @@ class Comment extends DataObject {
|
||||
/*
|
||||
* Modify the default fields shown to the user
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$commentField = $this->AllowHtml ? 'HtmlEditorField' : 'TextareaField';
|
||||
$fields = new FieldList(
|
||||
$this
|
||||
@ -610,7 +647,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function purifyHtml($dirtyHtml) {
|
||||
public function purifyHtml($dirtyHtml)
|
||||
{
|
||||
$purifier = $this->getHtmlPurifierService();
|
||||
return $purifier->purify($dirtyHtml);
|
||||
}
|
||||
@ -618,7 +656,8 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* @return HTMLPurifier (or anything with a "purify()" method)
|
||||
*/
|
||||
public function getHtmlPurifierService() {
|
||||
public function getHtmlPurifierService()
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$allowedElements = $this->getOption('html_allowed_elements');
|
||||
$config->set('HTML.AllowedElements', $allowedElements);
|
||||
@ -639,7 +678,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function Gravatar() {
|
||||
public function Gravatar()
|
||||
{
|
||||
$gravatar = '';
|
||||
$use_gravatar = $this->getOption('use_gravatar');
|
||||
if ($use_gravatar) {
|
||||
@ -658,7 +698,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getRepliesEnabled() {
|
||||
public function getRepliesEnabled()
|
||||
{
|
||||
// Check reply option
|
||||
if (!$this->getOption('nested_comments')) {
|
||||
return false;
|
||||
@ -675,7 +716,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return SS_List
|
||||
*/
|
||||
public function AllReplies() {
|
||||
public function AllReplies()
|
||||
{
|
||||
// No replies if disabled
|
||||
if (!$this->getRepliesEnabled()) {
|
||||
return new ArrayList();
|
||||
@ -697,7 +739,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return SS_List
|
||||
*/
|
||||
public function Replies() {
|
||||
public function Replies()
|
||||
{
|
||||
// No replies if disabled
|
||||
if (!$this->getRepliesEnabled()) {
|
||||
return new ArrayList();
|
||||
@ -729,7 +772,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return PaginatedList
|
||||
*/
|
||||
public function PagedReplies() {
|
||||
public function PagedReplies()
|
||||
{
|
||||
$list = $this->Replies();
|
||||
|
||||
// Add pagination
|
||||
@ -746,7 +790,8 @@ class Comment extends DataObject {
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
public function ReplyForm() {
|
||||
public function ReplyForm()
|
||||
{
|
||||
// Ensure replies are enabled
|
||||
if (!$this->getRepliesEnabled()) {
|
||||
return null;
|
||||
@ -770,7 +815,8 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* Refresh of this comment in the hierarchy
|
||||
*/
|
||||
public function updateDepth() {
|
||||
public function updateDepth()
|
||||
{
|
||||
$parent = $this->ParentComment();
|
||||
if ($parent && $parent->exists()) {
|
||||
$parent->updateDepth();
|
||||
@ -785,14 +831,16 @@ class Comment extends DataObject {
|
||||
/**
|
||||
* Provides the ability to generate cryptographically secure tokens for comment moderation
|
||||
*/
|
||||
class Comment_SecurityToken {
|
||||
class Comment_SecurityToken
|
||||
{
|
||||
|
||||
private $secret = null;
|
||||
|
||||
/**
|
||||
* @param Comment $comment Comment to generate this token for
|
||||
*/
|
||||
public function __construct($comment) {
|
||||
public function __construct($comment)
|
||||
{
|
||||
if (!$comment->SecretToken) {
|
||||
$comment->SecretToken = $this->generate();
|
||||
$comment->write();
|
||||
@ -807,7 +855,8 @@ class Comment_SecurityToken {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getToken($salt) {
|
||||
protected function getToken($salt)
|
||||
{
|
||||
return hash_pbkdf2('sha256', $this->secret, $salt, 1000, 30);
|
||||
}
|
||||
|
||||
@ -823,7 +872,8 @@ class Comment_SecurityToken {
|
||||
*
|
||||
* @return string Generated salt specific to this member
|
||||
*/
|
||||
protected function memberSalt($salt, $member) {
|
||||
protected function memberSalt($salt, $member)
|
||||
{
|
||||
// Fallback to salting with ID in case the member has not one set
|
||||
return $salt . ($member->Salt ?: $member->ID);
|
||||
}
|
||||
@ -834,7 +884,8 @@ class Comment_SecurityToken {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function addToUrl($url, $member) {
|
||||
public function addToUrl($url, $member)
|
||||
{
|
||||
$salt = $this->generate(15); // New random salt; Will be passed into url
|
||||
// Generate salt specific to this member
|
||||
$memberSalt = $this->memberSalt($salt, $member);
|
||||
@ -854,9 +905,12 @@ class Comment_SecurityToken {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkRequest($request) {
|
||||
public function checkRequest($request)
|
||||
{
|
||||
$member = Member::currentUser();
|
||||
if(!$member) return false;
|
||||
if (!$member) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$salt = $request->getVar('s');
|
||||
$memberSalt = $this->memberSalt($salt, $member);
|
||||
@ -874,10 +928,13 @@ class Comment_SecurityToken {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generate($length = null) {
|
||||
protected function generate($length = null)
|
||||
{
|
||||
$generator = new RandomGenerator();
|
||||
$result = $generator->randomToken('sha256');
|
||||
if($length !== null) return substr($result, 0, $length);
|
||||
if ($length !== null) {
|
||||
return substr($result, 0, $length);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -7,18 +7,21 @@
|
||||
*
|
||||
* @author dmooyman
|
||||
*/
|
||||
class CommentList extends HasManyList {
|
||||
class CommentList extends HasManyList
|
||||
{
|
||||
|
||||
/**
|
||||
* Retrieve the name of the class this relation is filtered by
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getForeignClass() {
|
||||
public function getForeignClass()
|
||||
{
|
||||
return $this->dataQuery->getQueryParam('Foreign.Class');
|
||||
}
|
||||
|
||||
public function __construct($parentClassName) {
|
||||
public function __construct($parentClassName)
|
||||
{
|
||||
parent::__construct('Comment', 'ParentID');
|
||||
|
||||
|
||||
@ -38,7 +41,8 @@ class CommentList extends HasManyList {
|
||||
*
|
||||
* @param Comment $item The comment to be added
|
||||
*/
|
||||
public function add($item) {
|
||||
public function add($item)
|
||||
{
|
||||
// Check item given
|
||||
if (is_numeric($item)) {
|
||||
$item = Comment::get()->byID($item);
|
||||
@ -62,7 +66,8 @@ class CommentList extends HasManyList {
|
||||
*
|
||||
* @param Comment $item The Comment to be removed
|
||||
*/
|
||||
public function remove($item) {
|
||||
public function remove($item)
|
||||
{
|
||||
// Check item given
|
||||
if (is_numeric($item)) {
|
||||
$item = Comment::get()->byID($item);
|
||||
@ -75,7 +80,9 @@ class CommentList extends HasManyList {
|
||||
// Don't remove item with unrelated class key
|
||||
$foreignClass = $this->getForeignClass();
|
||||
$classNames = ClassInfo::subclassesFor($foreignClass);
|
||||
if(!in_array($item->BaseClass, $classNames)) return;
|
||||
if (!in_array($item->BaseClass, $classNames)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't remove item which doesn't belong to this list
|
||||
$foreignID = $this->getForeignID();
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
class CommentAdminTest extends SapphireTest {
|
||||
public function testProvidePermissions() {
|
||||
class CommentAdminTest extends SapphireTest
|
||||
{
|
||||
public function testProvidePermissions()
|
||||
{
|
||||
$commentAdmin = new CommentAdmin();
|
||||
$locale = i18n::get_locale();
|
||||
|
||||
@ -26,7 +28,8 @@ class CommentAdminTest extends SapphireTest {
|
||||
$this->assertEquals($expected, $commentAdmin->providePermissions());
|
||||
}
|
||||
|
||||
public function testGetEditForm() {
|
||||
public function testGetEditForm()
|
||||
{
|
||||
$commentAdmin = new CommentAdmin();
|
||||
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
||||
$form = $commentAdmin->getEditForm();
|
||||
@ -38,12 +41,15 @@ class CommentAdminTest extends SapphireTest {
|
||||
);
|
||||
$this->assertEquals($expected, $names);
|
||||
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
|
||||
$form = $commentAdmin->getEditForm();
|
||||
}
|
||||
|
||||
private function getFormFieldNames($form) {
|
||||
private function getFormFieldNames($form)
|
||||
{
|
||||
$result = array();
|
||||
$fields = $form->Fields();
|
||||
$tab = $fields->findOrMakeTab('Root');
|
||||
@ -53,5 +59,4 @@ class CommentAdminTest extends SapphireTest {
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class CommentListTest extends FunctionalTest {
|
||||
class CommentListTest extends FunctionalTest
|
||||
{
|
||||
|
||||
public static $fixture_file = 'comments/tests/CommentsTest.yml';
|
||||
|
||||
@ -10,7 +11,8 @@ class CommentListTest extends FunctionalTest {
|
||||
'CommentableItemDisabled'
|
||||
);
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Config::nest();
|
||||
|
||||
@ -34,12 +36,14 @@ class CommentListTest extends FunctionalTest {
|
||||
));
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
Config::unnest();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testGetForeignClass() {
|
||||
public function testGetForeignClass()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
|
||||
// This is the class the Comments are related to
|
||||
@ -47,7 +51,8 @@ class CommentListTest extends FunctionalTest {
|
||||
$item->Comments()->getForeignClass());
|
||||
}
|
||||
|
||||
public function testAddNonComment() {
|
||||
public function testAddNonComment()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$comments = $item->Comments();
|
||||
$this->assertEquals(4, $comments->count());
|
||||
@ -63,7 +68,8 @@ class CommentListTest extends FunctionalTest {
|
||||
}
|
||||
}
|
||||
|
||||
public function testAddComment() {
|
||||
public function testAddComment()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$firstComment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$comments = $item->Comments();//->sort('Created');
|
||||
@ -99,7 +105,8 @@ class CommentListTest extends FunctionalTest {
|
||||
$list->add($newComment);
|
||||
}
|
||||
|
||||
public function testRemoveComment() {
|
||||
public function testRemoveComment()
|
||||
{
|
||||
// remove by comment
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$this->assertEquals(4, $item->Comments()->count());
|
||||
@ -114,7 +121,8 @@ class CommentListTest extends FunctionalTest {
|
||||
$this->assertEquals(2, $item->Comments()->count());
|
||||
}
|
||||
|
||||
public function testRemoveNonComment() {
|
||||
public function testRemoveNonComment()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$this->assertEquals(4, $item->Comments()->count());
|
||||
$comments = $item->Comments();
|
||||
@ -134,5 +142,4 @@ class CommentListTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,20 @@
|
||||
<?php
|
||||
|
||||
class CommentTestHelper {
|
||||
class CommentTestHelper
|
||||
{
|
||||
/*
|
||||
This only works if the last section is not a field group, e.g. a Comments
|
||||
field group inside of a Root.Settings tab will not work
|
||||
*/
|
||||
public static function assertFieldsForTab($context, $tabName, $expected, $fields) {
|
||||
public static function assertFieldsForTab($context, $tabName, $expected, $fields)
|
||||
{
|
||||
$tab = $fields->findOrMakeTab($tabName);
|
||||
$fields = $tab->FieldList();
|
||||
CommentTestHelper::assertFieldNames($context, $expected, $fields);
|
||||
}
|
||||
|
||||
public static function assertFieldNames($context, $expected, $fields) {
|
||||
public static function assertFieldNames($context, $expected, $fields)
|
||||
{
|
||||
$actual = array();
|
||||
foreach ($fields as $field) {
|
||||
if (get_class($field) == 'FieldGroup') {
|
||||
|
@ -4,7 +4,8 @@
|
||||
* @package comments
|
||||
* @subpackage tests
|
||||
*/
|
||||
class CommentingControllerTest extends FunctionalTest {
|
||||
class CommentingControllerTest extends FunctionalTest
|
||||
{
|
||||
|
||||
public static $fixture_file = 'CommentsTest.yml';
|
||||
|
||||
@ -14,7 +15,8 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
|
||||
protected $securityEnabled;
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
if ($this->securityEnabled) {
|
||||
SecurityToken::enable();
|
||||
} else {
|
||||
@ -23,12 +25,14 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->securityEnabled = SecurityToken::is_enabled();
|
||||
}
|
||||
|
||||
public function testApprove() {
|
||||
public function testApprove()
|
||||
{
|
||||
SecurityToken::disable();
|
||||
|
||||
// mark a comment as spam then approve it
|
||||
@ -49,10 +53,10 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
// try and approve a non existent comment
|
||||
$response = $this->get('CommentingController/approve/100000');
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
|
||||
}
|
||||
|
||||
public function testSetGetOwnerController() {
|
||||
public function testSetGetOwnerController()
|
||||
{
|
||||
$commController = new CommentingController();
|
||||
$commController->setOwnerController(Controller::curr());
|
||||
$this->assertEquals(Controller::curr(), $commController->getOwnerController());
|
||||
@ -60,7 +64,8 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
$this->assertNull($commController->getOwnerController());
|
||||
}
|
||||
|
||||
public function testHam() {
|
||||
public function testHam()
|
||||
{
|
||||
SecurityToken::disable();
|
||||
|
||||
// mark a comment as spam then ham it
|
||||
@ -81,10 +86,10 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
// try and ham a non existent comment
|
||||
$response = $this->get('CommentingController/ham/100000');
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
|
||||
}
|
||||
|
||||
public function testSpam() {
|
||||
public function testSpam()
|
||||
{
|
||||
// mark a comment as approved then spam it
|
||||
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
@ -103,10 +108,10 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
// try and spam a non existent comment
|
||||
$response = $this->get('CommentingController/spam/100000');
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
|
||||
}
|
||||
|
||||
public function testRSS() {
|
||||
public function testRSS()
|
||||
{
|
||||
// Delete the newly added children of firstComA so as not to have to recalculate values below
|
||||
$this->objFromFixture('Comment', 'firstComAChild1')->delete();
|
||||
$this->objFromFixture('Comment', 'firstComAChild2')->delete();
|
||||
@ -177,7 +182,8 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
}
|
||||
*/
|
||||
|
||||
public function testCommentsFormUsePreview() {
|
||||
public function testCommentsFormUsePreview()
|
||||
{
|
||||
// test with preview on
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'use_preview' => true
|
||||
@ -208,7 +214,8 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
CommentTestHelper::assertFieldNames($this, $expected, $commentsFields);
|
||||
}
|
||||
|
||||
public function testCommentsForm() {
|
||||
public function testCommentsForm()
|
||||
{
|
||||
// Delete the newly added children of firstComA so as not to change this test
|
||||
$this->objFromFixture('Comment', 'firstComAChild1')->delete();
|
||||
$this->objFromFixture('Comment', 'firstComAChild2')->delete();
|
||||
@ -268,7 +275,5 @@ class CommentingControllerTest extends FunctionalTest {
|
||||
'BaseClass' => 'CommentableItem',
|
||||
'ParentCommentID' => $parentComment->ID
|
||||
)), $parentComment->ChildComments());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
<?php
|
||||
|
||||
class CommentingTest extends SapphireTest {
|
||||
class CommentingTest extends SapphireTest
|
||||
{
|
||||
|
||||
public function setUpOnce() {
|
||||
public function setUpOnce()
|
||||
{
|
||||
parent::setUpOnce();
|
||||
}
|
||||
|
||||
public function testDeprecatedMethods() {
|
||||
public function testDeprecatedMethods()
|
||||
{
|
||||
$methods = array('add', 'remove', 'has_commenting');
|
||||
foreach ($methods as $methodName) {
|
||||
try {
|
||||
@ -20,7 +23,8 @@ class CommentingTest extends SapphireTest {
|
||||
}
|
||||
|
||||
|
||||
public function test_set_config_value() {
|
||||
public function test_set_config_value()
|
||||
{
|
||||
// public static function set_config_value($class, $key, $value = false) {
|
||||
Commenting::set_config_value(
|
||||
'CommentableItem',
|
||||
@ -55,7 +59,8 @@ class CommentingTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function test_get_config_value() {
|
||||
public function test_get_config_value()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments',
|
||||
array(
|
||||
'comments_holder_id' => 'commentable_item'
|
||||
@ -84,7 +89,8 @@ class CommentingTest extends SapphireTest {
|
||||
Commenting::get_config_value('Member', 'comments_holder_id');
|
||||
}
|
||||
|
||||
public function test_config_value_equals() {
|
||||
public function test_config_value_equals()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments',
|
||||
array(
|
||||
'comments_holder_id' => 'some_value'
|
||||
@ -108,7 +114,8 @@ class CommentingTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function test_add() {
|
||||
public function test_add()
|
||||
{
|
||||
Commenting::add('Member', array('comments_holder_id' => 'test_add_value'));
|
||||
|
||||
$config = Config::inst()->get(
|
||||
@ -136,13 +143,14 @@ class CommentingTest extends SapphireTest {
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException', "\$settings needs to be an array or null");
|
||||
Commenting::add('Member', 'illegal format, not an array');
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function test_can_member_post() {
|
||||
public function test_can_member_post()
|
||||
{
|
||||
// logout
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
|
||||
Config::inst()->update('CommentableItem', 'comments',
|
||||
array(
|
||||
@ -169,5 +177,4 @@ class CommentingTest extends SapphireTest {
|
||||
|
||||
$this->assertTrue(Commenting::can_member_post('CommentableItem'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class CommentsExtensionTest extends SapphireTest {
|
||||
class CommentsExtensionTest extends SapphireTest
|
||||
{
|
||||
|
||||
public static $fixture_file = 'comments/tests/CommentsTest.yml';
|
||||
|
||||
@ -10,7 +11,8 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
'CommentableItemDisabled'
|
||||
);
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Config::nest();
|
||||
|
||||
@ -38,20 +40,24 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
));
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
Config::unnest();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testPopulateDefaults() {
|
||||
public function testPopulateDefaults()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testUpdateSettingsFields() {
|
||||
public function testUpdateSettingsFields()
|
||||
{
|
||||
$this->markTestSkipped('This needs SiteTree installed');
|
||||
}
|
||||
|
||||
public function testGetModerationRequired() {
|
||||
public function testGetModerationRequired()
|
||||
{
|
||||
|
||||
// the 3 options take precedence in this order, executed if true
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
@ -92,7 +98,8 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
$this->assertEquals('None', $item->getModerationRequired());
|
||||
}
|
||||
|
||||
public function testGetCommentsRequireLogin() {
|
||||
public function testGetCommentsRequireLogin()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'require_login_cms' => true
|
||||
));
|
||||
@ -115,26 +122,30 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
'require_login' => true
|
||||
));
|
||||
$this->assertTrue($item->getCommentsRequireLogin());
|
||||
|
||||
}
|
||||
|
||||
public function testAllComments() {
|
||||
public function testAllComments()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testAllVisibleComments() {
|
||||
public function testAllVisibleComments()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testComments() {
|
||||
public function testComments()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testGetCommentsEnabled() {
|
||||
public function testGetCommentsEnabled()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testGetCommentHolderID() {
|
||||
public function testGetCommentHolderID()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'comments_holder_id' => 'commentid_test1',
|
||||
@ -148,30 +159,35 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
}
|
||||
|
||||
|
||||
public function testGetPostingRequiredPermission() {
|
||||
public function testGetPostingRequiredPermission()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testCanModerateComments() {
|
||||
public function testCanModerateComments()
|
||||
{
|
||||
// ensure nobody logged in
|
||||
if(Member::currentUser()) { Member::currentUser()->logOut(); }
|
||||
if (Member::currentUser()) {
|
||||
Member::currentUser()->logOut();
|
||||
}
|
||||
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$this->assertFalse($item->canModerateComments());
|
||||
|
||||
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
||||
$this->assertTrue($item->canModerateComments());
|
||||
|
||||
}
|
||||
|
||||
public function testGetCommentRSSLink() {
|
||||
public function testGetCommentRSSLink()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$link = $item->getCommentRSSLink();
|
||||
$this->assertEquals('/CommentingController/rss', $link);
|
||||
}
|
||||
|
||||
|
||||
public function testGetCommentRSSLinkPage() {
|
||||
public function testGetCommentRSSLinkPage()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$page = $item->getCommentRSSLinkPage();
|
||||
$this->assertEquals(
|
||||
@ -180,7 +196,8 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testCommentsForm() {
|
||||
public function testCommentsForm()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'include_js' => false
|
||||
)
|
||||
@ -257,11 +274,13 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testAttachedToSiteTree() {
|
||||
public function testAttachedToSiteTree()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testPagedComments() {
|
||||
public function testPagedComments()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
// Ensure Created times are set, as order not guaranteed if all set to 0
|
||||
$comments = $item->PagedComments()->sort('ID');
|
||||
@ -299,15 +318,18 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
$this->assertEquals(4, sizeof($results));
|
||||
}
|
||||
|
||||
public function testGetCommentsOption() {
|
||||
public function testGetCommentsOption()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testUpdateModerationFields() {
|
||||
public function testUpdateModerationFields()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testUpdateCMSFields() {
|
||||
public function testUpdateCMSFields()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'require_login_cms' => false
|
||||
)
|
||||
@ -380,7 +402,8 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
|
||||
|
||||
|
||||
public function testDeprecatedMethods() {
|
||||
public function testDeprecatedMethods()
|
||||
{
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$methodNames = array(
|
||||
'getRssLinkPage',
|
||||
@ -403,7 +426,5 @@ class CommentsExtensionTest extends SapphireTest {
|
||||
}
|
||||
|
||||
// ooh, $this->setExpectedException('ExpectedException', 'Expected Message');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class CommentsGridFieldActionTest extends SapphireTest {
|
||||
class CommentsGridFieldActionTest extends SapphireTest
|
||||
{
|
||||
|
||||
/** @var ArrayList */
|
||||
protected $list;
|
||||
@ -11,7 +12,8 @@ class CommentsGridFieldActionTest extends SapphireTest {
|
||||
/** @var Form */
|
||||
protected $form;
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->list = new DataList('GridFieldAction_Delete_Team');
|
||||
$config = CommentsGridFieldConfig::create()->addComponent(new GridFieldDeleteAction());
|
||||
@ -19,7 +21,8 @@ class CommentsGridFieldActionTest extends SapphireTest {
|
||||
$this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList());
|
||||
}
|
||||
|
||||
public function testAugmentColumns() {
|
||||
public function testAugmentColumns()
|
||||
{
|
||||
$action = new CommentsGridFieldAction();
|
||||
|
||||
// an entry called 'Actions' is added to the columns array
|
||||
@ -34,14 +37,16 @@ class CommentsGridFieldActionTest extends SapphireTest {
|
||||
$this->assertEquals($expected, $columns);
|
||||
}
|
||||
|
||||
public function testGetColumnAttributes() {
|
||||
public function testGetColumnAttributes()
|
||||
{
|
||||
$action = new CommentsGridFieldAction();
|
||||
$record = new Comment();
|
||||
$attrs = $action->getColumnAttributes($this->gridField, $record, 'Comment');
|
||||
$this->assertEquals(array('class' => 'col-buttons'), $attrs);
|
||||
}
|
||||
|
||||
public function testGetColumnMetadata() {
|
||||
public function testGetColumnMetadata()
|
||||
{
|
||||
$action = new CommentsGridFieldAction();
|
||||
$result = $action->getColumnMetadata($this->gridField, 'Actions');
|
||||
$this->assertEquals(array('title' => ''), $result);
|
||||
@ -49,13 +54,15 @@ class CommentsGridFieldActionTest extends SapphireTest {
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testGetColumnsHandled() {
|
||||
public function testGetColumnsHandled()
|
||||
{
|
||||
$action = new CommentsGridFieldAction();
|
||||
$result = $action->getColumnsHandled($this->gridField);
|
||||
$this->assertEquals(array('Actions'), $result);
|
||||
}
|
||||
|
||||
public function testGetColumnContent() {
|
||||
public function testGetColumnContent()
|
||||
{
|
||||
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
||||
$action = new CommentsGridFieldAction();
|
||||
$record = new Comment();
|
||||
@ -89,14 +96,16 @@ class CommentsGridFieldActionTest extends SapphireTest {
|
||||
$this->assertContains($spamAction, $html);
|
||||
}
|
||||
|
||||
public function testGetActions() {
|
||||
public function testGetActions()
|
||||
{
|
||||
$action = new CommentsGridFieldAction();
|
||||
$result = $action->getActions($this->gridField);
|
||||
$this->assertEquals(array('spam', 'approve'), $result);
|
||||
}
|
||||
|
||||
|
||||
public function testHandleAction() {
|
||||
public function testHandleAction()
|
||||
{
|
||||
$action = new CommentsGridFieldAction();
|
||||
$record = new Comment();
|
||||
$record->Name = 'Name of commeter';
|
||||
@ -129,5 +138,4 @@ class CommentsGridFieldActionTest extends SapphireTest {
|
||||
|
||||
error_log(Controller::curr()->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
<?php
|
||||
|
||||
class CommentsGridFieldBulkActionTest extends SapphireTest {
|
||||
public function testSpam() {
|
||||
class CommentsGridFieldBulkActionTest extends SapphireTest
|
||||
{
|
||||
public function testSpam()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testApprove() {
|
||||
public function testApprove()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
class CommentsGridFieldConfigTest extends SapphireTest {
|
||||
public function test__construct() {
|
||||
class CommentsGridFieldConfigTest extends SapphireTest
|
||||
{
|
||||
public function test__construct()
|
||||
{
|
||||
$config = new CommentsGridFieldConfigTest();
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
class CommentsGridFieldTest extends SapphireTest {
|
||||
public function testNewRow() {
|
||||
class CommentsGridFieldTest extends SapphireTest
|
||||
{
|
||||
public function testNewRow()
|
||||
{
|
||||
$gridfield = new CommentsGridField('testfield', 'testfield');
|
||||
// protected function newRow($total, $index, $record, $attributes, $content) {
|
||||
$comment = new Comment();
|
||||
@ -14,9 +16,7 @@ class CommentsGridFieldTest extends SapphireTest {
|
||||
$class = new ReflectionClass($gridfield);
|
||||
$method = $class->getMethod('newRow');
|
||||
$method->setAccessible(true);
|
||||
}
|
||||
|
||||
catch (ReflectionException $e) {
|
||||
} catch (ReflectionException $e) {
|
||||
$this->fail($e->getMessage());
|
||||
}
|
||||
|
||||
@ -33,8 +33,5 @@ class CommentsGridFieldTest extends SapphireTest {
|
||||
$params = array(1, 1, $comment, $attr, $comment->Comment);
|
||||
$newRow = $method->invokeArgs($gridfield, $params);
|
||||
$this->assertEquals('<tr class="cssClass spam">This is a comment</tr>', $newRow);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* @package comments
|
||||
*/
|
||||
class CommentsTest extends FunctionalTest {
|
||||
class CommentsTest extends FunctionalTest
|
||||
{
|
||||
|
||||
public static $fixture_file = 'comments/tests/CommentsTest.yml';
|
||||
|
||||
@ -13,7 +14,8 @@ class CommentsTest extends FunctionalTest {
|
||||
'CommentableItemDisabled'
|
||||
);
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Config::nest();
|
||||
|
||||
@ -37,12 +39,14 @@ class CommentsTest extends FunctionalTest {
|
||||
));
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
Config::unnest();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testCommentsList() {
|
||||
public function testCommentsList()
|
||||
{
|
||||
// comments don't require moderation so unmoderated comments can be
|
||||
// shown but not spam posts
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
@ -95,7 +99,9 @@ class CommentsTest extends FunctionalTest {
|
||||
'frontend_moderation' => false,
|
||||
'frontend_spam' => true,
|
||||
));
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$this->assertEquals(1, $item->Comments()->Count());
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
@ -108,7 +114,9 @@ class CommentsTest extends FunctionalTest {
|
||||
'frontend_moderation' => true,
|
||||
'frontend_spam' => true,
|
||||
));
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$this->assertEquals(1, $item->Comments()->Count());
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
@ -118,7 +126,8 @@ class CommentsTest extends FunctionalTest {
|
||||
/**
|
||||
* Test moderation options configured via the CMS
|
||||
*/
|
||||
public function testCommentCMSModerationList() {
|
||||
public function testCommentCMSModerationList()
|
||||
{
|
||||
// comments don't require moderation so unmoderated comments can be
|
||||
// shown but not spam posts
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
@ -159,7 +168,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals(2, $item->Comments()->Count());
|
||||
}
|
||||
|
||||
public function testCanPostComment() {
|
||||
public function testCanPostComment()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'require_login' => false,
|
||||
'require_login_cms' => false,
|
||||
@ -169,7 +179,9 @@ class CommentsTest extends FunctionalTest {
|
||||
$item2 = $this->objFromFixture('CommentableItem', 'second');
|
||||
|
||||
// Test restriction free commenting
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$this->assertFalse($item->CommentsRequireLogin);
|
||||
$this->assertTrue($item->canPostComment());
|
||||
|
||||
@ -192,7 +204,9 @@ class CommentsTest extends FunctionalTest {
|
||||
'required_permission' => false,
|
||||
));
|
||||
$this->assertTrue($item->CommentsRequireLogin);
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$this->assertFalse($item->canPostComment());
|
||||
$this->logInWithPermission('ANY_PERMISSION');
|
||||
$this->assertTrue($item->canPostComment());
|
||||
@ -204,7 +218,9 @@ class CommentsTest extends FunctionalTest {
|
||||
));
|
||||
$this->assertFalse($item->CommentsRequireLogin);
|
||||
$this->assertTrue($item2->CommentsRequireLogin);
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$this->assertTrue($item->canPostComment());
|
||||
$this->assertFalse($item2->canPostComment());
|
||||
|
||||
@ -212,11 +228,13 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->logInWithPermission('ANY_PERMISSION');
|
||||
$this->assertTrue($item->canPostComment());
|
||||
$this->assertTrue($item2->canPostComment());
|
||||
|
||||
}
|
||||
public function testDeleteComment() {
|
||||
public function testDeleteComment()
|
||||
{
|
||||
// Test anonymous user
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$commentID = $comment->ID;
|
||||
$this->assertNull($comment->DeleteLink(), 'No permission to see delete link');
|
||||
@ -253,9 +271,12 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertFalse($check && $check->exists());
|
||||
}
|
||||
|
||||
public function testSpamComment() {
|
||||
public function testSpamComment()
|
||||
{
|
||||
// Test anonymous user
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$commentID = $comment->ID;
|
||||
$this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link');
|
||||
@ -295,9 +316,12 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertNull($check->SpamLink());
|
||||
}
|
||||
|
||||
public function testHamComment() {
|
||||
public function testHamComment()
|
||||
{
|
||||
// Test anonymous user
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$comment = $this->objFromFixture('Comment', 'secondComC');
|
||||
$commentID = $comment->ID;
|
||||
$this->assertNull($comment->HamLink(), 'No permission to see mark as ham link');
|
||||
@ -337,9 +361,12 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertNull($check->HamLink());
|
||||
}
|
||||
|
||||
public function testApproveComment() {
|
||||
public function testApproveComment()
|
||||
{
|
||||
// Test anonymous user
|
||||
if($member = Member::currentUser()) $member->logOut();
|
||||
if ($member = Member::currentUser()) {
|
||||
$member->logOut();
|
||||
}
|
||||
$comment = $this->objFromFixture('Comment', 'secondComB');
|
||||
$commentID = $comment->ID;
|
||||
$this->assertNull($comment->ApproveLink(), 'No permission to see approve link');
|
||||
@ -379,7 +406,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertNull($check->ApproveLink());
|
||||
}
|
||||
|
||||
public function testCommenterURLWrite() {
|
||||
public function testCommenterURLWrite()
|
||||
{
|
||||
$comment = new Comment();
|
||||
// We only care about the CommenterURL, so only set that
|
||||
// Check a http and https URL. Add more test urls here as needed.
|
||||
@ -397,7 +425,8 @@ class CommentsTest extends FunctionalTest {
|
||||
}
|
||||
}
|
||||
|
||||
public function testSanitizesWithAllowHtml() {
|
||||
public function testSanitizesWithAllowHtml()
|
||||
{
|
||||
if (!class_exists('HTMLPurifier')) {
|
||||
$this->markTestSkipped('HTMLPurifier class not found');
|
||||
return;
|
||||
@ -435,7 +464,8 @@ class CommentsTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testDefaultTemplateRendersHtmlWithAllowHtml() {
|
||||
public function testDefaultTemplateRendersHtmlWithAllowHtml()
|
||||
{
|
||||
if (!class_exists('HTMLPurifier')) {
|
||||
$this->markTestSkipped('HTMLPurifier class not found');
|
||||
}
|
||||
@ -468,14 +498,14 @@ class CommentsTest extends FunctionalTest {
|
||||
'<p>my comment</p>',
|
||||
$html
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests whether comments are enabled or disabled by default
|
||||
*/
|
||||
public function testDefaultEnabled() {
|
||||
public function testDefaultEnabled()
|
||||
{
|
||||
// Ensure values are set via cms (not via config)
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'enabled_cms' => true,
|
||||
@ -527,7 +557,8 @@ class CommentsTest extends FunctionalTest {
|
||||
/*
|
||||
When a parent comment is deleted, remove the children
|
||||
*/
|
||||
public function testOnBeforeDelete() {
|
||||
public function testOnBeforeDelete()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
|
||||
$child = new Comment();
|
||||
@ -547,11 +578,13 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertFalse(DataObject::get_by_id('Comment', $childCommentID));
|
||||
}
|
||||
|
||||
public function testRequireDefaultRecords() {
|
||||
public function testRequireDefaultRecords()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testLink() {
|
||||
public function testLink()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'thirdComD');
|
||||
$this->assertEquals('CommentableItem_Controller#comment-'.$comment->ID,
|
||||
$comment->Link());
|
||||
@ -563,7 +596,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals('', $comment->Link());
|
||||
}
|
||||
|
||||
public function testPermalink() {
|
||||
public function testPermalink()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'thirdComD');
|
||||
$this->assertEquals('comment-' . $comment->ID, $comment->Permalink());
|
||||
}
|
||||
@ -571,7 +605,8 @@ class CommentsTest extends FunctionalTest {
|
||||
/*
|
||||
Test field labels in 2 languages
|
||||
*/
|
||||
public function testFieldLabels() {
|
||||
public function testFieldLabels()
|
||||
{
|
||||
$locale = i18n::get_locale();
|
||||
i18n::set_locale('fr');
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
@ -619,18 +654,21 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals($expected, $labels);
|
||||
}
|
||||
|
||||
public function testGetOption() {
|
||||
public function testGetOption()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testGetParent() {
|
||||
public function testGetParent()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$item = $this->objFromFixture('CommentableItem', 'first');
|
||||
$parent = $comment->getParent();
|
||||
$this->assertEquals($item, $parent);
|
||||
}
|
||||
|
||||
public function testGetParentTitle() {
|
||||
public function testGetParentTitle()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$title = $comment->getParentTitle();
|
||||
$this->assertEquals('First', $title);
|
||||
@ -641,21 +679,25 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals('', $comment->getParentTitle());
|
||||
}
|
||||
|
||||
public function testGetParentClassName() {
|
||||
public function testGetParentClassName()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$className = $comment->getParentClassName();
|
||||
$this->assertEquals('CommentableItem', $className);
|
||||
}
|
||||
|
||||
public function testCastingHelper() {
|
||||
public function testCastingHelper()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testGetEscapedComment() {
|
||||
public function testGetEscapedComment()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testIsPreview() {
|
||||
public function testIsPreview()
|
||||
{
|
||||
$comment = new Comment();
|
||||
$comment->Name = 'Fred Bloggs';
|
||||
$comment->Comment = 'this is a test comment';
|
||||
@ -664,7 +706,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertFalse($comment->isPreview());
|
||||
}
|
||||
|
||||
public function testCanCreate() {
|
||||
public function testCanCreate()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
|
||||
// admin can create - this is always false
|
||||
@ -676,7 +719,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertFalse($comment->canCreate());
|
||||
}
|
||||
|
||||
public function testCanView() {
|
||||
public function testCanView()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
|
||||
// admin can view
|
||||
@ -692,7 +736,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertFalse($comment->canView());
|
||||
}
|
||||
|
||||
public function testCanEdit() {
|
||||
public function testCanEdit()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
|
||||
// admin can edit
|
||||
@ -708,7 +753,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertFalse($comment->canEdit());
|
||||
}
|
||||
|
||||
public function testCanDelete() {
|
||||
public function testCanDelete()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
|
||||
// admin can delete
|
||||
@ -724,7 +770,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertFalse($comment->canDelete());
|
||||
}
|
||||
|
||||
public function testGetMember() {
|
||||
public function testGetMember()
|
||||
{
|
||||
$this->logInAs('visitor');
|
||||
$current = Member::currentUser();
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
@ -743,7 +790,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals($current, $member);
|
||||
}
|
||||
|
||||
public function testGetAuthorName() {
|
||||
public function testGetAuthorName()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$this->assertEquals(
|
||||
'FA',
|
||||
@ -768,11 +816,11 @@ class CommentsTest extends FunctionalTest {
|
||||
$comment->Name = null;
|
||||
$comment->AuthorID = 0;
|
||||
$this->assertNull($comment->getAuthorName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testLinks() {
|
||||
public function testLinks()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$this->logInAs('commentadmin');
|
||||
|
||||
@ -808,27 +856,31 @@ class CommentsTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testMarkSpam() {
|
||||
public function testMarkSpam()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$comment->markSpam();
|
||||
$this->assertTrue($comment->Moderated);
|
||||
$this->assertTrue($comment->IsSpam);
|
||||
}
|
||||
|
||||
public function testMarkApproved() {
|
||||
public function testMarkApproved()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$comment->markApproved();
|
||||
$this->assertTrue($comment->Moderated);
|
||||
$this->assertFalse($comment->IsSpam);
|
||||
}
|
||||
|
||||
public function testMarkUnapproved() {
|
||||
public function testMarkUnapproved()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$comment->markApproved();
|
||||
$this->assertTrue($comment->Moderated);
|
||||
}
|
||||
|
||||
public function testSpamClass() {
|
||||
public function testSpamClass()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$this->assertEquals('notspam', $comment->spamClass());
|
||||
$comment->Moderated = false;
|
||||
@ -837,7 +889,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals('spam', $comment->spamClass());
|
||||
}
|
||||
|
||||
public function testGetTitle() {
|
||||
public function testGetTitle()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$this->assertEquals(
|
||||
'Comment by FA on First',
|
||||
@ -845,7 +898,8 @@ class CommentsTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetCMSFields() {
|
||||
public function testGetCMSFields()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$fields = $comment->getCMSFields();
|
||||
$names = array();
|
||||
@ -863,7 +917,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals($expected, $names);
|
||||
}
|
||||
|
||||
public function testGetCMSFieldsCommentHasAuthor() {
|
||||
public function testGetCMSFieldsCommentHasAuthor()
|
||||
{
|
||||
$member = Member::get()->filter('FirstName', 'visitor')->first();
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
$comment->AuthorID = $member->ID;
|
||||
@ -886,7 +941,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals($expected, $names);
|
||||
}
|
||||
|
||||
public function testGetCMSFieldsWithParentComment() {
|
||||
public function testGetCMSFieldsWithParentComment()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
|
||||
$child = new Comment();
|
||||
@ -916,7 +972,8 @@ class CommentsTest extends FunctionalTest {
|
||||
}
|
||||
|
||||
|
||||
public function testPurifyHtml() {
|
||||
public function testPurifyHtml()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
|
||||
$dirtyHTML = '<p><script>alert("w00t")</script>my comment</p>';
|
||||
@ -926,7 +983,8 @@ class CommentsTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testGravatar() {
|
||||
public function testGravatar()
|
||||
{
|
||||
// Turn gravatars on
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'use_gravatar' => true
|
||||
@ -951,7 +1009,8 @@ class CommentsTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetRepliesEnabled() {
|
||||
public function testGetRepliesEnabled()
|
||||
{
|
||||
$comment = $this->objFromFixture('Comment', 'firstComA');
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'nested_comments' => false
|
||||
@ -983,11 +1042,10 @@ class CommentsTest extends FunctionalTest {
|
||||
|
||||
$comment->markApproved();
|
||||
$this->assertTrue($comment->getRepliesEnabled());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testAllReplies() {
|
||||
public function testAllReplies()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'nested_comments' => true,
|
||||
'nested_depth' => 4
|
||||
@ -1018,7 +1076,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals(0, $comment->allReplies()->count());
|
||||
}
|
||||
|
||||
public function testReplies() {
|
||||
public function testReplies()
|
||||
{
|
||||
CommentableItem::add_extension('CommentsExtension');
|
||||
$this->logInWithPermission('ADMIN');
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
@ -1085,7 +1144,8 @@ class CommentsTest extends FunctionalTest {
|
||||
CommentableItem::remove_extension('CommentsExtension');
|
||||
}
|
||||
|
||||
public function testPagedReplies() {
|
||||
public function testPagedReplies()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'nested_comments' => true,
|
||||
'nested_depth' => 4,
|
||||
@ -1111,7 +1171,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals(0, $comment->PagedReplies()->count());
|
||||
}
|
||||
|
||||
public function testReplyForm() {
|
||||
public function testReplyForm()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'nested_comments' => false,
|
||||
'nested_depth' => 4
|
||||
@ -1154,7 +1215,8 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertNull($form);
|
||||
}
|
||||
|
||||
public function testUpdateDepth() {
|
||||
public function testUpdateDepth()
|
||||
{
|
||||
Config::inst()->update('CommentableItem', 'comments', array(
|
||||
'nested_comments' => true,
|
||||
'nested_depth' => 4
|
||||
@ -1175,34 +1237,39 @@ class CommentsTest extends FunctionalTest {
|
||||
$this->assertEquals(4, $reply3->Depth);
|
||||
}
|
||||
|
||||
public function testGetToken() {
|
||||
public function testGetToken()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testMemberSalt() {
|
||||
public function testMemberSalt()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testAddToUrl() {
|
||||
public function testAddToUrl()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testCheckRequest() {
|
||||
public function testCheckRequest()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
public function testGenerate() {
|
||||
public function testGenerate()
|
||||
{
|
||||
$this->markTestSkipped('TODO');
|
||||
}
|
||||
|
||||
|
||||
protected static function getMethod($name) {
|
||||
protected static function getMethod($name)
|
||||
{
|
||||
$class = new ReflectionClass('Comment');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
return $method;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1210,7 +1277,8 @@ class CommentsTest extends FunctionalTest {
|
||||
* @package comments
|
||||
* @subpackage tests
|
||||
*/
|
||||
class CommentableItem extends DataObject implements TestOnly {
|
||||
class CommentableItem extends DataObject implements TestOnly
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'Title' => 'Varchar'
|
||||
@ -1220,34 +1288,46 @@ class CommentableItem extends DataObject implements TestOnly {
|
||||
'CommentsExtension'
|
||||
);
|
||||
|
||||
public function RelativeLink() {
|
||||
public function RelativeLink()
|
||||
{
|
||||
return "CommentableItem_Controller";
|
||||
}
|
||||
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is needed for canModerateComments
|
||||
public function canEdit($member = null) {
|
||||
if($member instanceof Member) $memberID = $member->ID;
|
||||
else if(is_numeric($member)) $memberID = $member;
|
||||
else $memberID = Member::currentUserID();
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
if ($member instanceof Member) {
|
||||
$memberID = $member->ID;
|
||||
} elseif (is_numeric($member)) {
|
||||
$memberID = $member;
|
||||
} else {
|
||||
$memberID = Member::currentUserID();
|
||||
}
|
||||
|
||||
if($memberID && Permission::checkMember($memberID, array("ADMIN", "CMS_ACCESS_CommentAdmin"))) return true;
|
||||
if ($memberID && Permission::checkMember($memberID, array("ADMIN", "CMS_ACCESS_CommentAdmin"))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function Link() {
|
||||
public function Link()
|
||||
{
|
||||
return $this->RelativeLink();
|
||||
}
|
||||
|
||||
public function AbsoluteLink() {
|
||||
public function AbsoluteLink()
|
||||
{
|
||||
return Director::absoluteURL($this->RelativeLink());
|
||||
}
|
||||
}
|
||||
|
||||
class CommentableItemEnabled extends CommentableItem {
|
||||
class CommentableItemEnabled extends CommentableItem
|
||||
{
|
||||
private static $defaults = array(
|
||||
'ProvideComments' => true,
|
||||
'ModerationRequired' => 'Required',
|
||||
@ -1256,7 +1336,8 @@ class CommentableItemEnabled extends CommentableItem {
|
||||
}
|
||||
|
||||
|
||||
class CommentableItemDisabled extends CommentableItem {
|
||||
class CommentableItemDisabled extends CommentableItem
|
||||
{
|
||||
private static $defaults = array(
|
||||
'ProvideComments' => false,
|
||||
'ModerationRequired' => 'None',
|
||||
@ -1268,9 +1349,11 @@ class CommentableItemDisabled extends CommentableItem {
|
||||
* @package comments
|
||||
* @subpackage tests
|
||||
*/
|
||||
class CommentableItem_Controller extends Controller implements TestOnly {
|
||||
class CommentableItem_Controller extends Controller implements TestOnly
|
||||
{
|
||||
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
return CommentableItem::get()->first()->CommentsForm();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user