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); }
/** * 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()); } }