Merge branch '5.5'
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / system / user / notification / event / TTestableConversationRelatedUserNotificationEvent.class.php
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\conversation\Conversation;
6 use wcf\data\conversation\ConversationAction;
7 use wcf\data\conversation\message\ConversationMessage;
8 use wcf\data\conversation\message\ConversationMessageAction;
9 use wcf\data\user\UserProfile;
10
11 /**
12 * Provides methods to create conversations and conversation messages for testing
13 * user notification events.
14 *
15 * @author Matthias Schmidt
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @since 3.1
19 */
20 trait TTestableConversationRelatedUserNotificationEvent
21 {
22 /**
23 * Creates a conversation for testing.
24 *
25 * @param UserProfile $conversationAuthor
26 * @param UserProfile $participant
27 * @return Conversation
28 */
29 public static function createTestConversation(UserProfile $conversationAuthor, UserProfile $participant)
30 {
31 return (new ConversationAction([], 'create', [
32 'data' => [
33 'subject' => 'Test Conversation Subject',
34 'time' => TIME_NOW,
35 'userID' => $conversationAuthor->userID,
36 'username' => $conversationAuthor->username,
37 ],
38 'messageData' => [
39 'message' => 'Test Conversation Message',
40 ],
41 'participants' => [$participant->userID],
42 ]))->executeAction()['returnValues'];
43 }
44
45 /**
46 * Creates a conversation message for testing.
47 *
48 * @param UserProfile $conversationAuthor
49 * @param UserProfile $messageAuthor
50 * @return ConversationMessage
51 */
52 public static function createTestConversationMessage(UserProfile $conversationAuthor, UserProfile $messageAuthor)
53 {
54 $conversation = self::createTestConversation($conversationAuthor, $messageAuthor);
55
56 return (new ConversationMessageAction([], 'create', [
57 'data' => [
58 'conversationID' => $conversation->conversationID,
59 'message' => 'Test Conversation Message Message',
60 'time' => TIME_NOW,
61 'userID' => $messageAuthor->userID,
62 'username' => $messageAuthor->username,
63 ],
64 'conversation' => $conversation,
65 ]))->executeAction()['returnValues'];
66 }
67 }