da9574b506ae3b29955952aad22af30b485b0f30
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\comment\Comment;
4 use wcf\data\comment\CommentAction;
5 use wcf\data\object\type\ObjectTypeCache;
6 use wcf\data\user\UserProfile;
7 use wcf\system\comment\manager\ICommentManager;
8 use wcf\system\user\notification\object\CommentUserNotificationObject;
9 use wcf\system\user\notification\object\IUserNotificationObject;
10
11 /**
12 * Default implementation of some methods of the testable user notification event interface
13 * for comment user notificiation events.
14 *
15 * As PHP 5.5 does not support abstract static functions in traits, we require them by this documentation:
16 * - protected static function getTestCommentObjectData(UserProfile $recipient, UserProfile $author)
17 * returns the `objectID` and `objectTypeID` parameter for comment creation.
18 *
19 * @author Matthias Schmidt
20 * @copyright 2001-2018 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22 * @package WoltLabSuite\Core\System\User\Notification\Event
23 * @since 3.1
24 */
25 trait TTestableCommentUserNotificationEvent {
26 use TTestableUserNotificationEvent;
27
28 /**
29 * @inheritDoc
30 */
31 public static function canBeTriggeredByGuests() {
32 return true;
33 }
34
35 /**
36 * Creates a test comment.
37 *
38 * @param UserProfile $recipient
39 * @param UserProfile $author
40 * @return Comment
41 */
42 public static function createTestComment(UserProfile $recipient, UserProfile $author) {
43 /** @var Comment $comment */
44 $comment = (new CommentAction([], 'create', [
45 'data' => array_merge([
46 'enableHtml' => 1,
47 'isDisabled' => 0,
48 'message' => '<p>Test Comment</p>',
49 'time' => TIME_NOW - 10,
50 'userID' => $recipient->userID,
51 'username' => $recipient->username
52 ], self::getTestCommentObjectData($recipient, $author))
53 ]))->executeAction()['returnValues'];
54
55 /** @var ICommentManager $commentManager */
56 $commentManager = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
57 $commentManager->updateCounter($comment->objectID, 1);
58
59 return $comment;
60 }
61
62 /**
63 * @see ITestableUserNotificationEvent::getTestAdditionalData()
64 */
65 public static function getTestAdditionalData(IUserNotificationObject $object) {
66 /** @var CommentUserNotificationObject $object */
67
68 return ['objectUserID' => $object->objectID];
69 }
70
71 /**
72 * @inheritDoc
73 * @return CommentUserNotificationObject[]
74 */
75 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
76 return [new CommentUserNotificationObject(self::createTestComment($recipient, $author))];
77 }
78 }