mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
Merge pull request #60137 from nextcloud/carl/commnent-event
fix: Dispatch old comment events
This commit is contained in:
commit
ff07c99e0a
9 changed files with 52 additions and 6 deletions
|
|
@ -13,7 +13,12 @@ namespace OCA\Comments\Listener;
|
|||
use OCA\Comments\Activity\Listener as ActivityListener;
|
||||
use OCA\Comments\Notification\Listener as NotificationListener;
|
||||
use OCP\Comments\CommentsEvent;
|
||||
use OCP\Comments\Events\BeforeCommentUpdatedEvent;
|
||||
use OCP\Comments\Events\CommentAddedEvent;
|
||||
use OCP\Comments\Events\CommentDeletedEvent;
|
||||
use OCP\Comments\Events\CommentUpdatedEvent;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
|
||||
/** @template-implements IEventListener<CommentsEvent|Event> */
|
||||
|
|
@ -21,6 +26,7 @@ class CommentsEventListener implements IEventListener {
|
|||
public function __construct(
|
||||
private ActivityListener $activityListener,
|
||||
private NotificationListener $notificationListener,
|
||||
private IEventDispatcher $eventDispatcher,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -30,6 +36,14 @@ class CommentsEventListener implements IEventListener {
|
|||
return;
|
||||
}
|
||||
|
||||
if ($event instanceof CommentAddedEvent
|
||||
|| $event instanceof CommentUpdatedEvent
|
||||
|| $event instanceof CommentDeletedEvent
|
||||
|| $event instanceof BeforeCommentUpdatedEvent) {
|
||||
// Dispatch the deprecated event name for backward compatibility
|
||||
$this->eventDispatcher->dispatchTyped(new CommentsEvent($event->getEvent(), $event->getComment()));
|
||||
}
|
||||
|
||||
if ($event->getComment()->getObjectType() !== 'files') {
|
||||
// this is a 'files'-specific Handler
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class ListenerTest extends TestCase {
|
|||
protected IShareHelper&MockObject $shareHelper;
|
||||
protected Listener $listener;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,12 +28,14 @@ use Test\TestCase;
|
|||
*/
|
||||
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
|
||||
class ApplicationTest extends TestCase {
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
Server::get(IUserManager::class)->createUser('dummy', '456');
|
||||
Server::get(IUserSession::class)->setUser(Server::get(IUserManager::class)->get('dummy'));
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function tearDown(): void {
|
||||
Server::get(IUserManager::class)->get('dummy')->delete();
|
||||
parent::tearDown();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class CommentersSorterTest extends TestCase {
|
|||
protected ICommentsManager&MockObject $commentsManager;
|
||||
protected CommentersSorter $sorter;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class NotificationsTest extends TestCase {
|
|||
protected IURLGenerator&MockObject $urlGenerator;
|
||||
protected NotificationsController $notificationsController;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ use OCP\Comments\Events\CommentAddedEvent;
|
|||
use OCP\Comments\Events\CommentDeletedEvent;
|
||||
use OCP\Comments\Events\CommentUpdatedEvent;
|
||||
use OCP\Comments\IComment;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
|
|
@ -25,23 +27,22 @@ class EventHandlerTest extends TestCase {
|
|||
protected NotificationListener&MockObject $notificationListener;
|
||||
protected CommentsEventListener $eventHandler;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->activityListener = $this->createMock(ActivityListener::class);
|
||||
$this->notificationListener = $this->createMock(NotificationListener::class);
|
||||
|
||||
$this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener);
|
||||
$this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener, $this->createMock(IEventDispatcher::class));
|
||||
}
|
||||
|
||||
public function testNotFiles(): void {
|
||||
/** @var IComment|MockObject $comment */
|
||||
$comment = $this->createMock(IComment::class);
|
||||
$comment->expects($this->once())
|
||||
->method('getObjectType')
|
||||
->willReturn('smiles');
|
||||
|
||||
/** @var CommentsEvent|MockObject $event */
|
||||
$event = $this->createMock(CommentsEvent::class);
|
||||
$event->expects($this->once())
|
||||
->method('getComment')
|
||||
|
|
@ -61,9 +62,8 @@ class EventHandlerTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'handledProvider')]
|
||||
#[DataProvider(methodName: 'handledProvider')]
|
||||
public function testHandled(string $eventType): void {
|
||||
/** @var IComment|MockObject $comment */
|
||||
$comment = $this->createMock(IComment::class);
|
||||
$comment->expects($this->once())
|
||||
->method('getObjectType')
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class ListenerTest extends TestCase {
|
|||
protected IURLGenerator&MockObject $urlGenerator;
|
||||
protected Listener $listener;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class NotifierTest extends TestCase {
|
|||
protected Notifier $notifier;
|
||||
protected string $lc = 'tlh_KX';
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
|
|
|||
27
psalm.xml
27
psalm.xml
|
|
@ -69,7 +69,32 @@
|
|||
<file name="tests/lib/TestCase.php"/>
|
||||
<file name="tests/lib/Files/Template/*.php"/>
|
||||
<ignoreFiles>
|
||||
<directory name="apps/**/tests"/>
|
||||
<directory name="apps/admin_audit/tests"/>
|
||||
<directory name="apps/cloud_federation_api/tests"/>
|
||||
<directory name="apps/contactsinteraction/tests"/>
|
||||
<directory name="apps/dashboard/tests"/>
|
||||
<directory name="apps/dav/tests"/>
|
||||
<directory name="apps/encryption/tests"/>
|
||||
<directory name="apps/federatedfilesharing/tests"/>
|
||||
<directory name="apps/federation/tests"/>
|
||||
<directory name="apps/files/tests"/>
|
||||
<directory name="apps/files_external/tests"/>
|
||||
<directory name="apps/files_sharing/tests"/>
|
||||
<directory name="apps/files_trashbin/tests"/>
|
||||
<directory name="apps/files_versions/tests"/>
|
||||
<directory name="apps/oauth2/tests"/>
|
||||
<directory name="apps/profile/tests"/>
|
||||
<directory name="apps/provisioning_api/tests"/>
|
||||
<directory name="apps/settings/tests"/>
|
||||
<directory name="apps/sharebymail/tests"/>
|
||||
<directory name="apps/systemtags/tests"/>
|
||||
<directory name="apps/theming/tests"/>
|
||||
<directory name="apps/twofactor_backupcodes/tests"/>
|
||||
<directory name="apps/updatenotification/tests"/>
|
||||
<directory name="apps/user_ldap/tests"/>
|
||||
<directory name="apps/user_status/tests"/>
|
||||
<directory name="apps/webhook_listeners/tests"/>
|
||||
<directory name="apps/workflowengine/tests"/>
|
||||
<directory name="apps/**/composer"/>
|
||||
<directory name="lib/composer"/>
|
||||
<directory name="lib/l10n"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue