33edf12f7e81481ea04ac4e35617f7e3881c6c36
[GitHub/WoltLab/WCF.git] /
1 <?php
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;
8
9 /**
10 * Provides a method to create a category of a certain object type to be used by
11 * categorized object user notification events.
12 *
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
17 * @since 3.1
18 */
19 trait TTestableCategorizedUserNotificationEvent {
20 /**
21 * Returns a newly created test category of the given object type.
22 *
23 * @param string $objectTypeName
24 * @param array $additionalData
25 * @return Category
26 */
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}'.");
31 }
32
33 $category = (new CategoryAction([], 'create', [
34 'data' => [
35 'additionalData' => serialize($additionalData),
36 'description' => 'Category Description',
37 'isDisabled' => 0,
38 'objectTypeID' => $objectType->objectTypeID,
39 'title' => 'Category Title'
40 ]
41 ]))->executeAction()['returnValues'];
42
43 // work-around to reset category cache during this request
44 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(CategoryCacheBuilder::getInstance());
45
46 CategoryHandler::getInstance()->reloadCache();
47
48 return $category;
49 }
50 }