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;
12 * Default implementation of some methods of the testable user notification event interface
13 * for comment user notificiation events.
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.
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
25 trait TTestableCommentUserNotificationEvent {
26 use TTestableUserNotificationEvent;
31 public static function canBeTriggeredByGuests() {
36 * Creates a test comment.
38 * @param UserProfile $recipient
39 * @param UserProfile $author
42 public static function createTestComment(UserProfile $recipient, UserProfile $author) {
43 /** @var Comment $comment */
44 $comment = (new CommentAction([], 'create', [
45 'data' => array_merge([
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'];
55 /** @var ICommentManager $commentManager */
56 $commentManager = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID)->getProcessor();
57 $commentManager->updateCounter($comment->objectID, 1);
63 * @see ITestableUserNotificationEvent::getTestAdditionalData()
65 public static function getTestAdditionalData(IUserNotificationObject $object) {
66 /** @var CommentUserNotificationObject $object */
68 return ['objectUserID' => $object->objectID];
73 * @return CommentUserNotificationObject[]
75 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
76 return [new CommentUserNotificationObject(self::createTestComment($recipient, $author))];