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