2 namespace wcf\system\user\notification\event;
3 use wcf\data\comment\response\CommentResponse;
4 use wcf\data\comment\response\CommentResponseAction;
5 use wcf\data\comment\Comment;
6 use wcf\data\comment\CommentAction;
7 use wcf\data\comment\CommentEditor;
8 use wcf\data\object\type\ObjectTypeCache;
9 use wcf\data\user\UserProfile;
10 use wcf\system\comment\manager\ICommentManager;
11 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
12 use wcf\system\user\notification\object\IUserNotificationObject;
15 * Default implementation of some methods of the testable user notification event interface
16 * for comment response user notificiation events.
18 * As PHP 5.5 does not support abstract static functions in traits, we require them by this documentation:
19 * - protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
20 * returns the `objectID` and `objectTypeID` parameter for comment creation.
22 * @author Matthias Schmidt
23 * @copyright 2001-2018 WoltLab GmbH
24 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
25 * @package WoltLabSuite\Core\System\User\Notification\Event
28 trait TTestableCommentResponseUserNotificationEvent {
29 use TTestableUserNotificationEvent;
34 public static function canBeTriggeredByGuests() {
39 * Creates a test comment response.
41 * @param UserProfile $recipient
42 * @param UserProfile $author
43 * @return CommentResponse
45 public static function createTestCommentResponse(UserProfile $recipient, UserProfile $author) {
46 /** @var Comment $comment */
47 $comment = (new CommentAction([], 'create', [
48 'data' => array_merge([
51 'message' => '<p>Test Comment</p>',
52 'time' => TIME_NOW - 10,
53 'userID' => $recipient->userID,
54 'username' => $recipient->username
55 ], self::getTestCommentObjectData($recipient, $author))
56 ]))->executeAction()['returnValues'];
58 /** @var ICommentManager $commentManager */
59 $commentManager = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
60 $commentManager->updateCounter($comment->objectID, 1);
62 /** @var CommentResponse $commentResponse */
63 $commentResponse = (new CommentResponseAction([], 'create', [
65 'commentID' => $comment->commentID,
66 'time' => TIME_NOW - 10,
67 'userID' => $author->userID,
68 'username' => $author->username,
69 'message' => 'Test Response',
72 ]))->executeAction()['returnValues'];
74 $commentResponse->setComment($comment);
76 $commentEditor = new CommentEditor($comment);
77 $commentEditor->updateResponseIDs();
78 $commentEditor->updateUnfilteredResponseIDs();
80 return $commentResponse;
86 public static function getTestAdditionalData(IUserNotificationObject $object) {
87 /** @var CommentResponseUserNotificationObject $object */
90 'commentID' => $object->commentID,
91 'objectID' => $object->getComment()->objectID,
92 'objectUserID' => $object->getComment()->objectID,
93 'userID' => $object->getComment()->userID
99 * @return CommentResponseUserNotificationObject[]
101 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
102 return [new CommentResponseUserNotificationObject(self::createTestCommentResponse($recipient, $author))];