07826f746398007d815cf2bb88f55d11bad7a872
[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\user\UserProfile;
9 use wcf\system\user\notification\object\CommentResponseUserNotificationObject;
10 use wcf\system\user\notification\object\IUserNotificationObject;
11
12 /**
13 * Default implementation of some methods of the testable user notification event interface
14 * for comment response user notificiation events.
15 *
16 * As PHP 5.5 does not support abstract static functions in traits, we require them by this documentation:
17 * - protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
18 * returns the `objectID` and `objectTypeID` parameter for comment creation.
19 *
20 * @author Matthias Schmidt
21 * @copyright 2001-2017 WoltLab GmbH
22 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 * @package WoltLabSuite\Core\System\User\Notification\Event
24 * @since 3.1
25 */
26 trait TTestableCommentResponseUserNotificationEvent {
27 use TTestableUserNotificationEvent;
28
29 /**
30 * @inheritDoc
31 */
32 public static function canBeTriggeredByGuests() {
33 return true;
34 }
35
36 /**
37 * Creates a test comment response.
38 *
39 * @param UserProfile $recipient
40 * @param UserProfile $author
41 * @return CommentResponse
42 */
43 public static function createTestCommentResponse(UserProfile $recipient, UserProfile $author) {
44 /** @var Comment $comment */
45 $comment = (new CommentAction([], 'create', [
46 'data' => array_merge([
47 'enableHtml' => 1,
48 'isDisabled' => 0,
49 'message' => '<p>Test Comment</p>',
50 'time' => TIME_NOW - 10,
51 'userID' => $recipient->userID,
52 'username' => $recipient->username
53 ], self::getTestCommentObjectData($recipient, $author))
54 ]))->executeAction()['returnValues'];
55
56 /** @var CommentResponse $commentResponse */
57 $commentResponse = (new CommentResponseAction([], 'create', [
58 'data' => [
59 'commentID' => $comment->commentID,
60 'time' => TIME_NOW - 10,
61 'userID' => $author->userID,
62 'username' => $author->username,
63 'message' => 'Test Response',
64 'isDisabled' => 0
65 ]
66 ]))->executeAction()['returnValues'];
67
68 $commentResponse->setComment($comment);
69
70 $commentEditor = new CommentEditor($comment);
71 $commentEditor->updateResponseIDs();
72 $commentEditor->updateUnfilteredResponseIDs();
73
74 return $commentResponse;
75 }
76
77 /**
78 * @inheritDoc
79 */
80 public static function getTestAdditionalData(IUserNotificationObject $object) {
81 /** @var CommentResponseUserNotificationObject $object */
82
83 return [
84 'commentID' => $object->commentID,
85 'objectID' => $object->getComment()->objectID,
86 'objectUserID' => $object->getComment()->objectID,
87 'userID' => $object->getComment()->userID
88 ];
89 }
90
91 /**
92 * @inheritDoc
93 * @return CommentResponseUserNotificationObject[]
94 */
95 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
96 return [new CommentResponseUserNotificationObject(self::createTestCommentResponse($recipient, $author))];
97 }
98 }