/** * @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification * @return INotification * @throws \InvalidArgumentException When the notification was not prepared by a notifier */ public function prepare(INotification $notification, $languageCode) { if ($notification->getApp() !== 'announcementcenter') { // Not my app => throw throw new \InvalidArgumentException(); } // Read the language from the notification $l = $this->l10nFactory->get('announcementcenter', $languageCode); switch ($notification->getSubject()) { // Deal with known subjects case 'announced': $params = $notification->getSubjectParameters(); $announcement = $this->manager->getAnnouncement($notification->getObjectId(), false); $params[] = $this->prepareMessage($announcement['subject']); $notification->setParsedMessage($this->prepareMessage($announcement['message']))->setParsedSubject((string) $l->t('%1$s announced “%2$s”', $params)); return $notification; default: // Unknown subject => Unknown notification => throw throw new \InvalidArgumentException(); } }
/** * @dataProvider dataSetParsedMessageInvalid * @param mixed $message * * @expectedException \InvalidArgumentException */ public function testSetParsedMessageInvalid($message) { $this->notification->setParsedMessage($message); }