diff options
Diffstat (limited to 'tests/lib/Notification/ManagerTest.php')
-rw-r--r-- | tests/lib/Notification/ManagerTest.php | 111 |
1 files changed, 46 insertions, 65 deletions
diff --git a/tests/lib/Notification/ManagerTest.php b/tests/lib/Notification/ManagerTest.php index 400ae3a53ef..cbd76989d24 100644 --- a/tests/lib/Notification/ManagerTest.php +++ b/tests/lib/Notification/ManagerTest.php @@ -2,23 +2,9 @@ declare(strict_types=1); /** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace Test\Notification; @@ -27,12 +13,12 @@ use OC\AppFramework\Bootstrap\Coordinator; use OC\AppFramework\Bootstrap\RegistrationContext; use OC\AppFramework\Bootstrap\ServiceRegistration; use OC\Notification\Manager; -use OCP\AppFramework\Utility\ITimeFactory; use OCP\ICache; use OCP\ICacheFactory; use OCP\IUserManager; use OCP\Notification\IManager; use OCP\Notification\INotification; +use OCP\RichObjectStrings\IRichTextFormatter; use OCP\RichObjectStrings\IValidator; use OCP\Support\Subscription\IRegistry; use PHPUnit\Framework\MockObject\MockObject; @@ -43,16 +29,14 @@ class ManagerTest extends TestCase { /** @var IManager */ protected $manager; - /** @var IValidator|MockObject */ - protected $validator; + protected IValidator&MockObject $validator; + protected IRichTextFormatter&MockObject $richTextFormatter; /** @var IUserManager|MockObject */ protected $userManager; /** @var ICacheFactory|MockObject */ protected $cacheFactory; /** @var ICache|MockObject */ protected $cache; - /** @var ITimeFactory|MockObject */ - protected $timeFactory; /** @var IRegistry|MockObject */ protected $subscriptionRegistry; /** @var LoggerInterface|MockObject */ @@ -66,9 +50,9 @@ class ManagerTest extends TestCase { parent::setUp(); $this->validator = $this->createMock(IValidator::class); + $this->richTextFormatter = $this->createMock(IRichTextFormatter::class); $this->userManager = $this->createMock(IUserManager::class); $this->cache = $this->createMock(ICache::class); - $this->timeFactory = $this->createMock(ITimeFactory::class); $this->subscriptionRegistry = $this->createMock(IRegistry::class); $this->logger = $this->createMock(LoggerInterface::class); @@ -82,10 +66,18 @@ class ManagerTest extends TestCase { $this->coordinator->method('getRegistrationContext') ->willReturn($this->registrationContext); - $this->manager = new Manager($this->validator, $this->userManager, $this->cacheFactory, $this->timeFactory, $this->subscriptionRegistry, $this->logger, $this->coordinator); + $this->manager = new Manager( + $this->validator, + $this->userManager, + $this->cacheFactory, + $this->subscriptionRegistry, + $this->logger, + $this->coordinator, + $this->richTextFormatter, + ); } - public function testRegisterApp() { + public function testRegisterApp(): void { $this->assertEquals([], self::invokePrivate($this->manager, 'getApps')); $this->manager->registerApp(DummyApp::class); @@ -98,7 +90,7 @@ class ManagerTest extends TestCase { $this->assertCount(2, self::invokePrivate($this->manager, 'getApps')); } - public function testRegisterAppInvalid() { + public function testRegisterAppInvalid(): void { $this->manager->registerApp(DummyNotifier::class); $this->logger->expects($this->once()) @@ -106,7 +98,7 @@ class ManagerTest extends TestCase { self::invokePrivate($this->manager, 'getApps'); } - public function testRegisterNotifier() { + public function testRegisterNotifier(): void { $this->assertEquals([], self::invokePrivate($this->manager, 'getNotifiers')); $this->manager->registerNotifierService(DummyNotifier::class); @@ -119,7 +111,7 @@ class ManagerTest extends TestCase { $this->assertCount(2, self::invokePrivate($this->manager, 'getNotifiers')); } - public function testRegisterNotifierBootstrap() { + public function testRegisterNotifierBootstrap(): void { $this->registrationContext->method('getNotifierServices') ->willReturn([ new ServiceRegistration('app', DummyNotifier::class), @@ -129,7 +121,7 @@ class ManagerTest extends TestCase { $this->assertCount(1, self::invokePrivate($this->manager, 'getNotifiers')); } - public function testRegisterNotifierInvalid() { + public function testRegisterNotifierInvalid(): void { $this->manager->registerNotifierService(DummyApp::class); $this->logger->expects($this->once()) @@ -137,13 +129,13 @@ class ManagerTest extends TestCase { self::invokePrivate($this->manager, 'getNotifiers'); } - public function testCreateNotification() { + public function testCreateNotification(): void { $action = $this->manager->createNotification(); - $this->assertInstanceOf('OCP\Notification\INotification', $action); + $this->assertInstanceOf(INotification::class, $action); } - public function testNotify() { - /** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ + public function testNotify(): void { + /** @var INotification|MockObject $notification */ $notification = $this->getMockBuilder(INotification::class) ->disableOriginalConstructor() ->getMock(); @@ -156,12 +148,12 @@ class ManagerTest extends TestCase { $this->validator, $this->userManager, $this->cacheFactory, - $this->timeFactory, $this->subscriptionRegistry, $this->logger, $this->coordinator, + $this->richTextFormatter, ]) - ->setMethods(['getApps']) + ->onlyMethods(['getApps']) ->getMock(); $manager->expects($this->once()) @@ -172,10 +164,10 @@ class ManagerTest extends TestCase { } - public function testNotifyInvalid() { + public function testNotifyInvalid(): void { $this->expectException(\InvalidArgumentException::class); - /** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ + /** @var INotification|MockObject $notification */ $notification = $this->getMockBuilder(INotification::class) ->disableOriginalConstructor() ->getMock(); @@ -188,12 +180,12 @@ class ManagerTest extends TestCase { $this->validator, $this->userManager, $this->cacheFactory, - $this->timeFactory, $this->subscriptionRegistry, $this->logger, $this->coordinator, + $this->richTextFormatter, ]) - ->setMethods(['getApps']) + ->onlyMethods(['getApps']) ->getMock(); $manager->expects($this->never()) @@ -202,8 +194,8 @@ class ManagerTest extends TestCase { $manager->notify($notification); } - public function testMarkProcessed() { - /** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ + public function testMarkProcessed(): void { + /** @var INotification|MockObject $notification */ $notification = $this->getMockBuilder(INotification::class) ->disableOriginalConstructor() ->getMock(); @@ -213,12 +205,12 @@ class ManagerTest extends TestCase { $this->validator, $this->userManager, $this->cacheFactory, - $this->timeFactory, $this->subscriptionRegistry, $this->logger, $this->coordinator, + $this->richTextFormatter, ]) - ->setMethods(['getApps']) + ->onlyMethods(['getApps']) ->getMock(); $manager->expects($this->once()) @@ -228,8 +220,8 @@ class ManagerTest extends TestCase { $manager->markProcessed($notification); } - public function testGetCount() { - /** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ + public function testGetCount(): void { + /** @var INotification|MockObject $notification */ $notification = $this->getMockBuilder(INotification::class) ->disableOriginalConstructor() ->getMock(); @@ -239,12 +231,12 @@ class ManagerTest extends TestCase { $this->validator, $this->userManager, $this->cacheFactory, - $this->timeFactory, $this->subscriptionRegistry, $this->logger, $this->coordinator, + $this->richTextFormatter, ]) - ->setMethods(['getApps']) + ->onlyMethods(['getApps']) ->getMock(); $manager->expects($this->once()) @@ -254,33 +246,22 @@ class ManagerTest extends TestCase { $manager->getCount($notification); } - public function dataIsFairUseOfFreePushService() { + public static function dataIsFairUseOfFreePushService(): array { return [ - // Before 1st March - [1646089199, true, 4999, true], - [1646089199, true, 5000, true], - [1646089199, false, 4999, true], - [1646089199, false, 5000, true], - - // After 1st March - [1646089200, true, 4999, true], - [1646089200, true, 5000, true], - [1646089200, false, 4999, true], - [1646089200, false, 5000, false], + [true, 999, true], + [true, 1000, true], + [false, 999, true], + [false, 1000, false], ]; } /** - * @dataProvider dataIsFairUseOfFreePushService - * @param int $time * @param bool $hasValidSubscription * @param int $userCount * @param bool $isFair */ - public function testIsFairUseOfFreePushService(int $time, bool $hasValidSubscription, int $userCount, bool $isFair): void { - $this->timeFactory->method('getTime') - ->willReturn($time); - + #[\PHPUnit\Framework\Attributes\DataProvider('dataIsFairUseOfFreePushService')] + public function testIsFairUseOfFreePushService(bool $hasValidSubscription, int $userCount, bool $isFair): void { $this->subscriptionRegistry->method('delegateHasValidSubscription') ->willReturn($hasValidSubscription); |