3 namespace wcf\system\user\notification\event;
5 use wcf\data\page\content\PageContentEditor;
6 use wcf\data\page\Page;
7 use wcf\data\page\PageAction;
8 use wcf\data\page\PageCache;
9 use wcf\system\cache\builder\PageCacheBuilder;
10 use wcf\system\cache\builder\RoutingCacheBuilder;
11 use wcf\system\request\ControllerMap;
12 use wcf\system\user\notification\TestableUserNotificationEventHandler;
15 * Provides a method to create a page for testing user notification
18 * @author Joshua Ruesweg
19 * @copyright 2001-2019 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package WoltLabSuite\Core\System\User\Notification\Event
24 trait TTestablePageUserNotificationEvent
27 * Creates a moderation queue entry for a reported user.
31 public static function getTestPage()
33 /** @var Page $page */
34 $page = (new PageAction([], 'create', [
36 'parentPageID' => null,
38 'name' => 'Page Title',
40 'applicationPackageID' => 1,
41 'lastUpdateTime' => TIME_NOW,
42 'isMultilingual' => 0,
48 'title' => 'Page Title',
49 'content' => 'Page Content',
50 'metaDescription' => '',
51 'customURL' => 'test-page',
54 ]))->executeAction()['returnValues'];
55 $pageContents = $page->getPageContents();
56 $pageContent = \reset($pageContents);
58 $editor = new PageContentEditor($pageContent);
60 'customURL' => 'test-page-' . $page->pageID,
63 self::resetPageCache();
68 private static function resetPageCache()
70 // reset cache builders
71 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(PageCacheBuilder::getInstance());
72 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(RoutingCacheBuilder::getInstance());
75 $reflectionClass = new \ReflectionClass(PageCache::class);
76 $reflectionProperty = $reflectionClass->getProperty('cache');
77 $reflectionProperty->setAccessible(true);
78 $reflectionProperty->setValue(PageCache::getInstance(), PageCacheBuilder::getInstance()->getData());
80 // reset controller map
81 $reflectionClass = new \ReflectionClass(ControllerMap::class);
82 $reflectionMethod = $reflectionClass->getMethod('init');
83 $reflectionMethod->setAccessible(true);
84 $reflectionMethod->invoke(ControllerMap::getInstance());