Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-11-16 17:52:51 +0300
committerJoas Schilling <nickvergessen@owncloud.com>2015-11-16 17:53:55 +0300
commit2a815a6adbe24675886d3afb5ea085dac6c32b31 (patch)
treeadb666745e21ab636b565aaef34d1cf76d983b28 /tests
parent8d301d8300d7839696b398fde2a547bb6037cb94 (diff)
Add an OCS endpoint to get a single notification
Diffstat (limited to 'tests')
-rw-r--r--tests/controller/EndpointControllerTest.php86
-rw-r--r--tests/lib/HandlerTest.php8
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/controller/EndpointControllerTest.php b/tests/controller/EndpointControllerTest.php
index 0bda457..b85e401 100644
--- a/tests/controller/EndpointControllerTest.php
+++ b/tests/controller/EndpointControllerTest.php
@@ -265,6 +265,92 @@ class EndpointControllerTest extends TestCase {
$this->assertSame(Http::STATUS_NO_CONTENT, $response->getStatusCode());
}
+ public function dataGetNotification() {
+ return [
+ [42, 'username1', ['$notification']],
+ [21, 'username2', ['$notification']],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetNotification
+ * @param int $id
+ * @param string $username
+ */
+ public function testGetNotification($id, $username) {
+ $controller = $this->getController([
+ 'notificationToArray',
+ ], $username);
+
+ $notification = $this->getMockBuilder('OC\Notification\INotification')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->manager->expects($this->once())
+ ->method('hasNotifiers')
+ ->willReturn(true);
+ $this->manager->expects($this->once() )
+ ->method('prepare')
+ ->with($notification)
+ ->willReturn($notification);
+
+ $this->handler->expects($this->once())
+ ->method('getById')
+ ->with($id, $username)
+ ->willReturn($notification);
+
+ $controller->expects($this->exactly(1))
+ ->method('notificationToArray')
+ ->with($id, $notification)
+ ->willReturn('$notification');
+
+ $response = $controller->getNotification(['id' => (string) $id]);
+ $this->assertInstanceOf('OC_OCS_Result', $response);
+
+ $this->assertSame(100, $response->getStatusCode());
+ }
+
+ public function dataGetNotificationNoId() {
+ $notification = $this->getMockBuilder('OC\Notification\INotification')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ return [
+ [false, [], false, null], // No notifiers
+ [true, [], false, null], // No id
+ [true, ['id' => 42], true, null], // Not found in database
+ [true, ['id' => 42], true, $notification], // Not handled on prepare
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetNotificationNoId
+ * @param bool $hasNotifiers
+ * @param array $parameters
+ * @param bool $called
+ * @param null|\OC\Notification\INotification $notification
+ */
+ public function testGetNotificationNoId($hasNotifiers, array $parameters, $called, $notification) {
+ $controller = $this->getController();
+
+ $this->manager->expects($this->once())
+ ->method('hasNotifiers')
+ ->willReturn($hasNotifiers);
+
+ $this->handler->expects($called ? $this->once() : $this->never())
+ ->method('getById')
+ ->willReturn($notification);
+
+ $this->manager->expects($called && $notification ? $this->once() : $this->never())
+ ->method('prepare')
+ ->willThrowException(new \InvalidArgumentException());
+
+ $response = $controller->getNotification($parameters);
+ $this->assertInstanceOf('OC_OCS_Result', $response);
+
+ $this->assertSame(404, $response->getStatusCode());
+ }
+
public function dataDeleteNotification() {
return [
[42, 'username1'],
diff --git a/tests/lib/HandlerTest.php b/tests/lib/HandlerTest.php
index c0c3136..649ce27 100644
--- a/tests/lib/HandlerTest.php
+++ b/tests/lib/HandlerTest.php
@@ -140,10 +140,18 @@ class HandlerTest extends TestCase {
reset($notifications);
$notificationId = key($notifications);
+ // Get with wrong user
+ $getNotification = $this->handler->getById($notificationId, 'test_user2');
+ $this->assertSame(null, $getNotification);
+
// Delete with wrong user
$this->handler->deleteById($notificationId, 'test_user2');
$this->assertSame(1, $this->handler->count($limitedNotification), 'Wrong notification count for user1 after trying to delete for user2');
+ // Get with wrong user
+ $getNotification = $this->handler->getById($notificationId, 'test_user1');
+ $this->assertInstanceOf('OC\Notification\INotification', $getNotification);
+
// Delete and count
$this->handler->deleteById($notificationId, 'test_user1');
$this->assertSame(0, $this->handler->count($limitedNotification), 'Wrong notification count for user1 after deleting');