2016-05-09 04:02:07 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-05-09 04:02:07 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Comments\Tests\Unit\Notification;
|
|
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Comments\Activity\Listener as ActivityListener;
|
2024-06-18 08:11:32 -04:00
|
|
|
use OCA\Comments\Listener\CommentsEventListener;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Comments\Notification\Listener as NotificationListener;
|
2016-05-09 04:02:07 -04:00
|
|
|
use OCP\Comments\CommentsEvent;
|
|
|
|
|
use OCP\Comments\IComment;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class EventHandlerTest extends TestCase {
|
2024-08-23 09:10:27 -04:00
|
|
|
/** @var CommentsEventListener */
|
2016-05-09 04:02:07 -04:00
|
|
|
protected $eventHandler;
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var ActivityListener|\PHPUnit\Framework\MockObject\MockObject */
|
2016-10-14 09:36:05 -04:00
|
|
|
protected $activityListener;
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var NotificationListener|\PHPUnit\Framework\MockObject\MockObject */
|
2016-10-14 09:36:05 -04:00
|
|
|
protected $notificationListener;
|
2016-05-09 04:02:07 -04:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2016-05-09 04:02:07 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2016-10-14 09:36:05 -04:00
|
|
|
$this->activityListener = $this->getMockBuilder(ActivityListener::class)
|
2016-05-09 04:02:07 -04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
|
2016-10-14 09:36:05 -04:00
|
|
|
$this->notificationListener = $this->getMockBuilder(NotificationListener::class)
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
|
2024-06-18 08:11:32 -04:00
|
|
|
$this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener);
|
2016-05-09 04:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testNotFiles(): void {
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
|
2016-05-09 04:02:07 -04:00
|
|
|
$comment = $this->getMockBuilder(IComment::class)->getMock();
|
|
|
|
|
$comment->expects($this->once())
|
|
|
|
|
->method('getObjectType')
|
|
|
|
|
->willReturn('smiles');
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
|
2016-05-09 04:02:07 -04:00
|
|
|
$event = $this->getMockBuilder(CommentsEvent::class)
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$event->expects($this->once())
|
|
|
|
|
->method('getComment')
|
|
|
|
|
->willReturn($comment);
|
|
|
|
|
$event->expects($this->never())
|
|
|
|
|
->method('getEvent');
|
|
|
|
|
|
|
|
|
|
$this->eventHandler->handle($event);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 19:10:49 -04:00
|
|
|
public function handledProvider() {
|
|
|
|
|
return [
|
|
|
|
|
[CommentsEvent::EVENT_DELETE],
|
2016-10-12 12:06:22 -04:00
|
|
|
[CommentsEvent::EVENT_UPDATE],
|
|
|
|
|
[CommentsEvent::EVENT_PRE_UPDATE],
|
2016-10-07 19:10:49 -04:00
|
|
|
[CommentsEvent::EVENT_ADD]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider handledProvider
|
|
|
|
|
* @param string $eventType
|
|
|
|
|
*/
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testHandled($eventType): void {
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var IComment|\PHPUnit\Framework\MockObject\MockObject $comment */
|
2016-05-09 04:02:07 -04:00
|
|
|
$comment = $this->getMockBuilder(IComment::class)->getMock();
|
|
|
|
|
$comment->expects($this->once())
|
|
|
|
|
->method('getObjectType')
|
|
|
|
|
->willReturn('files');
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var CommentsEvent|\PHPUnit\Framework\MockObject\MockObject $event */
|
2016-05-09 04:02:07 -04:00
|
|
|
$event = $this->getMockBuilder(CommentsEvent::class)
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$event->expects($this->atLeastOnce())
|
|
|
|
|
->method('getComment')
|
|
|
|
|
->willReturn($comment);
|
|
|
|
|
$event->expects($this->atLeastOnce())
|
|
|
|
|
->method('getEvent')
|
2016-10-07 19:10:49 -04:00
|
|
|
->willReturn($eventType);
|
2016-05-09 04:02:07 -04:00
|
|
|
|
2016-10-14 09:36:05 -04:00
|
|
|
$this->notificationListener->expects($this->once())
|
2016-05-09 04:02:07 -04:00
|
|
|
->method('evaluate')
|
|
|
|
|
->with($event);
|
|
|
|
|
|
2016-10-14 09:36:05 -04:00
|
|
|
$this->activityListener->expects($this->any())
|
2016-05-09 04:02:07 -04:00
|
|
|
->method('commentEvent')
|
|
|
|
|
->with($event);
|
|
|
|
|
|
|
|
|
|
$this->eventHandler->handle($event);
|
|
|
|
|
}
|
|
|
|
|
}
|