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