2 namespace wcf\system\user\notification\event;
3 use wcf\data\like\object\ILikeObject;
4 use wcf\data\like\Like;
5 use wcf\data\user\UserProfile;
6 use wcf\system\cache\runtime\UserRuntimeCache;
7 use wcf\system\like\LikeHandler;
8 use wcf\system\user\notification\object\IUserNotificationObject;
9 use wcf\system\user\notification\object\LikeUserNotificationObject;
13 * Default implementation of some methods of the testable user notification event interface
14 * for like user notificiation events.
16 * As PHP 5.5 does not support abstract static functions in traits, we require them by this documentation:
17 * - protected static function createTestLikeObject(UserProfile $recipient, UserProfile $author)
18 * creates a likable object
19 * - protected static function getTestLikeableObjectTypeName()
20 * returns the name of the likeable object type name
22 * @author Matthias Schmidt
23 * @copyright 2001-2018 WoltLab GmbH
24 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
25 * @package WoltLabSuite\Core\System\User\Notification\Event
28 trait TTestableLikeUserNotificationEvent {
32 public static function canBeTriggeredByGuests() {
37 * Returns the like object for the given user notification object.
39 * @param IUserNotificationObject $object
42 protected static function getTestLikeObject(IUserNotificationObject $object) {
43 /** @var LikeUserNotificationObject $object */
45 $oldUser = WCF::getUser();
47 WCF::getSession()->changeUser(UserRuntimeCache::getInstance()->getObject($object->userID), true);
49 LikeHandler::getInstance()->loadLikeObjects(
50 LikeHandler::getInstance()->getObjectType(self::getTestLikeableObjectTypeName()),
54 WCF::getSession()->changeUser($oldUser, true);
56 return LikeHandler::getInstance()->getLikeObject(
57 LikeHandler::getInstance()->getObjectType(self::getTestLikeableObjectTypeName()),
64 * @return LikeUserNotificationObject[]
66 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
67 /** @var ILikeObject $likeObject */
68 $likeObject = self::createTestLikeObject($recipient, $author);
69 $likeObject->setObjectType(LikeHandler::getInstance()->getObjectType(self::getTestLikeableObjectTypeName()));
71 /** @var Like $like */
72 $like = LikeHandler::getInstance()->like(
74 $author->getDecoratedObject(),
78 return [new LikeUserNotificationObject($like)];