forked from ezsystems/ezpublish-api
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZEE-2081: Move NotificationBundle into Kernel (#2356)
* EZEE-2081: Move NotificationBundle into Kernel * EZEE-2081: Notification Cache Handler * EZEE-2081: Feature goes into 7.2 * fixup! EZEE-2081: Notification Cache Handler * EZEE-2081: use alias fix * EZEE-2081: Typehints and docblocks fix * EZEE-2081: introduce API Notification value object * EZEE-2081: Impl. cache layer for \eZ\Publish\SPI\Persistence\Notification\Handler * EZEE-2081: Updated database schema * fixup! EZEE-2081: Updated database schema * EZEE-2081: Update Notifications fixes * EZEE-2081: psr-2 fixes * EZEE-2081: wrong return value from createNotification fix * EZEE-2081: Create struct * EZEE-2081: Impl. exception conversion layer for notifications gateway. * EZEE-2081: psr2 fix * EZEE-2081: Impl. unit tests for \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper * EZEE-2081: Slot Notification Service * EZEE-2081: service definition is now public * EZEE-2081: Delete signal added * EZEE-2081: Notification service slot fix * EZEE-2081: after review fixes - missing docblocks and some minor improv * EZEE-2081: Impl. unit tests for SPI Cache, SignalSlot layer, Notification/Handler (partial) * EZEE-2081: Impl. integration tests for NotificationService * fixup! EZEE-2081: Impl. integration tests for NotificationService * EZEE-2081: Impl. tests for \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase * EZEE-2081: Changed type of eznotification.data columny from bytea to text * fixup! EZEE-2081: Changed type of eznotification.data columny from bytea to text * fixup! EZEE-2081: Impl. unit tests for SPI Cache, SignalSlot layer, Notification/Handler (partial) * EZEE-2081: CS
- Loading branch information
Showing
7 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository; | ||
|
||
use eZ\Publish\API\Repository\Values\Notification\CreateStruct; | ||
use eZ\Publish\API\Repository\Values\Notification\Notification; | ||
use eZ\Publish\API\Repository\Values\Notification\NotificationList; | ||
|
||
interface NotificationService | ||
{ | ||
/** | ||
* Get currently logged user notifications. | ||
* @param int $offset | ||
* @param int $limit | ||
* | ||
* @return \eZ\Publish\API\Repository\Values\Notification\NotificationList | ||
*/ | ||
public function loadNotifications(int $offset, int $limit): NotificationList; | ||
|
||
/** | ||
* @param int $notificationId | ||
* | ||
* @return \eZ\Publish\API\Repository\Values\Notification\Notification | ||
*/ | ||
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 | ||
*/ | ||
public function markNotificationAsRead(Notification $notification): void; | ||
|
||
/** | ||
* Get count of unread users notifications. | ||
* | ||
* @return int | ||
*/ | ||
public function getPendingNotificationCount(): int; | ||
|
||
/** | ||
* Get count of total users notifications. | ||
* | ||
* @return int | ||
*/ | ||
public function getNotificationCount(): int; | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\Values\Notification\Notification $notification | ||
*/ | ||
public function deleteNotification(Notification $notification): void; | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\Values\Notification\CreateStruct $createStruct | ||
* | ||
* @return \eZ\Publish\API\Repository\Values\Notification\Notification | ||
*/ | ||
public function createNotification(CreateStruct $createStruct): Notification; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository\Tests; | ||
|
||
use eZ\Publish\API\Repository\Exceptions\NotFoundException; | ||
use eZ\Publish\API\Repository\Values\Notification\CreateStruct; | ||
use eZ\Publish\API\Repository\Values\Notification\Notification; | ||
use eZ\Publish\API\Repository\Values\Notification\NotificationList; | ||
|
||
/** | ||
* Test case for the NotificationService. | ||
* | ||
* @see \eZ\Publish\API\Repository\NotificationService | ||
*/ | ||
class NotificationServiceTest extends BaseTest | ||
{ | ||
/** | ||
* @covers \eZ\Publish\API\Repository\NotificationService::loadNotifications() | ||
*/ | ||
public function testLoadNotifications() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$notificationService = $repository->getNotificationService(); | ||
$notificationList = $notificationService->loadNotifications(0, 25); | ||
/* END: Use Case */ | ||
|
||
$this->assertInstanceOf(NotificationList::class, $notificationList); | ||
$this->assertInternalType('array', $notificationList->items); | ||
$this->assertInternalType('int', $notificationList->totalCount); | ||
$this->assertEquals(5, $notificationList->totalCount); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\NotificationService::getNotification() | ||
*/ | ||
public function testGetNotification() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
$notificationId = $this->generateId('notification', 5); | ||
|
||
/* BEGIN: Use Case */ | ||
$notificationService = $repository->getNotificationService(); | ||
// $notificationId is the ID of an existing notification | ||
$notification = $notificationService->getNotification($notificationId); | ||
/* END: Use Case */ | ||
|
||
$this->assertInstanceOf(Notification::class, $notification); | ||
$this->assertEquals($notificationId, $notification->id); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\NotificationService::markNotificationAsRead() | ||
*/ | ||
public function testMarkNotificationAsRead() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
$notificationId = $this->generateId('notification', 5); | ||
/* BEGIN: Use Case */ | ||
$notificationService = $repository->getNotificationService(); | ||
|
||
$notification = $notificationService->getNotification($notificationId); | ||
$notificationService->markNotificationAsRead($notification); | ||
$notification = $notificationService->getNotification($notificationId); | ||
/* END: Use Case */ | ||
|
||
$this->assertFalse($notification->isPending); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\NotificationService::getPendingNotificationCount() | ||
*/ | ||
public function testGetPendingNotificationCount() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$notificationService = $repository->getNotificationService(); | ||
$notificationPendingCount = $notificationService->getPendingNotificationCount(); | ||
/* END: Use Case */ | ||
|
||
$this->assertEquals(3, $notificationPendingCount); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\NotificationService::getNotificationCount() | ||
*/ | ||
public function testGetNotificationCount() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$notificationService = $repository->getNotificationService(); | ||
$notificationCount = $notificationService->getNotificationCount(); | ||
/* END: Use Case */ | ||
|
||
$this->assertEquals(5, $notificationCount); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\NotificationService::deleteNotification() | ||
*/ | ||
public function testDeleteNotification() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
$notificationId = $this->generateId('notification', 5); | ||
/* BEGIN: Use Case */ | ||
$notificationService = $repository->getNotificationService(); | ||
$notification = $notificationService->getNotification($notificationId); | ||
$notificationService->deleteNotification($notification); | ||
/* END: Use Case */ | ||
|
||
try { | ||
$notificationService->getNotification($notificationId); | ||
$this->fail('Notification ' . $notificationId . ' not deleted.'); | ||
} catch (NotFoundException $e) { | ||
} | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\NotificationService::createNotification() | ||
*/ | ||
public function testCreateNotification() | ||
{ | ||
$repository = $this->getRepository(); | ||
|
||
/* BEGIN: Use Case */ | ||
$notificationService = $repository->getNotificationService(); | ||
$user = $repository->getUserService()->loadUser(14); | ||
|
||
$createStruct = new CreateStruct([ | ||
'ownerId' => $user->id, | ||
'type' => 'TEST', | ||
'data' => [ | ||
'foo' => 'Foo', | ||
'bar' => 'Bar', | ||
'baz' => 'Baz', | ||
], | ||
]); | ||
|
||
$notification = $notificationService->createNotification($createStruct); | ||
/* END: Use Case */ | ||
|
||
$this->assertInstanceOf(Notification::class, $notification); | ||
$this->assertGreaterThan(0, $notification->id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository\Values\Notification; | ||
|
||
use eZ\Publish\API\Repository\Values\ValueObject; | ||
|
||
class CreateStruct extends ValueObject | ||
{ | ||
/** @var int $ownerId */ | ||
public $ownerId; | ||
|
||
/** @var string $type */ | ||
public $type; | ||
|
||
/** @var bool $isPending */ | ||
public $isPending = true; | ||
|
||
/** @var array $data */ | ||
public $data = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository\Values\Notification; | ||
|
||
use eZ\Publish\API\Repository\Values\ValueObject; | ||
|
||
/** | ||
* This class represents a notification value. | ||
* | ||
* @property-read int $id The ID of notification | ||
* @property-read int $ownerId The ID of notification owner | ||
* @property-read bool $isPending True if notification is unreaded | ||
* @property-read string $type Notification type | ||
* @property-read \DateTimeInterface $created Creation date. | ||
* @property-read array $data Optional context data | ||
*/ | ||
class Notification extends ValueObject | ||
{ | ||
/** @var int $id */ | ||
protected $id; | ||
|
||
/** @var int $ownerId */ | ||
protected $ownerId; | ||
|
||
/** @var bool $isPending */ | ||
protected $isPending; | ||
|
||
/** @var string $type */ | ||
protected $type; | ||
|
||
/** @var \DateTimeInterface $created */ | ||
protected $created; | ||
|
||
/** @var array $data */ | ||
protected $data = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository\Values\Notification; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
use eZ\Publish\API\Repository\Values\ValueObject; | ||
|
||
class NotificationList extends ValueObject implements IteratorAggregate | ||
{ | ||
/** @var int */ | ||
public $totalCount = 0; | ||
|
||
/** @var \eZ\Publish\API\Repository\Values\Notification\Notification[] */ | ||
public $items = []; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIterator() | ||
{ | ||
return new ArrayIterator($this->items); | ||
} | ||
} |