cb73071742651f5ae0e47f47f826e3a98b21e373
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\event;
3 use wcf\data\moderation\queue\ModerationQueue;
4 use wcf\data\object\type\ObjectTypeCache;
5 use wcf\data\user\UserProfile;
6 use wcf\system\moderation\queue\ModerationQueueManager;
7 use wcf\system\moderation\queue\ModerationQueueReportManager;
8 use wcf\system\WCF;
9
10 /**
11 * Provides a method to create a moderation queue entry for testing user notification
12 * events.
13 *
14 * @author Matthias Schmidt
15 * @copyright 2001-2017 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\User\Notification\Event
18 * @since 3.1
19 */
20 trait TTestableModerationQueueUserNotificationEvent {
21 /**
22 * Creates a moderation queue entry for a reported user.
23 *
24 * @param UserProfile $reportedUser
25 * @param UserProfile $reportingUser
26 * @return ModerationQueue
27 */
28 public static function getTestUserModerationQueueEntry(UserProfile $reportedUser, UserProfile $reportingUser) {
29 $objectTypeID = ModerationQueueReportManager::getInstance()->getObjectTypeID('com.woltlab.wcf.user');
30
31 $originalUser = WCF::getUser();
32 WCF::getSession()->changeUser($reportingUser->getDecoratedObject(), true);
33
34 ModerationQueueReportManager::getInstance()->addReport(
35 ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->objectType,
36 $reportedUser->userID,
37 'Report Message'
38 );
39
40 WCF::getSession()->changeUser($originalUser, true);
41
42 $sql = "SELECT *
43 FROM wcf" . WCF_N . "_moderation_queue
44 WHERE objectTypeID = ?
45 AND objectID = ?";
46 $statement = WCF::getDB()->prepareStatement($sql);
47 $statement->execute([$objectTypeID, $reportedUser->userID]);
48
49 $moderationQueue = $statement->fetchObject(ModerationQueue::class);
50
51 ModerationQueueManager::getInstance()->setAssignment([$moderationQueue->queueID => true]);
52
53 return $moderationQueue;
54 }
55 }