public function setUp()
 {
     parent::setUp();
     global $wgEchoNotifications;
     $this->setMwGlobals('wgAllowHTMLEmail', true);
     $event = $this->mockEvent('edit-user-talk');
     $event->expects($this->any())->method('getTitle')->will($this->returnValue(Title::newMainPage()));
     $formatter = EchoNotificationFormatter::factory($wgEchoNotifications[$event->getType()]);
     $formatter->setOutputFormat('email');
     $user = User::newFromId(1);
     $user->setName('Test');
     $user->setOption('echo-email-format', EchoHooks::EMAIL_FORMAT_HTML);
     $this->emailSingle = new EchoEmailSingle($formatter, $event, $user);
     $content[$event->getCategory()][] = EchoNotificationController::formatNotification($event, $user, 'email', 'emaildigest');
     $this->emailDigest = new EchoEmailDigest(User::newFromId(2), $content);
 }
Example #2
0
 /**
  * @param array
  */
 public function __construct($params)
 {
     parent::__construct($params);
     // Set up default params if any are missing
     $params = $this->setDefaultParams($params);
     // Title for archive page
     $this->title = array('message' => $params['title-message'], 'params' => $params['title-params']);
     // Title for the flyout
     $this->flyoutTitle = array('message' => $params['flyout-message'], 'params' => $params['flyout-params']);
     // Bundle title for both archive page and flyout
     $this->bundleTitle = array('message' => $params['bundle-message'], 'params' => $params['bundle-params']);
     // Notification payload data, eg, summary
     $this->payload = $params['payload'];
     // Notification email subject and body
     $this->email = array('subject' => array('message' => $params['email-subject-message'], 'params' => $params['email-subject-params']), 'batch-body' => array('message' => $params['email-body-batch-message'], 'params' => $params['email-body-batch-params']), 'batch-bundle-body' => array('message' => $params['email-body-batch-bundle-message'], 'params' => $params['email-body-batch-bundle-params']));
     // Notification icon for the event type
     $this->icon = $params['icon'];
 }
 /**
  * Formats a notification
  *
  * @param $event EchoEvent that the notification is for.
  * @param $user User to format the notification for.
  * @param $format string The format to show the notification in: text, html, or email
  * @param $type string The type of notification being distributed (e.g. email, web)
  * @return string|array The formatted notification, or an array of subject
  *     and body (for emails), or an error message
  */
 public static function formatNotification($event, $user, $format = 'text', $type = 'web')
 {
     global $wgEchoNotifications;
     $eventType = $event->getType();
     // if ($event->getId() == '104') {
     // print_r($event);
     // exit;
     // }
     //print $event->getId();
     $res = '';
     if (isset($wgEchoNotifications[$eventType])) {
         set_error_handler(array(__CLASS__, 'formatterErrorHandler'), -1);
         try {
             $params = $wgEchoNotifications[$eventType];
             $notifier = EchoNotificationFormatter::factory($params);
             $notifier->setOutputFormat($format);
             $res = $notifier->format($event, $user, $type);
         } catch (Exception $e) {
             $meta = array('id' => $event->getId(), 'eventType' => $eventType, 'format' => $format, 'type' => $type, 'user' => $user ? $user->getName() : 'no user');
             wfDebugLog(__CLASS__, __FUNCTION__ . ": Error formatting " . FormatJson::encode($meta));
             MWExceptionHandler::logException($e);
         }
         restore_error_handler();
     } else {
         $res = 'whoops - ' . $eventType;
     }
     if ($res) {
         return $res;
     } else {
         return Xml::tags('span', array('class' => 'error'), wfMessage('echo-error-no-formatter', $event->getType())->escaped());
     }
 }