40ca8a89bbd525ddaa62dc0cffa8b506dc58d392
[GitHub/WoltLab/WCF.git] /
1 <?php
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;
13
14 /**
15 * Default implementation of some methods of the testable user notification event interface
16 * for comment response user notificiation events.
17 *
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.
21 *
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
26 * @since 3.1
27 */
28 trait TTestableCommentResponseUserNotificationEvent {
29 use TTestableUserNotificationEvent;
30
31 /**
32 * @inheritDoc
33 */
34 public static function canBeTriggeredByGuests() {
35 return true;
36 }
37
38 /**
39 * Creates a test comment response.
40 *
41 * @param UserProfile $recipient
42 * @param UserProfile $author
43 * @return CommentResponse
44 */
45 public static function createTestCommentResponse(UserProfile $recipient, UserProfile $author) {
46 /** @var Comment $comment */
47 $comment = (new CommentAction([], 'create', [
48 'data' => array_merge([
49 'enableHtml' => 1,
50 'isDisabled' => 0,
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'];
57
58 /** @var ICommentManager $commentManager */
59 $commentManager = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
60 $commentManager->updateCounter($comment->objectID, 1);
61
62 /** @var CommentResponse $commentResponse */
63 $commentResponse = (new CommentResponseAction([], 'create', [
64 'data' => [
65 'commentID' => $comment->commentID,
66 'time' => TIME_NOW - 10,
67 'userID' => $author->userID,
68 'username' => $author->username,
69 'message' => 'Test Response',
70 'isDisabled' => 0
71 ]
72 ]))->executeAction()['returnValues'];
73
74 $commentResponse->setComment($comment);
75
76 $commentEditor = new CommentEditor($comment);
77 $commentEditor->updateResponseIDs();
78 $commentEditor->updateUnfilteredResponseIDs();
79
80 return $commentResponse;
81 }
82
83 /**
84 * @inheritDoc
85 */
86 public static function getTestAdditionalData(IUserNotificationObject $object) {
87 /** @var CommentResponseUserNotificationObject $object */
88
89 return [
90 'commentID' => $object->commentID,
91 'objectID' => $object->getComment()->objectID,
92 'objectUserID' => $object->getComment()->objectID,
93 'userID' => $object->getComment()->userID
94 ];
95 }
96
97 /**
98 * @inheritDoc
99 * @return CommentResponseUserNotificationObject[]
100 */
101 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
102 return [new CommentResponseUserNotificationObject(self::createTestCommentResponse($recipient, $author))];
103 }
104 }