summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-01-21 09:49:37 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2016-01-22 08:47:21 +0100
commit3cca8498cbbd4f04fea3db06976707fbfa13c7aa (patch)
treec7886cf2892395f0b09f2a908d0ced2f78492b36 /tests
parent50b303f3add4cc7ff8747f0e0fc4d0ac885fcd76 (diff)
downloadnextcloud-server-3cca8498cbbd4f04fea3db06976707fbfa13c7aa.tar.gz
nextcloud-server-3cca8498cbbd4f04fea3db06976707fbfa13c7aa.zip
Make it possible to get a list of notifiers for a potential settings page
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/notification/managertest.php79
1 files changed, 76 insertions, 3 deletions
diff --git a/tests/lib/notification/managertest.php b/tests/lib/notification/managertest.php
index fa2a0586f90..1f411bc74ee 100644
--- a/tests/lib/notification/managertest.php
+++ b/tests/lib/notification/managertest.php
@@ -82,15 +82,23 @@ class ManagerTest extends TestCase {
};
$this->assertEquals([], $this->invokePrivate($this->manager, 'getNotifiers'));
+ $this->assertEquals([], $this->invokePrivate($this->manager, 'listNotifiers'));
- $this->manager->registerNotifier($closure);
+ $this->manager->registerNotifier($closure, function() {
+ return ['id' => 'test1', 'name' => 'Test One'];
+ });
$this->assertEquals([$notifier], $this->invokePrivate($this->manager, 'getNotifiers'));
+ $this->assertEquals(['test1' => 'Test One'], $this->invokePrivate($this->manager, 'listNotifiers'));
$this->assertEquals([$notifier], $this->invokePrivate($this->manager, 'getNotifiers'));
+ $this->assertEquals(['test1' => 'Test One'], $this->invokePrivate($this->manager, 'listNotifiers'));
- $this->manager->registerNotifier($closure);
+ $this->manager->registerNotifier($closure, function() {
+ return ['id' => 'test2', 'name' => 'Test Two'];
+ });
$this->assertEquals([$notifier, $notifier], $this->invokePrivate($this->manager, 'getNotifiers'));
+ $this->assertEquals(['test1' => 'Test One', 'test2' => 'Test Two'], $this->invokePrivate($this->manager, 'listNotifiers'));
}
/**
@@ -105,11 +113,68 @@ class ManagerTest extends TestCase {
return $app;
};
- $this->manager->registerNotifier($closure);
+ $this->manager->registerNotifier($closure, function() {
+ return ['id' => 'test1', 'name' => 'Test One'];
+ });
$this->invokePrivate($this->manager, 'getNotifiers');
}
+ public function dataRegisterNotifierInfoInvalid() {
+ return [
+ [null],
+ ['No array'],
+ [['id' => 'test1', 'name' => 'Test One', 'size' => 'Invalid']],
+ [['no-id' => 'test1', 'name' => 'Test One']],
+ [['id' => 'test1', 'no-name' => 'Test One']],
+ ];
+ }
+
+ /**
+ * @dataProvider dataRegisterNotifierInfoInvalid
+ * @expectedException \InvalidArgumentException
+ * @param mixed $data
+ */
+ public function testRegisterNotifierInfoInvalid($data) {
+ $app = $this->getMockBuilder('OC\Notification\IApp')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $closure = function() use ($app) {
+ return $app;
+ };
+
+ $this->manager->registerNotifier($closure, function() use ($data) {
+ return $data;
+ });
+
+ $this->manager->listNotifiers();
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage The given notifier ID test1 is already in use
+ */
+ public function testRegisterNotifierInfoDuplicate() {
+ $app = $this->getMockBuilder('OC\Notification\IApp')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $closure = function() use ($app) {
+ return $app;
+ };
+
+ $this->manager->registerNotifier($closure, function() {
+ return ['id' => 'test1', 'name' => 'Test One'];
+ });
+
+ $this->manager->registerNotifier($closure, function() {
+ return ['id' => 'test1', 'name' => 'Test One'];
+ });
+
+ $this->manager->listNotifiers();
+ }
+
public function testCreateNotification() {
$action = $this->manager->createNotification();
$this->assertInstanceOf('OC\Notification\INotification', $action);
@@ -201,9 +266,13 @@ class ManagerTest extends TestCase {
$this->manager->registerNotifier(function() use ($notifier) {
return $notifier;
+ }, function() {
+ return ['id' => 'test1', 'name' => 'Test One'];
});
$this->manager->registerNotifier(function() use ($notifier2) {
return $notifier2;
+ }, function() {
+ return ['id' => 'test2', 'name' => 'Test Two'];
});
$this->assertEquals($notification2, $this->manager->prepare($notification, 'en'));
@@ -232,6 +301,8 @@ class ManagerTest extends TestCase {
$this->manager->registerNotifier(function() use ($notifier) {
return $notifier;
+ }, function() {
+ return ['id' => 'test1', 'name' => 'Test One'];
});
$this->manager->prepare($notification, 'de');
@@ -257,6 +328,8 @@ class ManagerTest extends TestCase {
$this->manager->registerNotifier(function() use ($notifier) {
return $notifier;
+ }, function() {
+ return ['id' => 'test1', 'name' => 'Test One'];
});
$this->assertEquals($notification, $this->manager->prepare($notification, 'de'));