Fix trophy user notification test
authorJoshua Rüsweg <josh@bastelstu.be>
Tue, 1 Aug 2017 09:56:26 +0000 (11:56 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Tue, 1 Aug 2017 09:56:26 +0000 (11:56 +0200)
See #2359

wcfsetup/install/files/lib/data/trophy/TrophyCache.class.php
wcfsetup/install/files/lib/system/user/notification/TestableUserNotificationEventHandler.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserTrophyReceivedNotificationEvent.class.php

index c3654eb5fb7452edcf9617d2becf69078cf66615..b5792d0cf4ed860cd7da751a0e20002170187934 100644 (file)
@@ -138,8 +138,5 @@ class TrophyCache extends SingletonFactory {
        public function clearCache() {
                TrophyCacheBuilder::getInstance()->reset();
                TrophyCacheBuilder::getInstance()->reset(['onlyEnabled' => 1]);
-               
-               // rebuild this cache
-               $this->init();
        }
 }
index 4acf40cd5c5a3a1d06b7f5b0007dd7fe5bf6f950..40a09d10f5877bc6eb8d888b745edfc37f81ffd9 100644 (file)
@@ -261,7 +261,7 @@ class TestableUserNotificationEventHandler extends SingletonFactory {
        
        /**
         * Forcefully resets the internal data of a cache builder to get up-to-date
-        * data within the same request. This is crutial as during testing, objects
+        * data within the same request. This is crucial as during testing, objects
         * are created and used within the same request.
         * 
         * @param       ICacheBuilder   $cacheBuilder
index 483bd8a5a2d5d0a90230c1d98f5ed130119da073..3e4619a6d5faaeb45792f6f643c2760860ac10f3 100644 (file)
@@ -1,12 +1,14 @@
 <?php
 namespace wcf\system\user\notification\event;
 use wcf\data\trophy\category\TrophyCategory;
+use wcf\data\trophy\category\TrophyCategoryCache;
 use wcf\data\trophy\Trophy;
 use wcf\data\trophy\TrophyAction;
 use wcf\data\trophy\TrophyCache;
 use wcf\data\user\trophy\UserTrophy;
 use wcf\data\user\trophy\UserTrophyAction;
 use wcf\data\user\UserProfile;
+use wcf\system\cache\builder\CategoryCacheBuilder;
 use wcf\system\cache\builder\TrophyCacheBuilder;
 use wcf\system\user\notification\object\UserTrophyNotificationObject;
 use wcf\system\user\notification\TestableUserNotificationEventHandler;
@@ -84,8 +86,16 @@ class UserTrophyReceivedNotificationEvent extends AbstractUserNotificationEvent
                        ]
                ]))->executeAction()['returnValues'];
                
-               /** @var UserTrophy $userTropy */
-               $userTropy = (new UserTrophyAction([], 'create', [
+               TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(TrophyCacheBuilder::getInstance());
+               TrophyCache::getInstance()->clearCache();
+               TrophyCache::getInstance()->init();
+               
+               TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(CategoryCacheBuilder::getInstance());
+               CategoryCacheBuilder::getInstance()->reset();
+               TrophyCategoryCache::getInstance()->init();
+               
+               /** @var UserTrophy $userTrophy */
+               $userTrophy = (new UserTrophyAction([], 'create', [
                        'data' => [
                                'trophyID' => $trophy->trophyID,
                                'userID' => $recipient->userID,
@@ -95,9 +105,6 @@ class UserTrophyReceivedNotificationEvent extends AbstractUserNotificationEvent
                        ]
                ]))->executeAction()['returnValues'];
                
-               TestableUserNotificationEventHandler::getInstance()->resetCacheBuilder(TrophyCacheBuilder::getInstance());
-               TrophyCache::getInstance()->clearCache();
-               
-               return [new UserTrophyNotificationObject($userTropy)];
+               return [new UserTrophyNotificationObject($userTrophy)];
        }
 }