2 declare(strict_types=1);
3 namespace wcf\system\user\notification\event;
4 use wcf\data\like\object\ILikeObject;
5 use wcf\data\like\Like;
6 use wcf\data\user\UserProfile;
7 use wcf\system\cache\runtime\UserRuntimeCache;
8 use wcf\system\like\LikeHandler;
9 use wcf\system\user\notification\object\IUserNotificationObject;
10 use wcf\system\user\notification\object\LikeUserNotificationObject;
14 * Default implementation of some methods of the testable user notification event interface
15 * for like user notificiation events.
17 * As PHP 5.5 does not support abstract static functions in traits, we require them by this documentation:
18 * - protected static function createTestLikeObject(UserProfile $recipient, UserProfile $author)
19 * creates a likable object
20 * - protected static function getTestLikeableObjectTypeName()
21 * returns the name of the likeable object type name
23 * @author Matthias Schmidt
24 * @copyright 2001-2018 WoltLab GmbH
25 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
26 * @package WoltLabSuite\Core\System\User\Notification\Event
29 trait TTestableLikeUserNotificationEvent {
33 public static function canBeTriggeredByGuests() {
38 * Returns the like object for the given user notification object.
40 * @param IUserNotificationObject $object
43 protected static function getTestLikeObject(IUserNotificationObject $object) {
44 /** @var LikeUserNotificationObject $object */
46 $oldUser = WCF::getUser();
48 WCF::getSession()->changeUser(UserRuntimeCache::getInstance()->getObject($object->userID), true);
50 LikeHandler::getInstance()->loadLikeObjects(
51 LikeHandler::getInstance()->getObjectType(self::getTestLikeableObjectTypeName()),
55 WCF::getSession()->changeUser($oldUser, true);
57 return LikeHandler::getInstance()->getLikeObject(
58 LikeHandler::getInstance()->getObjectType(self::getTestLikeableObjectTypeName()),
65 * @return LikeUserNotificationObject[]
67 public static function getTestObjects(UserProfile $recipient, UserProfile $author) {
68 /** @var ILikeObject $likeObject */
69 $likeObject = self::createTestLikeObject($recipient, $author);
70 $likeObject->setObjectType(LikeHandler::getInstance()->getObjectType(self::getTestLikeableObjectTypeName()));
72 /** @var Like $like */
73 $like = LikeHandler::getInstance()->like(
75 $author->getDecoratedObject(),
79 return [new LikeUserNotificationObject($like)];