aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/comments/tests')
-rw-r--r--apps/comments/tests/Unit/Activity/ListenerTest.php67
-rw-r--r--apps/comments/tests/Unit/AppInfo/ApplicationTest.php58
-rw-r--r--apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php114
-rw-r--r--apps/comments/tests/Unit/Controller/NotificationsTest.php70
-rw-r--r--apps/comments/tests/Unit/EventHandlerTest.php82
-rw-r--r--apps/comments/tests/Unit/Notification/ListenerTest.php120
-rw-r--r--apps/comments/tests/Unit/Notification/NotifierTest.php90
-rw-r--r--apps/comments/tests/js/filespluginSpec.js117
8 files changed, 206 insertions, 512 deletions
diff --git a/apps/comments/tests/Unit/Activity/ListenerTest.php b/apps/comments/tests/Unit/Activity/ListenerTest.php
index 9bd0bcfb60c..675a28a16b1 100644
--- a/apps/comments/tests/Unit/Activity/ListenerTest.php
+++ b/apps/comments/tests/Unit/Activity/ListenerTest.php
@@ -1,26 +1,10 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Tests\Unit\Activity;
@@ -39,30 +23,17 @@ use OCP\Files\Node;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IShareHelper;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ListenerTest extends TestCase {
-
- /** @var Listener */
- protected $listener;
-
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $activityManager;
-
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- protected $session;
-
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $appManager;
-
- /** @var IMountProviderCollection|\PHPUnit\Framework\MockObject\MockObject */
- protected $mountProviderCollection;
-
- /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
- protected $rootFolder;
-
- /** @var IShareHelper|\PHPUnit\Framework\MockObject\MockObject */
- protected $shareHelper;
+ protected IManager&MockObject $activityManager;
+ protected IUserSession&MockObject $session;
+ protected IAppManager&MockObject $appManager;
+ protected IMountProviderCollection&MockObject $mountProviderCollection;
+ protected IRootFolder&MockObject $rootFolder;
+ protected IShareHelper&MockObject $shareHelper;
+ protected Listener $listener;
protected function setUp(): void {
parent::setUp();
@@ -84,9 +55,9 @@ class ListenerTest extends TestCase {
);
}
- public function testCommentEvent() {
+ public function testCommentEvent(): void {
$this->appManager->expects($this->any())
- ->method('isInstalled')
+ ->method('isEnabledForAnyone')
->with('activity')
->willReturn(true);
@@ -95,7 +66,7 @@ class ListenerTest extends TestCase {
->method('getObjectType')
->willReturn('files');
- /** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
+ /** @var CommentsEvent|MockObject $event */
$event = $this->createMock(CommentsEvent::class);
$event->expects($this->any())
->method('getComment')
@@ -104,13 +75,13 @@ class ListenerTest extends TestCase {
->method('getEvent')
->willReturn(CommentsEvent::EVENT_ADD);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $ownerUser */
+ /** @var IUser|MockObject $ownerUser */
$ownerUser = $this->createMock(IUser::class);
$ownerUser->expects($this->any())
->method('getUID')
->willReturn('937393');
- /** @var \PHPUnit\Framework\MockObject\MockObject $mount */
+ /** @var MockObject $mount */
$mount = $this->createMock(ICachedMountFileInfo::class);
$mount->expects($this->any())
->method('getUser')
@@ -152,7 +123,7 @@ class ListenerTest extends TestCase {
->method('getUser')
->willReturn($ownerUser);
- /** @var \PHPUnit\Framework\MockObject\MockObject $activity */
+ /** @var MockObject $activity */
$activity = $this->createMock(IEvent::class);
$activity->expects($this->exactly(count($al['users'])))
->method('setAffectedUser');
diff --git a/apps/comments/tests/Unit/AppInfo/ApplicationTest.php b/apps/comments/tests/Unit/AppInfo/ApplicationTest.php
index 6e3658c0e5b..119db5333b5 100644
--- a/apps/comments/tests/Unit/AppInfo/ApplicationTest.php
+++ b/apps/comments/tests/Unit/AppInfo/ApplicationTest.php
@@ -1,31 +1,24 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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 OCA\Comments\Tests\Unit\AppInfo;
+use OCA\Comments\Activity\Filter;
+use OCA\Comments\Activity\Listener;
+use OCA\Comments\Activity\Provider;
+use OCA\Comments\Activity\Setting;
use OCA\Comments\AppInfo\Application;
+use OCA\Comments\Controller\NotificationsController;
use OCA\Comments\Notification\Notifier;
+use OCP\IUserManager;
+use OCP\IUserSession;
+use OCP\Server;
use Test\TestCase;
/**
@@ -38,29 +31,26 @@ use Test\TestCase;
class ApplicationTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- \OC::$server->getUserManager()->createUser('dummy', '456');
- \OC::$server->getUserSession()->setUser(\OC::$server->getUserManager()->get('dummy'));
+ Server::get(IUserManager::class)->createUser('dummy', '456');
+ Server::get(IUserSession::class)->setUser(Server::get(IUserManager::class)->get('dummy'));
}
protected function tearDown(): void {
- \OC::$server->getUserManager()->get('dummy')->delete();
+ Server::get(IUserManager::class)->get('dummy')->delete();
parent::tearDown();
}
- public function test() {
+ public function test(): void {
$app = new Application();
$c = $app->getContainer();
- // assert service instances in the container are properly setup
- $s = $c->get('NotificationsController');
- $this->assertInstanceOf('OCA\Comments\Controller\Notifications', $s);
-
$services = [
- 'OCA\Comments\Activity\Filter',
- 'OCA\Comments\Activity\Listener',
- 'OCA\Comments\Activity\Provider',
- 'OCA\Comments\Activity\Setting',
- 'OCA\Comments\Notification\Listener',
+ NotificationsController::class,
+ Filter::class,
+ Listener::class,
+ Provider::class,
+ Setting::class,
+ \OCA\Comments\Notification\Listener::class,
Notifier::class,
];
diff --git a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
index fe833e14a3b..4d3392a562d 100644
--- a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
+++ b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php
@@ -1,40 +1,20 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Tests\Unit\Collaboration;
use OCA\Comments\Collaboration\CommentersSorter;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class CommentersSorterTest extends TestCase {
- /** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $commentsManager;
- /** @var CommentersSorter */
- protected $sorter;
+ protected ICommentsManager&MockObject $commentsManager;
+ protected CommentersSorter $sorter;
protected function setUp(): void {
parent::setUp();
@@ -45,10 +25,10 @@ class CommentersSorterTest extends TestCase {
}
/**
- * @dataProvider sortDataProvider
* @param $data
*/
- public function testSort($data) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('sortDataProvider')]
+ public function testSort($data): void {
$commentMocks = [];
foreach ($data['actors'] as $actorType => $actors) {
foreach ($actors as $actorId => $noOfComments) {
@@ -75,38 +55,36 @@ class CommentersSorterTest extends TestCase {
$this->assertEquals($data['expected'], $workArray);
}
- public function sortDataProvider() {
+ public static function sortDataProvider(): array {
return [[
[
#1 – sort properly and otherwise keep existing order
'actors' => ['users' => ['celia' => 3, 'darius' => 7, 'faruk' => 5, 'gail' => 5], 'bots' => ['r2-d2' => 8]],
'input' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'elena']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'elena']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ],
'bots' => [
['value' => ['shareWith' => 'c-3po']],
['value' => ['shareWith' => 'r2-d2']],
]
],
'expected' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'elena']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'elena']],
+ ],
'bots' => [
['value' => ['shareWith' => 'r2-d2']],
['value' => ['shareWith' => 'c-3po']],
@@ -117,32 +95,30 @@ class CommentersSorterTest extends TestCase {
#2 – no commentors, input equals output
'actors' => [],
'input' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'elena']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'elena']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ],
'bots' => [
['value' => ['shareWith' => 'c-3po']],
['value' => ['shareWith' => 'r2-d2']],
]
],
'expected' => [
- 'users' =>
- [
- ['value' => ['shareWith' => 'alice']],
- ['value' => ['shareWith' => 'bob']],
- ['value' => ['shareWith' => 'celia']],
- ['value' => ['shareWith' => 'darius']],
- ['value' => ['shareWith' => 'elena']],
- ['value' => ['shareWith' => 'faruk']],
- ['value' => ['shareWith' => 'gail']],
- ],
+ 'users' => [
+ ['value' => ['shareWith' => 'alice']],
+ ['value' => ['shareWith' => 'bob']],
+ ['value' => ['shareWith' => 'celia']],
+ ['value' => ['shareWith' => 'darius']],
+ ['value' => ['shareWith' => 'elena']],
+ ['value' => ['shareWith' => 'faruk']],
+ ['value' => ['shareWith' => 'gail']],
+ ],
'bots' => [
['value' => ['shareWith' => 'c-3po']],
['value' => ['shareWith' => 'r2-d2']],
diff --git a/apps/comments/tests/Unit/Controller/NotificationsTest.php b/apps/comments/tests/Unit/Controller/NotificationsTest.php
index c21101030e8..04490ca63e8 100644
--- a/apps/comments/tests/Unit/Controller/NotificationsTest.php
+++ b/apps/comments/tests/Unit/Controller/NotificationsTest.php
@@ -1,31 +1,15 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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 OCA\Comments\Tests\Unit\Controller;
-use OCA\Comments\Controller\Notifications;
+use OCA\Comments\Controller\NotificationsController;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\Comments\IComment;
@@ -40,26 +24,16 @@ use OCP\IUser;
use OCP\IUserSession;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class NotificationsTest extends TestCase {
- /** @var Notifications */
- protected $notificationsController;
-
- /** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $commentsManager;
-
- /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
- protected $rootFolder;
-
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- protected $session;
-
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $notificationManager;
-
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- protected $urlGenerator;
+ protected ICommentsManager&MockObject $commentsManager;
+ protected IRootFolder&MockObject $rootFolder;
+ protected IUserSession&MockObject $session;
+ protected IManager&MockObject $notificationManager;
+ protected IURLGenerator&MockObject $urlGenerator;
+ protected NotificationsController $notificationsController;
protected function setUp(): void {
parent::setUp();
@@ -70,7 +44,7 @@ class NotificationsTest extends TestCase {
$this->notificationManager = $this->createMock(IManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
- $this->notificationsController = new Notifications(
+ $this->notificationsController = new NotificationsController(
'comments',
$this->createMock(IRequest::class),
$this->commentsManager,
@@ -81,7 +55,7 @@ class NotificationsTest extends TestCase {
);
}
- public function testViewGuestRedirect() {
+ public function testViewGuestRedirect(): void {
$this->commentsManager->expects($this->never())
->method('get');
@@ -99,10 +73,6 @@ class NotificationsTest extends TestCase {
$this->urlGenerator->expects($this->exactly(2))
->method('linkToRoute')
- ->withConsecutive(
- ['comments.Notifications.view', ['id' => '42']],
- ['core.login.showLoginForm', ['redirect_url' => 'link-to-comment']]
- )
->willReturnMap([
['comments.Notifications.view', ['id' => '42'], 'link-to-comment'],
['core.login.showLoginForm', ['redirect_url' => 'link-to-comment'], 'link-to-login'],
@@ -114,7 +84,7 @@ class NotificationsTest extends TestCase {
$this->assertSame('link-to-login', $response->getRedirectURL());
}
- public function testViewSuccess() {
+ public function testViewSuccess(): void {
$comment = $this->createMock(IComment::class);
$comment->expects($this->any())
->method('getObjectType')
@@ -164,11 +134,11 @@ class NotificationsTest extends TestCase {
$this->assertInstanceOf(RedirectResponse::class, $response);
}
- public function testViewInvalidComment() {
+ public function testViewInvalidComment(): void {
$this->commentsManager->expects($this->any())
->method('get')
->with('42')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->rootFolder->expects($this->never())
->method('getUserFolder');
@@ -192,7 +162,7 @@ class NotificationsTest extends TestCase {
$this->assertInstanceOf(NotFoundResponse::class, $response);
}
- public function testViewNoFile() {
+ public function testViewNoFile(): void {
$comment = $this->createMock(IComment::class);
$comment->expects($this->any())
->method('getObjectType')
diff --git a/apps/comments/tests/Unit/EventHandlerTest.php b/apps/comments/tests/Unit/EventHandlerTest.php
index 619cb31a714..9d26f828d70 100644
--- a/apps/comments/tests/Unit/EventHandlerTest.php
+++ b/apps/comments/tests/Unit/EventHandlerTest.php
@@ -1,71 +1,44 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Tests\Unit\Notification;
use OCA\Comments\Activity\Listener as ActivityListener;
-use OCA\Comments\EventHandler;
+use OCA\Comments\Listener\CommentsEventListener;
use OCA\Comments\Notification\Listener as NotificationListener;
use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class EventHandlerTest extends TestCase {
- /** @var EventHandler */
- protected $eventHandler;
-
- /** @var ActivityListener|\PHPUnit\Framework\MockObject\MockObject */
- protected $activityListener;
-
- /** @var NotificationListener|\PHPUnit\Framework\MockObject\MockObject */
- protected $notificationListener;
+ protected ActivityListener&MockObject $activityListener;
+ protected NotificationListener&MockObject $notificationListener;
+ protected CommentsEventListener $eventHandler;
protected function setUp(): void {
parent::setUp();
- $this->activityListener = $this->getMockBuilder(ActivityListener::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->notificationListener = $this->getMockBuilder(NotificationListener::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->activityListener = $this->createMock(ActivityListener::class);
+ $this->notificationListener = $this->createMock(NotificationListener::class);
- $this->eventHandler = new EventHandler($this->activityListener, $this->notificationListener);
+ $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener);
}
- public function testNotFiles() {
- /** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
- $comment = $this->getMockBuilder(IComment::class)->getMock();
+ public function testNotFiles(): void {
+ /** @var IComment|MockObject $comment */
+ $comment = $this->createMock(IComment::class);
$comment->expects($this->once())
->method('getObjectType')
->willReturn('smiles');
- /** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
- $event = $this->getMockBuilder(CommentsEvent::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var CommentsEvent|MockObject $event */
+ $event = $this->createMock(CommentsEvent::class);
$event->expects($this->once())
->method('getComment')
->willReturn($comment);
@@ -75,7 +48,7 @@ class EventHandlerTest extends TestCase {
$this->eventHandler->handle($event);
}
- public function handledProvider() {
+ public static function handledProvider(): array {
return [
[CommentsEvent::EVENT_DELETE],
[CommentsEvent::EVENT_UPDATE],
@@ -84,21 +57,16 @@ class EventHandlerTest extends TestCase {
];
}
- /**
- * @dataProvider handledProvider
- * @param string $eventType
- */
- public function testHandled($eventType) {
- /** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
- $comment = $this->getMockBuilder(IComment::class)->getMock();
+ #[\PHPUnit\Framework\Attributes\DataProvider('handledProvider')]
+ public function testHandled(string $eventType): void {
+ /** @var IComment|MockObject $comment */
+ $comment = $this->createMock(IComment::class);
$comment->expects($this->once())
->method('getObjectType')
->willReturn('files');
- /** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
- $event = $this->getMockBuilder(CommentsEvent::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var CommentsEvent|MockObject $event */
+ $event = $this->createMock(CommentsEvent::class);
$event->expects($this->atLeastOnce())
->method('getComment')
->willReturn($comment);
diff --git a/apps/comments/tests/Unit/Notification/ListenerTest.php b/apps/comments/tests/Unit/Notification/ListenerTest.php
index b70c00a22cd..356a26f23cd 100644
--- a/apps/comments/tests/Unit/Notification/ListenerTest.php
+++ b/apps/comments/tests/Unit/Notification/ListenerTest.php
@@ -1,27 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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 OCA\Comments\Tests\Unit\Notification;
@@ -32,26 +14,20 @@ use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ListenerTest extends TestCase {
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $notificationManager;
-
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $userManager;
-
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- protected $urlGenerator;
-
- /** @var Listener */
- protected $listener;
+ protected IManager&MockObject $notificationManager;
+ protected IUserManager&MockObject $userManager;
+ protected IURLGenerator&MockObject $urlGenerator;
+ protected Listener $listener;
protected function setUp(): void {
parent::setUp();
- $this->notificationManager = $this->createMock(\OCP\Notification\IManager::class);
- $this->userManager = $this->createMock(\OCP\IUserManager::class);
+ $this->notificationManager = $this->createMock(IManager::class);
+ $this->userManager = $this->createMock(IUserManager::class);
$this->listener = new Listener(
$this->notificationManager,
@@ -59,7 +35,7 @@ class ListenerTest extends TestCase {
);
}
- public function eventProvider() {
+ public static function eventProvider(): array {
return [
[CommentsEvent::EVENT_ADD, 'notify'],
[CommentsEvent::EVENT_UPDATE, 'notify'],
@@ -69,13 +45,13 @@ class ListenerTest extends TestCase {
}
/**
- * @dataProvider eventProvider
* @param string $eventType
* @param string $notificationMethod
*/
- public function testEvaluate($eventType, $notificationMethod) {
- /** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
- $comment = $this->getMockBuilder(IComment::class)->getMock();
+ #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')]
+ public function testEvaluate($eventType, $notificationMethod): void {
+ /** @var IComment|MockObject $comment */
+ $comment = $this->createMock(IComment::class);
$comment->expects($this->any())
->method('getObjectType')
->willReturn('files');
@@ -96,10 +72,8 @@ class ListenerTest extends TestCase {
->method('getId')
->willReturn('1234');
- /** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
- $event = $this->getMockBuilder(CommentsEvent::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var CommentsEvent|MockObject $event */
+ $event = $this->createMock(CommentsEvent::class);
$event->expects($this->once())
->method('getComment')
->willReturn($comment);
@@ -107,8 +81,8 @@ class ListenerTest extends TestCase {
->method(('getEvent'))
->willReturn($eventType);
- /** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
- $notification = $this->getMockBuilder(INotification::class)->getMock();
+ /** @var INotification|MockObject $notification */
+ $notification = $this->createMock(INotification::class);
$notification->expects($this->any())
->method($this->anything())
->willReturn($notification);
@@ -124,26 +98,22 @@ class ListenerTest extends TestCase {
$this->userManager->expects($this->exactly(6))
->method('userExists')
- ->withConsecutive(
- ['foobar'],
- ['barfoo'],
- ['foo@bar.com'],
- ['bar@foo.org@foobar.io'],
- ['23452-4333-54353-2342'],
- ['yolo']
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['foobar', true],
+ ['barfoo', true],
+ ['foo@bar.com', true],
+ ['bar@foo.org@foobar.io', true],
+ ['23452-4333-54353-2342', true],
+ ['yolo', true]
+ ]);
$this->listener->evaluate($event);
}
- /**
- * @dataProvider eventProvider
- * @param string $eventType
- */
- public function testEvaluateNoMentions($eventType) {
- /** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
- $comment = $this->getMockBuilder(IComment::class)->getMock();
+ #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')]
+ public function testEvaluateNoMentions(string $eventType): void {
+ /** @var IComment|MockObject $comment */
+ $comment = $this->createMock(IComment::class);
$comment->expects($this->any())
->method('getObjectType')
->willReturn('files');
@@ -154,10 +124,8 @@ class ListenerTest extends TestCase {
->method('getMentions')
->willReturn([]);
- /** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
- $event = $this->getMockBuilder(CommentsEvent::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var CommentsEvent|MockObject $event */
+ $event = $this->createMock(CommentsEvent::class);
$event->expects($this->once())
->method('getComment')
->willReturn($comment);
@@ -178,9 +146,9 @@ class ListenerTest extends TestCase {
$this->listener->evaluate($event);
}
- public function testEvaluateUserDoesNotExist() {
- /** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
- $comment = $this->getMockBuilder(IComment::class)->getMock();
+ public function testEvaluateUserDoesNotExist(): void {
+ /** @var IComment|MockObject $comment */
+ $comment = $this->createMock(IComment::class);
$comment->expects($this->any())
->method('getObjectType')
->willReturn('files');
@@ -194,10 +162,8 @@ class ListenerTest extends TestCase {
->method('getId')
->willReturn('1234');
- /** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
- $event = $this->getMockBuilder(CommentsEvent::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var CommentsEvent|MockObject $event */
+ $event = $this->createMock(CommentsEvent::class);
$event->expects($this->once())
->method('getComment')
->willReturn($comment);
@@ -205,8 +171,8 @@ class ListenerTest extends TestCase {
->method(('getEvent'))
->willReturn(CommentsEvent::EVENT_ADD);
- /** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */
- $notification = $this->getMockBuilder(INotification::class)->getMock();
+ /** @var INotification|MockObject $notification */
+ $notification = $this->createMock(INotification::class);
$notification->expects($this->any())
->method($this->anything())
->willReturn($notification);
@@ -221,9 +187,7 @@ class ListenerTest extends TestCase {
$this->userManager->expects($this->once())
->method('userExists')
- ->withConsecutive(
- ['foobar']
- )
+ ->with('foobar')
->willReturn(false);
$this->listener->evaluate($event);
diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php
index 9281bb99fe8..37cad0b43df 100644
--- a/apps/comments/tests/Unit/Notification/NotifierTest.php
+++ b/apps/comments/tests/Unit/Notification/NotifierTest.php
@@ -1,28 +1,10 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Comments\Tests\Unit\Notification;
@@ -37,31 +19,23 @@ use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
+use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\INotification;
+use OCP\Notification\UnknownNotificationException;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class NotifierTest extends TestCase {
- /** @var Notifier */
- protected $notifier;
- /** @var IFactory|MockObject */
- protected $l10nFactory;
- /** @var IL10N|MockObject */
- protected $l;
- /** @var IRootFolder|MockObject */
- protected $folder;
- /** @var ICommentsManager|MockObject */
- protected $commentsManager;
- /** @var IURLGenerator|MockObject */
- protected $url;
- /** @var IUserManager|MockObject */
- protected $userManager;
- /** @var INotification|MockObject */
- protected $notification;
- /** @var IComment|MockObject */
- protected $comment;
- /** @var string */
- protected $lc = 'tlh_KX';
+ protected IFactory&MockObject $l10nFactory;
+ protected IL10N&MockObject $l;
+ protected IRootFolder&MockObject $folder;
+ protected ICommentsManager&MockObject $commentsManager;
+ protected IURLGenerator&MockObject $url;
+ protected IUserManager&MockObject $userManager;
+ protected INotification&MockObject $notification;
+ protected IComment&MockObject $comment;
+ protected Notifier $notifier;
+ protected string $lc = 'tlh_KX';
protected function setUp(): void {
parent::setUp();
@@ -91,12 +65,11 @@ class NotifierTest extends TestCase {
$this->comment = $this->createMock(IComment::class);
}
- public function testPrepareSuccess() {
+ public function testPrepareSuccess(): void {
$fileName = 'Gre\'thor.odp';
$displayName = 'Huraga';
- $message = '@Huraga mentioned you in a comment on "Gre\'thor.odp"';
- /** @var Node|MockObject $node */
+ /** @var Node&MockObject $node */
$node = $this->createMock(Node::class);
$node
->expects($this->atLeastOnce())
@@ -209,9 +182,8 @@ class NotifierTest extends TestCase {
$this->notifier->prepare($this->notification, $this->lc);
}
- public function testPrepareSuccessDeletedUser() {
+ public function testPrepareSuccessDeletedUser(): void {
$fileName = 'Gre\'thor.odp';
- $message = 'You were mentioned on "Gre\'thor.odp", in a comment by a user that has since been deleted';
/** @var Node|MockObject $node */
$node = $this->createMock(Node::class);
@@ -255,7 +227,7 @@ class NotifierTest extends TestCase {
$this->notification
->expects($this->once())
->method('setRichSubject')
- ->with('You were mentioned on "{file}", in a comment by a user that has since been deleted', $this->anything())
+ ->with('You were mentioned on "{file}", in a comment by an account that has since been deleted', $this->anything())
->willReturnSelf();
$this->notification
->expects($this->once())
@@ -324,8 +296,8 @@ class NotifierTest extends TestCase {
}
- public function testPrepareDifferentApp() {
- $this->expectException(\InvalidArgumentException::class);
+ public function testPrepareDifferentApp(): void {
+ $this->expectException(UnknownNotificationException::class);
$this->folder
->expects($this->never())
@@ -361,8 +333,8 @@ class NotifierTest extends TestCase {
}
- public function testPrepareNotFound() {
- $this->expectException(\InvalidArgumentException::class);
+ public function testPrepareNotFound(): void {
+ $this->expectException(UnknownNotificationException::class);
$this->folder
->expects($this->never())
@@ -399,8 +371,8 @@ class NotifierTest extends TestCase {
}
- public function testPrepareDifferentSubject() {
- $this->expectException(\InvalidArgumentException::class);
+ public function testPrepareDifferentSubject(): void {
+ $this->expectException(UnknownNotificationException::class);
$displayName = 'Huraga';
@@ -456,8 +428,8 @@ class NotifierTest extends TestCase {
}
- public function testPrepareNotFiles() {
- $this->expectException(\InvalidArgumentException::class);
+ public function testPrepareNotFiles(): void {
+ $this->expectException(UnknownNotificationException::class);
$displayName = 'Huraga';
@@ -514,8 +486,8 @@ class NotifierTest extends TestCase {
}
- public function testPrepareUnresolvableFileID() {
- $this->expectException(\OCP\Notification\AlreadyProcessedException::class);
+ public function testPrepareUnresolvableFileID(): void {
+ $this->expectException(AlreadyProcessedException::class);
$displayName = 'Huraga';
diff --git a/apps/comments/tests/js/filespluginSpec.js b/apps/comments/tests/js/filespluginSpec.js
deleted file mode 100644
index 4230a77874d..00000000000
--- a/apps/comments/tests/js/filespluginSpec.js
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * Copyright (c) 2016 Vincent Petry <pvince81@owncloud.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0-or-later
- *
- * 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/>.
- *
- */
-
-describe('OCA.Comments.FilesPlugin tests', function() {
- var fileList;
- var testFiles;
-
- beforeEach(function() {
- var $content = $('<div id="app-content"></div>');
- $('#testArea').append($content);
- // dummy file list
- var $div = $(
- '<div>' +
- '<table class="files-filestable">' +
- '<thead></thead>' +
- '<tbody class="files-fileList"></tbody>' +
- '</table>' +
- '</div>');
- $('#app-content').append($div);
-
- fileList = new OCA.Files.FileList($div);
- OCA.Comments.FilesPlugin.attach(fileList);
-
- testFiles = [{
- id: 1,
- type: 'file',
- name: 'One.txt',
- path: '/subdir',
- mimetype: 'text/plain',
- size: 12,
- permissions: OC.PERMISSION_ALL,
- etag: 'abc',
- shareOwner: 'User One',
- isShareMountPoint: false,
- commentsUnread: 3
- }];
- });
- afterEach(function() {
- fileList.destroy();
- fileList = null;
- });
-
- describe('Comment icon', function() {
- it('does not render icon when no unread comments available', function() {
- testFiles[0].commentsUnread = 0;
- fileList.setFiles(testFiles);
- var $tr = fileList.findFileEl('One.txt');
- expect($tr.find('.action-comment').length).toEqual(0);
- });
- it('renders comment icon and extra data', function() {
- var $action, $tr;
- fileList.setFiles(testFiles);
- $tr = fileList.findFileEl('One.txt');
- $action = $tr.find('.action-comment');
- expect($action.length).toEqual(1);
- expect($action.hasClass('permanent')).toEqual(true);
-
- expect($tr.attr('data-comments-unread')).toEqual('3');
- });
- it('clicking icon opens sidebar', function() {
- var sidebarTabStub = sinon.stub(OCA.Files.Sidebar, 'setActiveTab');
- var sidebarStub = sinon.stub(OCA.Files.Sidebar, 'open');
- var $action, $tr;
- fileList.setFiles(testFiles);
- $tr = fileList.findFileEl('One.txt');
- $action = $tr.find('.action-comment');
- $action.click();
-
- expect(sidebarTabStub.calledOnce).toEqual(true);
- expect(sidebarTabStub.lastCall.args[0]).toEqual('comments');
- expect(sidebarStub.calledOnce).toEqual(true);
- expect(sidebarStub.lastCall.args[0]).toEqual('/subdir/One.txt');
- });
- });
- describe('elementToFile', function() {
- it('returns comment count', function() {
- fileList.setFiles(testFiles);
- var $tr = fileList.findFileEl('One.txt');
- var data = fileList.elementToFile($tr);
- expect(data.commentsUnread).toEqual(3);
- });
- it('does not set comment count when not set', function() {
- delete testFiles[0].commentsUnread;
- fileList.setFiles(testFiles);
- var $tr = fileList.findFileEl('One.txt');
- var data = fileList.elementToFile($tr);
- expect(data.commentsUnread).not.toBeDefined();
- });
- it('does not set comment count when zero', function() {
- testFiles[0].commentsUnread = 0;
- fileList.setFiles(testFiles);
- var $tr = fileList.findFileEl('One.txt');
- var data = fileList.elementToFile($tr);
- expect(data.commentsUnread).not.toBeDefined();
- });
- });
-});