Beispiel #1
0
 /**
  * @param INotification $notification
  * @param string $languageCode The code of the language that should be used to prepare the notification
  * @return INotification
  */
 public function prepare(INotification $notification, $languageCode)
 {
     if ($notification->getApp() !== 'files_sharing') {
         // Not my app => throw
         throw new \InvalidArgumentException();
     }
     // Read the language from the notification
     $l = $this->factory->get('files_sharing', $languageCode);
     switch ($notification->getSubject()) {
         // Deal with known subjects
         case 'remote_share':
             $params = $notification->getSubjectParameters();
             $notification->setParsedSubject((string) $l->t('You received "/%2$s" as a remote share from %1$s', $params));
             // Deal with the actions for a known subject
             foreach ($notification->getActions() as $action) {
                 switch ($action->getLabel()) {
                     case 'accept':
                         $action->setParsedLabel((string) $l->t('Accept'))->setPrimary(true);
                         break;
                     case 'decline':
                         $action->setParsedLabel((string) $l->t('Decline'));
                         break;
                 }
                 $notification->addParsedAction($action);
             }
             return $notification;
         default:
             // Unknown subject => Unknown notification => throw
             throw new \InvalidArgumentException();
     }
 }
Beispiel #2
0
 public function testAddActionSecondParsedPrimary()
 {
     /** @var \OCP\Notification\IAction|\PHPUnit_Framework_MockObject_MockObject $action */
     $action = $this->getMockBuilder('OCP\\Notification\\IAction')->disableOriginalConstructor()->getMock();
     $action->expects($this->exactly(2))->method('isValidParsed')->willReturn(true);
     $action->expects($this->exactly(2))->method('isPrimary')->willReturn(true);
     $this->assertSame($this->notification, $this->notification->addParsedAction($action));
     $this->setExpectedException('\\InvalidArgumentException');
     $this->notification->addParsedAction($action);
 }