From 679d357089e5e1c13da0427e646dc1d3dd459ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Wed, 27 Jun 2018 16:02:14 +0200 Subject: [PATCH] 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 --- Repository/NotificationService.php | 66 ++++++++ Repository/Repository.php | 7 + Repository/Tests/NotificationServiceTest.php | 157 ++++++++++++++++++ Repository/Tests/RepositoryTest.php | 17 ++ .../Values/Notification/CreateStruct.php | 26 +++ .../Values/Notification/Notification.php | 42 +++++ .../Values/Notification/NotificationList.php | 30 ++++ 7 files changed, 345 insertions(+) create mode 100644 Repository/NotificationService.php create mode 100644 Repository/Tests/NotificationServiceTest.php create mode 100644 Repository/Values/Notification/CreateStruct.php create mode 100644 Repository/Values/Notification/Notification.php create mode 100644 Repository/Values/Notification/NotificationList.php diff --git a/Repository/NotificationService.php b/Repository/NotificationService.php new file mode 100644 index 000000000..973784755 --- /dev/null +++ b/Repository/NotificationService.php @@ -0,0 +1,66 @@ +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); + } +} diff --git a/Repository/Tests/RepositoryTest.php b/Repository/Tests/RepositoryTest.php index 861860800..b96a4a929 100644 --- a/Repository/Tests/RepositoryTest.php +++ b/Repository/Tests/RepositoryTest.php @@ -9,6 +9,7 @@ namespace eZ\Publish\API\Repository\Tests; use Exception; +use eZ\Publish\API\Repository\NotificationService; use eZ\Publish\API\Repository\Repository; use eZ\Publish\Core\Repository\Values\User\UserReference; @@ -127,6 +128,22 @@ public function testGetUserService() ); } + /** + * Test for the getNotificationService() method. + * + * @group user + * + * @see \eZ\Publish\API\Repository\Repository::getNotificationService() + */ + public function testGetNotificationService() + { + $repository = $this->getRepository(); + $this->assertInstanceOf( + NotificationService::class, + $repository->getNotificationService() + ); + } + /** * Test for the getTrashService() method. * diff --git a/Repository/Values/Notification/CreateStruct.php b/Repository/Values/Notification/CreateStruct.php new file mode 100644 index 000000000..63b8f3e3f --- /dev/null +++ b/Repository/Values/Notification/CreateStruct.php @@ -0,0 +1,26 @@ +items); + } +}