public function testUnlocked()
 {
     $user = FactoryMuffin::create('RainLab\\User\\Models\\User');
     $step = FactoryMuffin::create('DMA\\Friends\\Models\\Step');
     $params = ['object' => $step, 'user' => $user];
     FriendsLog::unlocked($params);
 }
 /**
  * Complete the step and proceed to complete a badge if it can be completed
  *
  * @param Step $step
  * A step model
  * @param User $user
  * A user model
  */
 private static function completeBadge(Step $step, User $user)
 {
     $badge = $step->badge;
     // Check badge global limit
     if ($badge->maximum_earnings_global > 0 && count($badge->users) > $badge->maximum_earnings_global) {
         return false;
     }
     // Complete step
     try {
         $user->steps()->save($step);
         Event::fire('dma.friends.step.completed', [$step, $user]);
     } catch (Exception $e) {
         throw new Exception(Lang::get('dma.friends::lang.exceptions.stepFailed'));
     }
     // See if the user has completed all steps for a badge
     foreach ($badge->steps as $step) {
         if (!$user->steps->contains($step->id)) {
             //user did not complete a step in badge so we cannot complete the badge
             return;
         }
     }
     try {
         // If loop completes with out returning false the user has completed all steps
         $user->badges()->save($badge);
         $userExtend = new UserExtend($user);
         $userExtend->addPoints($badge->points);
         Event::fire('dma.friends.badge.completed', [$badge, $user]);
         // log an entry to the activity log
         FriendsLog::unlocked(['user' => $user, 'object' => $badge]);
         if ($badge->congratulations_text) {
             $notificationText = $badge->congratulations_text;
         } else {
             $notificationText = Lang::get('dma.friends::lang.badges.completed', ['title' => $badge->title]);
         }
         //Flash::info($notificationText);
         Postman::send('simple', function (NotificationMessage $notification) use($user, $badge, $notificationText) {
             // Set user
             $notification->to($user, $user->name);
             // Send code and activity just in case we want to use in the template
             $notification->addData(['badge' => $badge]);
             $notification->message($notificationText);
         }, ['flash', 'kiosk']);
     } catch (Exception $e) {
         throw new Exception(Lang::get('dma.friends::lang.exceptions.badgeFailed'));
     }
 }