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