2 namespace wcf\system\user\notification\event;
3 use wcf\data\category\Category;
4 use wcf\data\category\CategoryAction;
5 use wcf\system\cache\builder\CategoryCacheBuilder;
6 use wcf\system\category\CategoryHandler;
7 use wcf\system\user\notification\TestableUserNotificationEventHandler;
10 * Provides a method to create a category of a certain object type to be used by
11 * categorized object user notification events.
13 * @author Matthias Schmidt
14 * @copyright 2001-2018 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\User\Notification\Event
19 trait TTestableCategorizedUserNotificationEvent {
21 * Returns a newly created test category of the given object type.
23 * @param string $objectTypeName
24 * @param array $additionalData
27 protected static function createTestCategory($objectTypeName, array $additionalData = []) {
28 $objectType = CategoryHandler::getInstance()->getObjectTypeByName($objectTypeName);
29 if ($objectType === null) {
30 throw new \InvalidArgumentException("Unknown comment object type '{$objectTypeName}'.");
33 $category = (new CategoryAction([], 'create', [
35 'additionalData' => serialize($additionalData),
36 'description' => 'Category Description',
38 'objectTypeID' => $objectType->objectTypeID,
39 'title' => 'Category Title'
41 ]))->executeAction()['returnValues'];
43 // work-around to reset category cache during this request
44 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(CategoryCacheBuilder::getInstance());
46 CategoryHandler::getInstance()->reloadCache();