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