mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Keep the old method as a fallback and adjust the tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
6d71e471e1
commit
55f5bc79a1
14 changed files with 240 additions and 432 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,6 @@ class Application extends App {
|
|||
|
||||
public function registerNotifier() {
|
||||
$notificationsManager = $this->getContainer()->getServer()->getNotificationManager();
|
||||
$notificationsManager->registerNotifier(Notifier::class);
|
||||
$notificationsManager->registerNotifierService(Notifier::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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[]
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
56
tests/lib/Notification/DummyApp.php
Normal file
56
tests/lib/Notification/DummyApp.php
Normal file
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
63
tests/lib/Notification/DummyNotifier.php
Normal file
63
tests/lib/Notification/DummyNotifier.php
Normal file
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
|
@ -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([], self::invokePrivate($this->manager, 'getApps'));
|
||||
|
||||
$this->assertEquals([], $this->invokePrivate($this->manager, 'getApps'));
|
||||
$this->manager->registerApp(DummyApp::class);
|
||||
|
||||
$this->manager->registerApp($closure);
|
||||
$this->assertCount(1, self::invokePrivate($this->manager, 'getApps'));
|
||||
$this->assertCount(1, self::invokePrivate($this->manager, 'getApps'));
|
||||
|
||||
$this->assertEquals([$app], $this->invokePrivate($this->manager, 'getApps'));
|
||||
$this->assertEquals([$app], $this->invokePrivate($this->manager, 'getApps'));
|
||||
$this->manager->registerApp(DummyApp::class);
|
||||
|
||||
$this->manager->registerApp($closure);
|
||||
|
||||
$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();
|
||||
$this->manager->registerApp(DummyNotifier::class);
|
||||
|
||||
$closure = function() use ($notifier) {
|
||||
return $notifier;
|
||||
};
|
||||
|
||||
$this->manager->registerApp($closure);
|
||||
|
||||
$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();
|
||||
$this->assertEquals([], self::invokePrivate($this->manager, 'getNotifiers'));
|
||||
|
||||
$closure = function() use ($notifier) {
|
||||
return $notifier;
|
||||
};
|
||||
$this->manager->registerNotifierService(DummyNotifier::class);
|
||||
|
||||
$this->assertEquals([], $this->invokePrivate($this->manager, 'getNotifiers'));
|
||||
$this->assertEquals([], $this->invokePrivate($this->manager, 'listNotifiers'));
|
||||
$this->assertCount(1, self::invokePrivate($this->manager, 'getNotifiers'));
|
||||
$this->assertCount(1, self::invokePrivate($this->manager, 'getNotifiers'));
|
||||
|
||||
$this->manager->registerNotifier($closure, function() {
|
||||
return ['id' => 'test1', 'name' => 'Test One'];
|
||||
});
|
||||
$this->manager->registerNotifierService(DummyNotifier::class);
|
||||
|
||||
$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, 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();
|
||||
$this->manager->registerNotifierService(DummyApp::class);
|
||||
|
||||
$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->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);
|
||||
$manager->expects($this->once())
|
||||
->method('getApps')
|
||||
->willReturn([]);
|
||||
|
||||
$this->manager->registerApp(function() use ($app) {
|
||||
return $app;
|
||||
});
|
||||
$this->manager->registerApp(function() use ($app2) {
|
||||
return $app2;
|
||||
});
|
||||
|
||||
$this->manager->notify($notification);
|
||||
$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()
|
||||
$manager = $this->getMockBuilder(Manager::class)
|
||||
->setConstructorArgs([
|
||||
$this->validator,
|
||||
$this->logger,
|
||||
])
|
||||
->setMethods(['getApps'])
|
||||
->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);
|
||||
$manager->expects($this->never())
|
||||
->method('getApps');
|
||||
|
||||
/** @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()
|
||||
->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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
$manager->expects($this->once())
|
||||
->method('getApps')
|
||||
->willReturn([]);
|
||||
|
||||
$this->manager->registerApp(function() use ($app) {
|
||||
return $app;
|
||||
});
|
||||
$this->manager->registerApp(function() use ($app2) {
|
||||
return $app2;
|
||||
});
|
||||
|
||||
$this->manager->markProcessed($notification);
|
||||
$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);
|
||||
$manager->expects($this->once())
|
||||
->method('getApps')
|
||||
->willReturn([]);
|
||||
|
||||
$this->manager->registerApp(function() use ($app) {
|
||||
return $app;
|
||||
});
|
||||
$this->manager->registerApp(function() use ($app2) {
|
||||
return $app2;
|
||||
});
|
||||
|
||||
$this->assertSame(63, $this->manager->getCount($notification));
|
||||
$manager->getCount($notification);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)]],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue