public function testCacheAndGetMungeIdsByUser()
 {
     if (AllPermissionsOptimizationCache::supportsAndAllowsMemcache()) {
         $super = User::getByUsername('super');
         AllPermissionsOptimizationCache::cacheMungeIdsByUser($super, array(3, 4, 5));
         $mungeIds = AllPermissionsOptimizationCache::getMungeIdsByUser($super);
         $this->assertEquals(array(3, 4, 5), $mungeIds);
         $oldValue = Yii::app()->params['showFlashMessageWhenSecurityCacheShouldBeRebuilt'];
         Yii::app()->params['showFlashMessageWhenSecurityCacheShouldBeRebuilt'] = true;
         $this->assertEquals(0, count(Yii::app()->user->getFlashes()));
         AllPermissionsOptimizationCache::forgetAll();
         $this->assertEquals(1, count(Yii::app()->user->getFlashes()));
         Yii::app()->params['showFlashMessageWhenSecurityCacheShouldBeRebuilt'] = false;
         $this->assertEquals(0, count(Yii::app()->user->getFlashes()));
         AllPermissionsOptimizationCache::forgetAll();
         $this->assertEquals(0, count(Yii::app()->user->getFlashes()));
         Yii::app()->params['showFlashMessageWhenSecurityCacheShouldBeRebuilt'] = $oldValue;
         try {
             AllPermissionsOptimizationCache::getMungeIdsByUser($super);
             $this->fail('NotFoundException exception is not thrown.');
         } catch (NotFoundException $e) {
             $this->assertTrue(true);
         }
     }
 }
 /**
  * @param User $user
  * @return array
  */
 public static function getMungeIdsByUser(User $user)
 {
     try {
         return AllPermissionsOptimizationCache::getMungeIdsByUser($user);
     } catch (NotFoundException $e) {
         list($roleId, $groupIds) = self::getUserRoleIdAndGroupIds($user);
         $mungeIds = array("U{$user->id}");
         if ($roleId != null) {
             $mungeIds[] = "R{$roleId}";
         }
         foreach ($groupIds as $groupId) {
             $mungeIds[] = "G{$groupId}";
         }
         //Add everyone group
         $everyoneGroupId = Group::getByName(Group::EVERYONE_GROUP_NAME)->id;
         if (!in_array("G" . $everyoneGroupId, $mungeIds) && $everyoneGroupId > 0) {
             $mungeIds[] = "G" . $everyoneGroupId;
         }
         AllPermissionsOptimizationCache::cacheMungeIdsByUser($user, $mungeIds);
     }
     return $mungeIds;
 }