summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/comments/lib/EventHandler.php21
-rw-r--r--apps/comments/tests/Unit/EventHandlerTest.php22
2 files changed, 36 insertions, 7 deletions
diff --git a/apps/comments/lib/EventHandler.php b/apps/comments/lib/EventHandler.php
index a32bb8ffa71..6692ccc520d 100644
--- a/apps/comments/lib/EventHandler.php
+++ b/apps/comments/lib/EventHandler.php
@@ -53,12 +53,20 @@ class EventHandler implements ICommentsEventHandler {
return;
}
- if( $event->getEvent() === CommentsEvent::EVENT_ADD
+ $eventType = $event->getEvent();
+ if( $eventType === CommentsEvent::EVENT_ADD
&& $event instanceof CommentsEvent
) {
$this->onAdd($event);
return;
}
+
+ if( $eventType === CommentsEvent::EVENT_DELETE
+ && $event instanceof CommentsEvent
+ ) {
+ $this->onDelete($event);
+ return;
+ }
}
/**
@@ -75,4 +83,15 @@ class EventHandler implements ICommentsEventHandler {
$activityListener = $c->query(ActivityListener::class);
$activityListener->commentEvent($event);
}
+
+ /**
+ * @param CommentsEvent $event
+ */
+ private function onDelete(CommentsEvent $event) {
+ $c = $this->app->getContainer();
+
+ /** @var NotificationListener $notificationListener */
+ $notificationListener = $c->query(NotificationListener::class);
+ $notificationListener->evaluate($event);
+ }
}
diff --git a/apps/comments/tests/Unit/EventHandlerTest.php b/apps/comments/tests/Unit/EventHandlerTest.php
index 7a630329974..21b701ea8cc 100644
--- a/apps/comments/tests/Unit/EventHandlerTest.php
+++ b/apps/comments/tests/Unit/EventHandlerTest.php
@@ -71,14 +71,13 @@ class EventHandlerTest extends TestCase {
public function notHandledProvider() {
return [
- [CommentsEvent::EVENT_DELETE],
[CommentsEvent::EVENT_UPDATE]
];
}
/**
* @dataProvider notHandledProvider
- * @param $eventType
+ * @param string $eventType
*/
public function testNotHandled($eventType) {
/** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */
@@ -103,7 +102,18 @@ class EventHandlerTest extends TestCase {
$this->eventHandler->handle($event);
}
- public function testHandled() {
+ public function handledProvider() {
+ return [
+ [CommentsEvent::EVENT_DELETE],
+ [CommentsEvent::EVENT_ADD]
+ ];
+ }
+
+ /**
+ * @dataProvider handledProvider
+ * @param string $eventType
+ */
+ public function testHandled($eventType) {
/** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */
$comment = $this->getMockBuilder(IComment::class)->getMock();
$comment->expects($this->once())
@@ -119,7 +129,7 @@ class EventHandlerTest extends TestCase {
->willReturn($comment);
$event->expects($this->atLeastOnce())
->method('getEvent')
- ->willReturn(CommentsEvent::EVENT_ADD);
+ ->willReturn($eventType);
$notificationListener = $this->getMockBuilder(NotificationListener::class)
->disableOriginalConstructor()
@@ -131,13 +141,13 @@ class EventHandlerTest extends TestCase {
$activityListener = $this->getMockBuilder(ActivityListener::class)
->disableOriginalConstructor()
->getMock();
- $activityListener->expects($this->once())
+ $activityListener->expects($this->any())
->method('commentEvent')
->with($event);
/** @var IContainer|\PHPUnit_Framework_MockObject_MockObject $c */
$c = $this->getMockBuilder(IContainer::class)->getMock();
- $c->expects($this->exactly(2))
+ $c->expects($this->atLeastOnce())
->method('query')
->withConsecutive([NotificationListener::class], [ActivityListener::class])
->willReturnOnConsecutiveCalls($notificationListener, $activityListener);