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;
13 * Default implementation of some methods of the testable user notification event interface
14 * for comment response user notificiation events.
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.
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
26 trait TTestableCommentResponseUserNotificationEvent {
27 use TTestableUserNotificationEvent;
32 public static function canBeTriggeredByGuests() {
37 * Creates a test comment response.
39 * @param UserProfile $recipient
40 * @param UserProfile $author
41 * @return CommentResponse
43 public static function createTestCommentResponse(UserProfile $recipient, UserProfile $author) {
44 /** @var Comment $comment */
45 $comment = (new CommentAction([], 'create', [
46 'data' => array_merge([
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'];
56 /** @var CommentResponse $commentResponse */
57 $commentResponse = (new CommentResponseAction([], 'create', [
59 'commentID' => $comment->commentID,
60 'time' => TIME_NOW - 10,
61 'userID' => $author->userID,
62 'username' => $author->username,
63 'message' => 'Test Response',
66 ]))->executeAction()['returnValues'];
68 $commentResponse->setComment($comment);
70 $commentEditor = new CommentEditor($comment);
71 $commentEditor->updateResponseIDs();
72 $commentEditor->updateUnfilteredResponseIDs();
74 return $commentResponse;
80 public static function getTestAdditionalData(IUserNotificationObject $object) {
81 /** @var CommentResponseUserNotificationObject $object */
84 'commentID' => $object->commentID,
85 'objectID' => $object->getComment()->objectID,
86 'objectUserID' => $object->getComment()->objectID,
87 'userID' => $object->getComment()->userID
93 * @return CommentResponseUserNotificationObject[]
95 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
96 return [new CommentResponseUserNotificationObject(self::createTestCommentResponse($recipient, $author))];