/**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @return JSONResponse
  */
 public function get()
 {
     // When there are no apps registered that use the notifications
     // We stop polling for them.
     if (!$this->manager->hasNotifiers()) {
         $response = new Response();
         $response->setStatus(Http::STATUS_NO_CONTENT);
         return $response;
     }
     $filter = $this->manager->createNotification();
     $filter->setUser($this->user);
     $language = $this->config->getUserValue($this->user, 'core', 'lang', null);
     $notifications = $this->handler->get($filter);
     $data = [];
     $notificationIds = [];
     foreach ($notifications as $notificationId => $notification) {
         try {
             $notification = $this->manager->prepare($notification, $language);
         } catch (\InvalidArgumentException $e) {
             // The app was disabled, skip the notification
             continue;
         }
         $notificationIds[] = $notificationId;
         $data[] = $this->notificationToArray($notificationId, $notification);
     }
     $response = new JSONResponse($data);
     $response->setETag($this->generateEtag($notificationIds));
     return $response;
 }
 /**
  * @return \OC_OCS_Result
  */
 public function disableMonthly()
 {
     $this->jobList->remove('OCA\\PopularityContestClient\\MonthlyReport');
     $notification = $this->manager->createNotification();
     $notification->setApp('popularitycontestclient');
     $this->manager->markProcessed($notification);
     return new \OC_OCS_Result();
 }
 public function testRegisterApp()
 {
     $this->manager->expects($this->once())->method('registerApp')->willReturnCallback(function ($closure) {
         $this->assertInstanceOf('\\Closure', $closure);
         $navigation = $closure();
         $this->assertInstanceOf('\\OCA\\Notifications\\App', $navigation);
     });
     include __DIR__ . '/../../appinfo/app.php';
 }
 public function testCreatePublicity()
 {
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('setApp')->with('announcementcenter')->willReturnSelf();
     $event->expects($this->once())->method('setType')->with('announcementcenter')->willReturnSelf();
     $event->expects($this->once())->method('setAuthor')->with('author')->willReturnSelf();
     $event->expects($this->once())->method('setTimestamp')->with(1337)->willReturnSelf();
     $event->expects($this->once())->method('setSubject')->with('announcementsubject#10', ['author'])->willReturnSelf();
     $event->expects($this->once())->method('setMessage')->with('announcementmessage#10', ['author'])->willReturnSelf();
     $event->expects($this->once())->method('setObject')->with('announcement', 10)->willReturnSelf();
     $event->expects($this->exactly(5))->method('setAffectedUser')->willReturnSelf();
     $notification = $this->getMockBuilder('OC\\Notification\\INotification')->disableOriginalConstructor()->getMock();
     $notification->expects($this->once())->method('setApp')->with('announcementcenter')->willReturnSelf();
     $dateTime = new \DateTime();
     $dateTime->setTimestamp(1337);
     $notification->expects($this->once())->method('setDateTime')->with($dateTime)->willReturnSelf();
     $notification->expects($this->once())->method('setSubject')->with('announced', ['author'])->willReturnSelf();
     $notification->expects($this->once())->method('setObject')->with('announcement', 10)->willReturnSelf();
     $notification->expects($this->once())->method('setLink')->willReturnSelf();
     $notification->expects($this->exactly(4))->method('setUser')->willReturnSelf();
     $controller = $this->getController();
     $this->activityManager->expects($this->once())->method('generateEvent')->willReturn($event);
     $this->notificationManager->expects($this->once())->method('createNotification')->willReturn($notification);
     $this->userManager->expects($this->once())->method('search')->with('')->willReturn([$this->getUserMock('author', 'User One'), $this->getUserMock('u2', 'User Two'), $this->getUserMock('u3', 'User Three'), $this->getUserMock('u4', 'User Four'), $this->getUserMock('u5', 'User Five')]);
     $this->activityManager->expects($this->exactly(5))->method('publish');
     $this->notificationManager->expects($this->exactly(4))->method('notify');
     $this->invokePrivate($controller, 'createPublicity', [10, 'author', 1337]);
 }
 public function testGetNoNotifiers()
 {
     $controller = $this->getController();
     $this->manager->expects($this->once())->method('hasNotifiers')->willReturn(false);
     $response = $controller->get();
     $this->assertInstanceOf('OCP\\AppFramework\\Http\\Response', $response);
     $this->assertSame(Http::STATUS_NO_CONTENT, $response->getStatus());
 }
 /**
  * @param int $id
  * @param string $authorId
  * @param int $timeStamp
  */
 protected function createPublicity($id, $authorId, $timeStamp)
 {
     $users = $this->userManager->search('');
     $event = $this->activityManager->generateEvent();
     $event->setApp('announcementcenter')->setType('announcementcenter')->setAuthor($authorId)->setTimestamp($timeStamp)->setSubject('announcementsubject#' . $id, [$authorId])->setMessage('announcementmessage#' . $id, [$authorId])->setObject('announcement', $id);
     $dateTime = new \DateTime();
     $dateTime->setTimestamp($timeStamp);
     $notification = $this->notificationManager->createNotification();
     $notification->setApp('announcementcenter')->setDateTime($dateTime)->setObject('announcement', $id)->setSubject('announced', [$authorId])->setLink($this->urlGenerator->linkToRoute('announcementcenter.page.index'));
     foreach ($users as $user) {
         $event->setAffectedUser($user->getUID());
         $this->activityManager->publish($event);
         if ($authorId !== $user->getUID()) {
             $notification->setUser($user->getUID());
             $this->notificationManager->notify($notification);
         }
     }
 }
Exemple #7
0
 public function testGetCount()
 {
     /** @var \OC\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification */
     $notification = $this->getMockBuilder('OC\\Notification\\INotification')->disableOriginalConstructor()->getMock();
     /** @var \OC\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app */
     $app = $this->getMockBuilder('OC\\Notification\\IApp')->disableOriginalConstructor()->getMock();
     $app->expects($this->once())->method('getCount')->with($notification)->willReturn(21);
     /** @var \OC\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app2 */
     $app2 = $this->getMockBuilder('OC\\Notification\\IApp')->disableOriginalConstructor()->getMock();
     $app2->expects($this->once())->method('getCount')->with($notification)->willReturn(42);
     $this->manager->registerApp(function () use($app) {
         return $app;
     });
     $this->manager->registerApp(function () use($app2) {
         return $app2;
     });
     $this->assertSame(63, $this->manager->getCount($notification));
 }
 /**
  * Turn a database row into a INotification
  *
  * @param array $row
  * @return INotification
  */
 protected function notificationFromRow(array $row)
 {
     $notification = $this->manager->createNotification();
     $notification->setApp($row['app'])->setUser($row['user'])->setTimestamp((int) $row['timestamp'])->setObject($row['object_type'], (int) $row['object_id'])->setSubject($row['subject'], (array) json_decode($row['subject_parameters'], true));
     if ($row['message'] !== '') {
         $notification->setMessage($row['message'], (array) json_decode($row['message_parameters'], true));
     }
     if ($row['link'] !== '') {
         $notification->setLink($row['link']);
     }
     if ($row['icon'] !== '') {
         $notification->setIcon($row['icon']);
     }
     $actions = (array) json_decode($row['actions'], true);
     foreach ($actions as $actionData) {
         $action = $notification->createAction();
         $action->setLabel($actionData['label'])->setLink($actionData['link'], $actionData['type']);
         if ($actionData['icon']) {
             $action->setIcon($actionData['icon']);
         }
         $notification->addAction($action);
     }
     return $notification;
 }
Exemple #9
0
 /**
  * @param int $remoteShare
  */
 protected function scrapNotification($remoteShare)
 {
     $filter = $this->notificationManager->createNotification();
     $filter->setApp('files_sharing')->setUser($this->uid)->setObject('remote_share', (int) $remoteShare);
     $this->notificationManager->markProcessed($filter);
 }