/** * Remove the notification and prevent rendering, when the update is installed * * @param INotification $notification * @param string $installedVersion * @throws \InvalidArgumentException When the update is already installed */ protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { $this->notificationManager->markProcessed($notification); throw new \InvalidArgumentException(); } }
/** * @dataProvider dataUpdateAlreadyInstalledCheck * * @param string $versionNotification * @param string $versionInstalled * @param bool $exception */ public function testUpdateAlreadyInstalledCheck($versionNotification, $versionInstalled, $exception) { $notifier = $this->getNotifier(); $notification = $this->getMock('OCP\\Notification\\INotification'); $notification->expects($this->once())->method('getObjectId')->willReturn($versionNotification); if ($exception) { $this->notificationManager->expects($this->once())->method('markProcessed')->with($notification); } else { $this->notificationManager->expects($this->never())->method('markProcessed'); } try { $this->invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, $versionInstalled]); $this->assertFalse($exception); } catch (\Exception $e) { $this->assertTrue($exception); $this->assertInstanceOf('InvalidArgumentException', $e); } }
/** * @dataProvider dataDeleteOutdatedNotifications * @param string $app * @param string $version */ public function testDeleteOutdatedNotifications($app, $version) { $notification = $this->getMock('OCP\\Notification\\INotification'); $notification->expects($this->once())->method('setApp')->with('updatenotification')->willReturnSelf(); $notification->expects($this->once())->method('setObject')->with($app, $version)->willReturnSelf(); $this->notificationManager->expects($this->once())->method('createNotification')->willReturn($notification); $this->notificationManager->expects($this->once())->method('markProcessed')->with($notification); $job = $this->getJob(); $this->invokePrivate($job, 'deleteOutdatedNotifications', [$app, $version]); }
public function testGetCount() { /** @var \OCP\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification */ $notification = $this->getMockBuilder('OCP\\Notification\\INotification')->disableOriginalConstructor()->getMock(); /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app */ $app = $this->getMockBuilder('OCP\\Notification\\IApp')->disableOriginalConstructor()->getMock(); $app->expects($this->once())->method('getCount')->with($notification)->willReturn(21); /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app2 */ $app2 = $this->getMockBuilder('OCP\\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)); }
/** * @NoAdminRequired * @NoCSRFRequired * * @param array $parameters * @return \OC_OCS_Result */ public function getNotification(array $parameters) { if (!$this->manager->hasNotifiers()) { return new \OC_OCS_Result(null, Http::STATUS_NOT_FOUND); } if (!isset($parameters['id'])) { return new \OC_OCS_Result(null, HTTP::STATUS_NOT_FOUND); } $id = (int) $parameters['id']; $notification = $this->handler->getById($id, $this->getCurrentUser()); if (!$notification instanceof INotification) { return new \OC_OCS_Result(null, HTTP::STATUS_NOT_FOUND); } $language = $this->config->getUserValue($this->getCurrentUser(), 'core', 'lang', null); try { $notification = $this->manager->prepare($notification, $language); } catch (\InvalidArgumentException $e) { // The app was disabled return new \OC_OCS_Result(null, HTTP::STATUS_NOT_FOUND); } return new \OC_OCS_Result($this->notificationToArray($id, $notification), 100); }
/** * Turn a database row into a INotification * * @param array $row * @return INotification */ protected function notificationFromRow(array $row) { $dateTime = new \DateTime(); $dateTime->setTimestamp((int) $row['timestamp']); $notification = $this->manager->createNotification(); $notification->setApp($row['app'])->setUser($row['user'])->setDateTime($dateTime)->setObject($row['object_type'], $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']); } $actions = (array) json_decode($row['actions'], true); foreach ($actions as $actionData) { $action = $notification->createAction(); $action->setLabel($actionData['label'])->setLink($actionData['link'], $actionData['type']); if (isset($actionData['primary'])) { $action->setPrimary($actionData['primary']); } $notification->addAction($action); } return $notification; }
/** * @param int $remoteShare */ public function processNotification($remoteShare) { $filter = $this->notificationManager->createNotification(); $filter->setApp('files_sharing')->setUser($this->uid)->setObject('remote_share', (int) $remoteShare); $this->notificationManager->markProcessed($filter); }
/** * Delete notifications for old updates * * @param string $app * @param string $version */ protected function deleteOutdatedNotifications($app, $version) { $notification = $this->notificationManager->createNotification(); $notification->setApp('updatenotification')->setObject($app, $version); $this->notificationManager->markProcessed($notification); }