1c5d2989c49158d7cd92588033c871fdddeca1fa
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
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;
13
14 /**
15 * Provides a method to create a page for testing user notification
16 * events.
17 *
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
22 * @since 5.2
23 */
24 trait TTestablePageUserNotificationEvent
25 {
26 /**
27 * Creates a moderation queue entry for a reported user.
28 *
29 * @return Page
30 */
31 public static function getTestPage()
32 {
33 /** @var Page $page */
34 $page = (new PageAction([], 'create', [
35 'data' => [
36 'parentPageID' => null,
37 'pageType' => 'text',
38 'name' => 'Page Title',
39 'cssClassName' => '',
40 'applicationPackageID' => 1,
41 'lastUpdateTime' => TIME_NOW,
42 'isMultilingual' => 0,
43 'identifier' => '',
44 'packageID' => 1,
45 ],
46 'content' => [
47 0 => [
48 'title' => 'Page Title',
49 'content' => 'Page Content',
50 'metaDescription' => '',
51 'customURL' => 'test-page',
52 ],
53 ],
54 ]))->executeAction()['returnValues'];
55 $pageContents = $page->getPageContents();
56 $pageContent = \reset($pageContents);
57
58 $editor = new PageContentEditor($pageContent);
59 $editor->update([
60 'customURL' => 'test-page-' . $page->pageID,
61 ]);
62
63 self::resetPageCache();
64
65 return $page;
66 }
67
68 private static function resetPageCache()
69 {
70 // reset cache builders
71 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(PageCacheBuilder::getInstance());
72 TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(RoutingCacheBuilder::getInstance());
73
74 // reset page cache
75 $reflectionClass = new \ReflectionClass(PageCache::class);
76 $reflectionProperty = $reflectionClass->getProperty('cache');
77 $reflectionProperty->setAccessible(true);
78 $reflectionProperty->setValue(PageCache::getInstance(), PageCacheBuilder::getInstance()->getData());
79
80 // reset controller map
81 $reflectionClass = new \ReflectionClass(ControllerMap::class);
82 $reflectionMethod = $reflectionClass->getMethod('init');
83 $reflectionMethod->setAccessible(true);
84 $reflectionMethod->invoke(ControllerMap::getInstance());
85 }
86 }