Skip to content

Commit

Permalink
EZEE-2081: NotificationService clean up (#2368)
Browse files Browse the repository at this point in the history
* EZEE-2081: Missing backticks around owner_id column

* EZEE-2081: Removed out of date SQL query to eznotification table creation from upgrade notes

* EZEE-2081: Removed unused import from eZ/Publish/SPI/Persistence/Handler

* EZEE-2081: Added \eZ\Publish\API\Repository\Values\Notification\CreateStruct validation

* EZEE-2081: Moved @throws from impl. to \eZ\Publish\API\Repository\NotificationService

* EZEE-2081: Moved NotificationRenderer to eZ\Publish\Core\Notification\Renderer\

* EZEE-2081: Replaced tag ezstudio.notification.renderer with ezpublish.notification.renderer

* EZEE-2081: CS

* EZEE-2081: Applied the CR suggestions
  • Loading branch information
adamwojs authored and Łukasz Serwatka committed Jun 29, 2018
1 parent 61fab10 commit 1c73ffc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
35 changes: 26 additions & 9 deletions Repository/NotificationService.php
Expand Up @@ -12,20 +12,28 @@
use eZ\Publish\API\Repository\Values\Notification\Notification;
use eZ\Publish\API\Repository\Values\Notification\NotificationList;

/**
* Service to manager user notifications. It works in the context of a current User (obtained from
* the PermissionResolver).
*/
interface NotificationService
{
/**
* Get currently logged user notifications.
* @param int $offset
* @param int $limit
*
* @param int $offset the start offset for paging
* @param int $limit the number of notifications returned
*
* @return \eZ\Publish\API\Repository\Values\Notification\NotificationList
*/
public function loadNotifications(int $offset, int $limit): NotificationList;

/**
* @param int $notificationId
* Load single notification (by ID).
*
* @param int $notificationId Notification ID
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*
* @return \eZ\Publish\API\Repository\Values\Notification\Notification
*/
Expand All @@ -35,6 +43,9 @@ public function getNotification(int $notificationId): Notification;
* Mark notification as read so it no longer bother the user.
*
* @param \eZ\Publish\API\Repository\Values\Notification\Notification $notification
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function markNotificationAsRead(Notification $notification): void;

Expand All @@ -53,14 +64,20 @@ public function getPendingNotificationCount(): int;
public function getNotificationCount(): int;

/**
* @param \eZ\Publish\API\Repository\Values\Notification\Notification $notification
*/
public function deleteNotification(Notification $notification): void;

/**
* Creates a new notification.
*
* @param \eZ\Publish\API\Repository\Values\Notification\CreateStruct $createStruct
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*
* @return \eZ\Publish\API\Repository\Values\Notification\Notification
*/
public function createNotification(CreateStruct $createStruct): Notification;

/**
* Deletes a notification.
*
* @param \eZ\Publish\API\Repository\Values\Notification\Notification $notification
*/
public function deleteNotification(Notification $notification): void;
}
42 changes: 42 additions & 0 deletions Repository/Tests/NotificationServiceTest.php
Expand Up @@ -154,4 +154,46 @@ public function testCreateNotification()
$this->assertInstanceOf(Notification::class, $notification);
$this->assertGreaterThan(0, $notification->id);
}

/**
* @covers \eZ\Publish\API\Repository\NotificationService::createNotification()
* @depends testCreateNotification
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function testCreateNotificationThrowsInvalidArgumentExceptionOnMissingOwner()
{
$repository = $this->getRepository();

/* BEGIN: Use Case */
$notificationService = $repository->getNotificationService();

$createStruct = new CreateStruct([
'type' => 'TEST',
]);

// This call will fail because notification owner is not specified
$notificationService->createNotification($createStruct);
/* END: Use Case */
}

/**
* @covers \eZ\Publish\API\Repository\NotificationService::createNotification()
* @depends testCreateNotification
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function testCreateNotificationThrowsInvalidArgumentExceptionOnMissingType()
{
$repository = $this->getRepository();

/* BEGIN: Use Case */
$notificationService = $repository->getNotificationService();

$createStruct = new CreateStruct([
'ownerId' => 14,
]);

// This call will fail because notification type is not specified
$notificationService->createNotification($createStruct);
/* END: Use Case */
}
}

0 comments on commit 1c73ffc

Please sign in to comment.