2 namespace wcf\system\user\notification\event;
3 use wcf\data\page\content\PageContentEditor;
4 use wcf\data\page\Page;
5 use wcf\data\page\PageAction;
6 use wcf\data\page\PageCache;
7 use wcf\system\cache\builder\PageCacheBuilder;
8 use wcf\system\cache\builder\RoutingCacheBuilder;
9 use wcf\system\request\ControllerMap;
10 use wcf\system\user\notification\TestableUserNotificationEventHandler;
13 * Provides a method to create a page for testing user notification
16 * @author Joshua Ruesweg
17 * @copyright 2001-2018 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package WoltLabSuite\Core\System\User\Notification\Event
22 trait TTestablePageUserNotificationEvent {
24 * Creates a moderation queue entry for a reported user.
28 public static function getTestPage() {
29 /** @var Page $page */
30 $page = (new PageAction([], 'create', [
32 'parentPageID' => null,
34 'name' => 'Page Title',
36 'applicationPackageID' => 1,
37 'lastUpdateTime' => TIME_NOW,
38 'isMultilingual' => 0,
44 'title' => 'Page Title',
45 'content' => 'Page Content',
46 'metaDescription' => '',
48 'customURL' => 'test-page'
51 ]))->executeAction()['returnValues'];
52 $pageContents = $page->getPageContents();
53 $pageContent = reset($pageContents);
55 $editor = new PageContentEditor($pageContent);
57 'customURL' => 'test-page-'. $page->pageID
60 self::resetPageCache();
65 private static function resetPageCache() {
66 // reset cache builders
67 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(PageCacheBuilder::getInstance());
68 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(RoutingCacheBuilder::getInstance());
71 $reflectionClass = new \ReflectionClass(PageCache::class);
72 $reflectionProperty = $reflectionClass->getProperty('cache');
73 $reflectionProperty->setAccessible(true);
74 $reflectionProperty->setValue(PageCache::getInstance(), PageCacheBuilder::getInstance()->getData());
76 // reset controller map
77 $reflectionClass = new \ReflectionClass(ControllerMap::class);
78 $reflectionMethod = $reflectionClass->getMethod('init');
79 $reflectionMethod->setAccessible(true);
80 $reflectionMethod->invoke(ControllerMap::getInstance());