aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-07-16 11:36:32 +0200
committerJoas Schilling <coding@schilljs.com>2019-07-16 11:36:32 +0200
commit55f5bc79a148f065cffa8c97e1867c5814047ff0 (patch)
treef7873ae6cce3d3fa96ea620854e36f2470c25e3a
parent6d71e471e166c30c0b9abe05d36240b9f1556d8e (diff)
downloadnextcloud-server-55f5bc79a148f065cffa8c97e1867c5814047ff0.tar.gz
nextcloud-server-55f5bc79a148f065cffa8c97e1867c5814047ff0.zip
Keep the old method as a fallback and adjust the tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--apps/comments/lib/AppInfo/Application.php2
-rw-r--r--apps/federatedfilesharing/appinfo/app.php2
-rw-r--r--apps/twofactor_backupcodes/lib/AppInfo/Application.php2
-rw-r--r--apps/updatenotification/lib/AppInfo/Application.php2
-rw-r--r--apps/user_ldap/appinfo/app.php2
-rw-r--r--core/Application.php4
-rw-r--r--lib/private/Notification/Manager.php25
-rw-r--r--lib/public/Notification/AlreadyProcessedException.php6
-rw-r--r--lib/public/Notification/IManager.php14
-rw-r--r--tests/lib/Notification/ActionTest.php45
-rw-r--r--tests/lib/Notification/DummyApp.php56
-rw-r--r--tests/lib/Notification/DummyNotifier.php63
-rw-r--r--tests/lib/Notification/ManagerTest.php378
-rw-r--r--tests/lib/Notification/NotificationTest.php77
14 files changed, 243 insertions, 435 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php
index 3d20cbbc169..916345e4a5f 100644
--- a/apps/comments/lib/AppInfo/Application.php
+++ b/apps/comments/lib/AppInfo/Application.php
@@ -76,7 +76,7 @@ class Application extends App {
}
protected function registerNotifier() {
- $this->getContainer()->getServer()->getNotificationManager()->registerNotifier(Notifier::class);
+ $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);
}
protected function registerCommentsEventHandler() {
diff --git a/apps/federatedfilesharing/appinfo/app.php b/apps/federatedfilesharing/appinfo/app.php
index bd46f9824f2..6b273faca80 100644
--- a/apps/federatedfilesharing/appinfo/app.php
+++ b/apps/federatedfilesharing/appinfo/app.php
@@ -29,7 +29,7 @@ $app = new \OCA\FederatedFileSharing\AppInfo\Application();
$eventDispatcher = \OC::$server->getEventDispatcher();
$manager = \OC::$server->getNotificationManager();
-$manager->registerNotifier(Notifier::class);
+$manager->registerNotifierService(Notifier::class);
$federatedShareProvider = $app->getFederatedShareProvider();
diff --git a/apps/twofactor_backupcodes/lib/AppInfo/Application.php b/apps/twofactor_backupcodes/lib/AppInfo/Application.php
index c4e02aaa261..735ee091bd1 100644
--- a/apps/twofactor_backupcodes/lib/AppInfo/Application.php
+++ b/apps/twofactor_backupcodes/lib/AppInfo/Application.php
@@ -74,7 +74,7 @@ class Application extends App {
$container = $this->getContainer();
/** @var IManager $manager */
$manager = $container->query(IManager::class);
- $manager->registerNotifier(Notifier::class);
+ $manager->registerNotifierService(Notifier::class);
}
public function deleteUser($params) {
diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php
index 91b9020d82e..6a1bf719469 100644
--- a/apps/updatenotification/lib/AppInfo/Application.php
+++ b/apps/updatenotification/lib/AppInfo/Application.php
@@ -71,6 +71,6 @@ class Application extends App {
public function registerNotifier() {
$notificationsManager = $this->getContainer()->getServer()->getNotificationManager();
- $notificationsManager->registerNotifier(Notifier::class);
+ $notificationsManager->registerNotifierService(Notifier::class);
}
}
diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php
index 34b850e655d..c6e1208e6ea 100644
--- a/apps/user_ldap/appinfo/app.php
+++ b/apps/user_ldap/appinfo/app.php
@@ -42,7 +42,7 @@ if(count($configPrefixes) > 0) {
$ldapWrapper = new OCA\User_LDAP\LDAP();
$ocConfig = \OC::$server->getConfig();
$notificationManager = \OC::$server->getNotificationManager();
- $notificationManager->registerNotifier(\OCA\User_LDAP\Notification\Notifier::class);
+ $notificationManager->registerNotifierService(\OCA\User_LDAP\Notification\Notifier::class);
$userSession = \OC::$server->getUserSession();
$userPluginManager = \OC::$server->query('LDAPUserPluginManager');
diff --git a/core/Application.php b/core/Application.php
index 3a212f85472..7949cfd6638 100644
--- a/core/Application.php
+++ b/core/Application.php
@@ -65,8 +65,8 @@ class Application extends App {
$eventDispatcher = $server->query(IEventDispatcher::class);
$notificationManager = $server->getNotificationManager();
- $notificationManager->registerNotifier(RemoveLinkSharesNotifier::class);
- $notificationManager->registerNotifier(AuthenticationNotifier::class);
+ $notificationManager->registerNotifierService(RemoveLinkSharesNotifier::class);
+ $notificationManager->registerNotifierService(AuthenticationNotifier::class);
$eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
function (GenericEvent $event) use ($container) {
diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php
index 2ed7aa7c176..9cca86a4bda 100644
--- a/lib/private/Notification/Manager.php
+++ b/lib/private/Notification/Manager.php
@@ -74,12 +74,27 @@ class Manager implements IManager {
}
/**
- * @param string $notifierClass The service must implement INotifier, otherwise a
+ * @param \Closure $service The service must implement INotifier, otherwise a
+ * \InvalidArgumentException is thrown later
+ * @param \Closure $info An array with the keys 'id' and 'name' containing
+ * the app id and the app name
+ * @deprecated 17.0.0 use registerNotifierService instead.
+ * @since 8.2.0 - Parameter $info was added in 9.0.0
+ */
+ public function registerNotifier(\Closure $service, \Closure $info) {
+ $infoData = $info();
+ $this->logger->logException(new \InvalidArgumentException(
+ 'Notifier ' . $infoData['name'] . ' (id: ' . $infoData['id'] . ') is not considered because it is using the old way to register.'
+ ));
+ }
+
+ /**
+ * @param string $notifierService The service must implement INotifier, otherwise a
* \InvalidArgumentException is thrown later
* @since 17.0.0
*/
- public function registerNotifier(string $notifierClass): void {
- $this->notifierClasses[] = $notifierClass;
+ public function registerNotifierService(string $notifierService): void {
+ $this->notifierClasses[] = $notifierService;
}
/**
@@ -111,6 +126,8 @@ class Manager implements IManager {
$this->apps[] = $app;
}
+ $this->appClasses = [];
+
return $this->apps;
}
@@ -143,6 +160,8 @@ class Manager implements IManager {
$this->notifiers[] = $notifier;
}
+ $this->notifierClasses = [];
+
return $this->notifiers;
}
diff --git a/lib/public/Notification/AlreadyProcessedException.php b/lib/public/Notification/AlreadyProcessedException.php
index 3cfe4667d6b..0ccac25f0fb 100644
--- a/lib/public/Notification/AlreadyProcessedException.php
+++ b/lib/public/Notification/AlreadyProcessedException.php
@@ -23,8 +23,14 @@ declare(strict_types=1);
namespace OCP\Notification;
+/**
+ * @since 17.0.0
+ */
class AlreadyProcessedException extends \RuntimeException {
+ /**
+ * @since 17.0.0
+ */
public function __construct() {
parent::__construct('Notification is processed already');
}
diff --git a/lib/public/Notification/IManager.php b/lib/public/Notification/IManager.php
index 262bb121431..af890594d4c 100644
--- a/lib/public/Notification/IManager.php
+++ b/lib/public/Notification/IManager.php
@@ -38,11 +38,21 @@ interface IManager extends IApp, INotifier {
public function registerApp(string $appClass): void;
/**
- * @param string $notifierClass The service must implement INotifier, otherwise a
+ * @param \Closure $service The service must implement INotifier, otherwise a
+ * \InvalidArgumentException is thrown later
+ * @param \Closure $info An array with the keys 'id' and 'name' containing
+ * the app id and the app name
+ * @deprecated 17.0.0 use registerNotifierService instead.
+ * @since 8.2.0 - Parameter $info was added in 9.0.0
+ */
+ public function registerNotifier(\Closure $service, \Closure $info);
+
+ /**
+ * @param string $notifierService The service must implement INotifier, otherwise a
* \InvalidArgumentException is thrown later
* @since 17.0.0
*/
- public function registerNotifier(string $notifierClass): void;
+ public function registerNotifierService(string $notifierService): void;
/**
* @return INotifier[]
diff --git a/tests/lib/Notification/ActionTest.php b/tests/lib/Notification/ActionTest.php
index 74c995280c9..9160ea7a7c3 100644
--- a/tests/lib/Notification/ActionTest.php
+++ b/tests/lib/Notification/ActionTest.php
@@ -55,14 +55,8 @@ class ActionTest extends TestCase {
public function dataSetLabelInvalid() {
return [
- [true],
- [false],
- [0],
- [1],
[''],
[str_repeat('a', 33)],
- [[]],
- [[str_repeat('a', 33)]],
];
}
@@ -96,13 +90,7 @@ class ActionTest extends TestCase {
public function dataSetParsedLabelInvalid() {
return [
- [true],
- [false],
- [0],
- [1],
[''],
- [[]],
- [[str_repeat('a', 33)]],
];
}
@@ -140,23 +128,11 @@ class ActionTest extends TestCase {
public function dataSetLinkInvalid() {
return [
// Invalid link
- [true, 'GET'],
- [false, 'GET'],
- [0, 'GET'],
- [1, 'GET'],
['', 'GET'],
[str_repeat('a', 257), 'GET'],
- [[], 'GET'],
- [[str_repeat('a', 257)], 'GET'],
// Invalid type
['url', 'notGET'],
- ['url', true],
- ['url', false],
- ['url', 0],
- ['url', 1],
- ['url', []],
- ['url', ['GET']],
];
}
@@ -188,27 +164,6 @@ class ActionTest extends TestCase {
$this->assertSame($primary, $this->action->isPrimary());
}
- public function dataSetPrimaryInvalid() {
- return [
- [0],
- [1],
- [''],
- [str_repeat('a', 257)],
- [[]],
- [[str_repeat('a', 257)]],
- ];
- }
-
- /**
- * @dataProvider dataSetPrimaryInvalid
- * @param mixed $primary
- *
- * @expectedException \InvalidArgumentException
- */
- public function testSetPrimaryInvalid($primary) {
- $this->action->setPrimary($primary);
- }
-
public function testIsValid() {
$this->assertFalse($this->action->isValid());
$this->assertFalse($this->action->isValidParsed());
diff --git a/tests/lib/Notification/DummyApp.php b/tests/lib/Notification/DummyApp.php
new file mode 100644
index 00000000000..680fb44d009
--- /dev/null
+++ b/tests/lib/Notification/DummyApp.php
@@ -0,0 +1,56 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Notification;
+
+
+use OCP\Notification\IApp;
+use OCP\Notification\INotification;
+
+class DummyApp implements IApp {
+
+ /**
+ * @param INotification $notification
+ * @throws \InvalidArgumentException When the notification is not valid
+ * @since 9.0.0
+ */
+ public function notify(INotification $notification): void {
+ // TODO: Implement notify() method.
+ }
+
+ /**
+ * @param INotification $notification
+ * @since 9.0.0
+ */
+ public function markProcessed(INotification $notification): void {
+ // TODO: Implement markProcessed() method.
+ }
+
+ /**
+ * @param INotification $notification
+ * @return int
+ * @since 9.0.0
+ */
+ public function getCount(INotification $notification): int {
+ // TODO: Implement getCount() method.
+ }
+}
diff --git a/tests/lib/Notification/DummyNotifier.php b/tests/lib/Notification/DummyNotifier.php
new file mode 100644
index 00000000000..849fb3c275f
--- /dev/null
+++ b/tests/lib/Notification/DummyNotifier.php
@@ -0,0 +1,63 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Notification;
+
+
+use OCP\Notification\AlreadyProcessedException;
+use OCP\Notification\INotification;
+use OCP\Notification\INotifier;
+
+class DummyNotifier implements INotifier {
+
+ /**
+ * Identifier of the notifier, only use [a-z0-9_]
+ *
+ * @return string
+ * @since 17.0.0
+ */
+ public function getID(): string {
+ // TODO: Implement getID() method.
+ }
+
+ /**
+ * Human readable name describing the notifier
+ *
+ * @return string
+ * @since 17.0.0
+ */
+ public function getName(): string {
+ // TODO: Implement getName() method.
+ }
+
+ /**
+ * @param INotification $notification
+ * @param string $languageCode The code of the language that should be used to prepare the notification
+ * @return INotification
+ * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
+ * @since 9.0.0
+ */
+ public function prepare(INotification $notification, string $languageCode): INotification {
+ // TODO: Implement prepare() method.
+ }
+}
diff --git a/tests/lib/Notification/ManagerTest.php b/tests/lib/Notification/ManagerTest.php
index cb6504b67e7..259ac0beefe 100644
--- a/tests/lib/Notification/ManagerTest.php
+++ b/tests/lib/Notification/ManagerTest.php
@@ -22,162 +22,72 @@
namespace Test\Notification;
use OC\Notification\Manager;
+use OCP\ILogger;
use OCP\Notification\IApp;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\RichObjectStrings\IValidator;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ManagerTest extends TestCase {
/** @var IManager */
protected $manager;
+ /** @var IValidator|MockObject */
+ protected $validator;
+ /** @var ILogger|MockObject */
+ protected $logger;
+
public function setUp() {
parent::setUp();
- $validator = $this->createMock(IValidator::class);
- $this->manager = new Manager($validator);
+ $this->validator = $this->createMock(IValidator::class);
+ $this->logger = $this->createMock(ILogger::class);
+ $this->manager = new Manager($this->validator, $this->logger);
}
public function testRegisterApp() {
- $app = $this->getMockBuilder(IApp::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $closure = function() use ($app) {
- return $app;
- };
- $this->assertEquals([], $this->invokePrivate($this->manager, 'getApps'));
+ $this->assertEquals([], self::invokePrivate($this->manager, 'getApps'));
- $this->manager->registerApp($closure);
+ $this->manager->registerApp(DummyApp::class);
- $this->assertEquals([$app], $this->invokePrivate($this->manager, 'getApps'));
- $this->assertEquals([$app], $this->invokePrivate($this->manager, 'getApps'));
+ $this->assertCount(1, self::invokePrivate($this->manager, 'getApps'));
+ $this->assertCount(1, self::invokePrivate($this->manager, 'getApps'));
- $this->manager->registerApp($closure);
+ $this->manager->registerApp(DummyApp::class);
- $this->assertEquals([$app, $app], $this->invokePrivate($this->manager, 'getApps'));
+ $this->assertCount(2, self::invokePrivate($this->manager, 'getApps'));
}
- /**
- * @expectedException \InvalidArgumentException
- */
public function testRegisterAppInvalid() {
- $notifier = $this->getMockBuilder(INotifier::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $closure = function() use ($notifier) {
- return $notifier;
- };
-
- $this->manager->registerApp($closure);
+ $this->manager->registerApp(DummyNotifier::class);
- $this->invokePrivate($this->manager, 'getApps');
+ $this->logger->expects($this->once())
+ ->method('error');
+ self::invokePrivate($this->manager, 'getApps');
}
public function testRegisterNotifier() {
- $notifier = $this->getMockBuilder(INotifier::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $closure = function() use ($notifier) {
- return $notifier;
- };
+ $this->assertEquals([], self::invokePrivate($this->manager, 'getNotifiers'));
- $this->assertEquals([], $this->invokePrivate($this->manager, 'getNotifiers'));
- $this->assertEquals([], $this->invokePrivate($this->manager, 'listNotifiers'));
+ $this->manager->registerNotifierService(DummyNotifier::class);
- $this->manager->registerNotifier($closure, function() {
- return ['id' => 'test1', 'name' => 'Test One'];
- });
+ $this->assertCount(1, self::invokePrivate($this->manager, 'getNotifiers'));
+ $this->assertCount(1, self::invokePrivate($this->manager, 'getNotifiers'));
- $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->registerNotifierService(DummyNotifier::class);
- $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'));
+ $this->assertCount(2, self::invokePrivate($this->manager, 'getNotifiers'));
}
- /**
- * @expectedException \InvalidArgumentException
- */
public function testRegisterNotifierInvalid() {
- $app = $this->getMockBuilder(IApp::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $closure = function() use ($app) {
- return $app;
- };
-
- $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(IApp::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $closure = function() use ($app) {
- return $app;
- };
-
- $this->manager->registerNotifier($closure, function() use ($data) {
- return $data;
- });
+ $this->manager->registerNotifierService(DummyApp::class);
- $this->manager->listNotifiers();
- }
-
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The given notifier ID test1 is already in use
- */
- public function testRegisterNotifierInfoDuplicate() {
- $app = $this->getMockBuilder(IApp::class)
- ->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();
+ $this->logger->expects($this->once())
+ ->method('error');
+ self::invokePrivate($this->manager, 'getNotifiers');
}
public function testCreateNotification() {
@@ -194,30 +104,19 @@ class ManagerTest extends TestCase {
->method('isValid')
->willReturn(true);
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app */
- $app = $this->getMockBuilder(IApp::class)
- ->disableOriginalConstructor()
+ $manager = $this->getMockBuilder(Manager::class)
+ ->setConstructorArgs([
+ $this->validator,
+ $this->logger,
+ ])
+ ->setMethods(['getApps'])
->getMock();
- $app->expects($this->once())
- ->method('notify')
- ->with($notification);
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app2 */
- $app2 = $this->getMockBuilder(IApp::class)
- ->disableOriginalConstructor()
- ->getMock();
- $app2->expects($this->once())
- ->method('notify')
- ->with($notification);
-
- $this->manager->registerApp(function() use ($app) {
- return $app;
- });
- $this->manager->registerApp(function() use ($app2) {
- return $app2;
- });
-
- $this->manager->notify($notification);
+ $manager->expects($this->once())
+ ->method('getApps')
+ ->willReturn([]);
+
+ $manager->notify($notification);
}
/**
@@ -232,127 +131,18 @@ class ManagerTest extends TestCase {
->method('isValid')
->willReturn(false);
- $this->manager->notify($notification);
- }
-
- public function testPrepare() {
- /** @var \OCP\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification */
- $notification = $this->getMockBuilder(INotification::class)
- ->disableOriginalConstructor()
- ->getMock();
- $notification->expects($this->once())
- ->method('isValidParsed')
- ->willReturn(true);
- /** @var \OCP\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification2 */
- $notification2 = $this->getMockBuilder(INotification::class)
- ->disableOriginalConstructor()
- ->getMock();
- $notification2->expects($this->exactly(2))
- ->method('isValidParsed')
- ->willReturn(true);
-
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $notifier */
- $notifier = $this->getMockBuilder(INotifier::class)
- ->disableOriginalConstructor()
- ->getMock();
- $notifier->expects($this->once())
- ->method('prepare')
- ->with($notification, 'en')
- ->willReturnArgument(0);
-
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $notifier2 */
- $notifier2 = $this->getMockBuilder(INotifier::class)
- ->disableOriginalConstructor()
- ->getMock();
- $notifier2->expects($this->once())
- ->method('prepare')
- ->with($notification, 'en')
- ->willReturn($notification2);
-
- $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'));
- }
-
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testPrepareInvalid() {
- /** @var \OCP\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification */
- $notification = $this->getMockBuilder(INotification::class)
- ->disableOriginalConstructor()
- ->getMock();
- $notification->expects($this->once())
- ->method('isValidParsed')
- ->willReturn(false);
-
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $notifier */
- $notifier = $this->getMockBuilder(INotifier::class)
- ->disableOriginalConstructor()
- ->getMock();
- $notifier->expects($this->once())
- ->method('prepare')
- ->with($notification, 'de')
- ->willReturnArgument(0);
-
- $this->manager->registerNotifier(function() use ($notifier) {
- return $notifier;
- }, function() {
- return ['id' => 'test1', 'name' => 'Test One'];
- });
-
- $this->manager->prepare($notification, 'de');
- }
-
- public function testPrepareNotifierThrows() {
- /** @var \OCP\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification */
- $notification = $this->getMockBuilder(INotification::class)
- ->disableOriginalConstructor()
+ $manager = $this->getMockBuilder(Manager::class)
+ ->setConstructorArgs([
+ $this->validator,
+ $this->logger,
+ ])
+ ->setMethods(['getApps'])
->getMock();
- $notification->expects($this->once())
- ->method('isValidParsed')
- ->willReturn(true);
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $notifier */
- $notifier = $this->getMockBuilder(INotifier::class)
- ->disableOriginalConstructor()
- ->getMock();
- $notifier->expects($this->once())
- ->method('prepare')
- ->with($notification, 'de')
- ->willThrowException(new \InvalidArgumentException);
-
- $this->manager->registerNotifier(function() use ($notifier) {
- return $notifier;
- }, function() {
- return ['id' => 'test1', 'name' => 'Test One'];
- });
-
- $this->assertEquals($notification, $this->manager->prepare($notification, 'de'));
- }
+ $manager->expects($this->never())
+ ->method('getApps');
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testPrepareNoNotifier() {
- /** @var \OCP\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification */
- $notification = $this->getMockBuilder(INotification::class)
- ->disableOriginalConstructor()
- ->getMock();
- $notification->expects($this->once())
- ->method('isValidParsed')
- ->willReturn(false);
-
- $this->manager->prepare($notification, 'en');
+ $manager->notify($notification);
}
public function testMarkProcessed() {
@@ -361,30 +151,19 @@ class ManagerTest extends TestCase {
->disableOriginalConstructor()
->getMock();
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app */
- $app = $this->getMockBuilder(IApp::class)
- ->disableOriginalConstructor()
+ $manager = $this->getMockBuilder(Manager::class)
+ ->setConstructorArgs([
+ $this->validator,
+ $this->logger,
+ ])
+ ->setMethods(['getApps'])
->getMock();
- $app->expects($this->once())
- ->method('markProcessed')
- ->with($notification);
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app2 */
- $app2 = $this->getMockBuilder(IApp::class)
- ->disableOriginalConstructor()
- ->getMock();
- $app2->expects($this->once())
- ->method('markProcessed')
- ->with($notification);
-
- $this->manager->registerApp(function() use ($app) {
- return $app;
- });
- $this->manager->registerApp(function() use ($app2) {
- return $app2;
- });
-
- $this->manager->markProcessed($notification);
+ $manager->expects($this->once())
+ ->method('getApps')
+ ->willReturn([]);
+
+ $manager->markProcessed($notification);
}
public function testGetCount() {
@@ -393,31 +172,18 @@ class ManagerTest extends TestCase {
->disableOriginalConstructor()
->getMock();
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app */
- $app = $this->getMockBuilder(IApp::class)
- ->disableOriginalConstructor()
+ $manager = $this->getMockBuilder(Manager::class)
+ ->setConstructorArgs([
+ $this->validator,
+ $this->logger,
+ ])
+ ->setMethods(['getApps'])
->getMock();
- $app->expects($this->once())
- ->method('getCount')
- ->with($notification)
- ->willReturn(21);
- /** @var \OCP\Notification\IApp|\PHPUnit_Framework_MockObject_MockObject $app2 */
- $app2 = $this->getMockBuilder(IApp::class)
- ->disableOriginalConstructor()
- ->getMock();
- $app2->expects($this->once())
- ->method('getCount')
- ->with($notification)
- ->willReturn(42);
-
- $this->manager->registerApp(function() use ($app) {
- return $app;
- });
- $this->manager->registerApp(function() use ($app2) {
- return $app2;
- });
-
- $this->assertSame(63, $this->manager->getCount($notification));
+ $manager->expects($this->once())
+ ->method('getApps')
+ ->willReturn([]);
+
+ $manager->getCount($notification);
}
}
diff --git a/tests/lib/Notification/NotificationTest.php b/tests/lib/Notification/NotificationTest.php
index 7517be715ee..d72c9f62ae0 100644
--- a/tests/lib/Notification/NotificationTest.php
+++ b/tests/lib/Notification/NotificationTest.php
@@ -63,29 +63,6 @@ class NotificationTest extends TestCase {
return $dataSets;
}
- protected function dataInvalidStringType() {
- return [
- [true],
- [false],
- [16412],
- [[]],
- [null],
- ];
- }
-
- protected function dataInvalidInt() {
- return [
- [true],
- [false],
- [''],
- ['a'],
- [str_repeat('a', 256)],
- [[]],
- [['a']],
- [[str_repeat('a', 256)]],
- ];
- }
-
public function dataSetApp() {
return $this->dataValidString(32);
}
@@ -104,10 +81,6 @@ class NotificationTest extends TestCase {
return $this->dataInvalidString(32);
}
- public function dataSetAppInvalidType() {
- return $this->dataInvalidStringType();
- }
-
/**
* @dataProvider dataSetAppInvalid
* @param mixed $app
@@ -118,16 +91,6 @@ class NotificationTest extends TestCase {
$this->notification->setApp($app);
}
- /**
- * @dataProvider dataSetAppInvalidType
- * @param mixed $app
- *
- * @expectedException \TypeError
- */
- public function testSetAppInvalidType($app) {
- $this->notification->setApp($app);
- }
-
public function dataSetUser() {
return $this->dataValidString(64);
@@ -147,10 +110,6 @@ class NotificationTest extends TestCase {
return $this->dataInvalidString(64);
}
- public function dataSetUserInvalidType() {
- return $this->dataInvalidStringType();
- }
-
/**
* @dataProvider dataSetUserInvalid
* @param mixed $user
@@ -161,16 +120,6 @@ class NotificationTest extends TestCase {
$this->notification->setUser($user);
}
- /**
- * @dataProvider dataSetUserInvalidType
- * @param mixed $user
- *
- * @expectedException \TypeError
- */
- public function testSetUserInvalidType($user) {
- $this->notification->setUser($user);
- }
-
public function dataSetDateTime() {
$past = new \DateTime();
$past->sub(new \DateInterval('P1Y'));
@@ -216,48 +165,32 @@ class NotificationTest extends TestCase {
public function dataSetObject() {
return [
- ['a', '21', '21'],
- [str_repeat('a', 64), 42, '42'],
+ ['a', '21'],
+ [str_repeat('a', 64), '42'],
];
}
/**
* @dataProvider dataSetObject
* @param string $type
- * @param int|string $id
- * @param string $exptectedId
+ * @param string $id
*/
- public function testSetObject($type, $id, $exptectedId) {
+ public function testSetObject($type, $id) {
$this->assertSame('', $this->notification->getObjectType());
$this->assertSame('', $this->notification->getObjectId());
$this->assertSame($this->notification, $this->notification->setObject($type, $id));
$this->assertSame($type, $this->notification->getObjectType());
- $this->assertSame($exptectedId, $this->notification->getObjectId());
+ $this->assertSame($id, $this->notification->getObjectId());
}
public function dataSetObjectTypeInvalid() {
return $this->dataInvalidString(64);
}
- /**
- * @dataProvider dataSetObjectTypeInvalid
- * @param mixed $type
- *
- * @expectedException \InvalidArgumentException
- * @expectedMessage 'The given object type is invalid'
- */
- public function testSetObjectTypeInvalid($type) {
- $this->notification->setObject($type, 1337);
- }
-
public function dataSetObjectIdInvalid() {
return [
- [true],
- [false],
[''],
[str_repeat('a', 64 + 1)],
- [[]],
- [[str_repeat('a', 64 + 1)]],
];
}