@@ -10,44 +10,44 @@ |
||
| 10 | 10 | use OCP\IL10N; |
| 11 | 11 | |
| 12 | 12 | class Setting extends ActivitySettings { |
| 13 | - public function __construct( |
|
| 14 | - protected readonly IL10N $l, |
|
| 15 | - ) { |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - public function getIdentifier(): string { |
|
| 19 | - return 'comments'; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - public function getName(): string { |
|
| 23 | - return $this->l->t('<strong>Comments</strong> for files'); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - public function getGroupIdentifier(): string { |
|
| 27 | - return 'files'; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function getGroupName(): string { |
|
| 31 | - return $this->l->t('Files'); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function getPriority(): int { |
|
| 35 | - return 50; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function canChangeStream(): bool { |
|
| 39 | - return true; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function isDefaultEnabledStream(): bool { |
|
| 43 | - return true; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function canChangeMail(): bool { |
|
| 47 | - return true; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function isDefaultEnabledMail(): bool { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 13 | + public function __construct( |
|
| 14 | + protected readonly IL10N $l, |
|
| 15 | + ) { |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + public function getIdentifier(): string { |
|
| 19 | + return 'comments'; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + public function getName(): string { |
|
| 23 | + return $this->l->t('<strong>Comments</strong> for files'); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + public function getGroupIdentifier(): string { |
|
| 27 | + return 'files'; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function getGroupName(): string { |
|
| 31 | + return $this->l->t('Files'); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function getPriority(): int { |
|
| 35 | + return 50; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function canChangeStream(): bool { |
|
| 39 | + return true; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function isDefaultEnabledStream(): bool { |
|
| 43 | + return true; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function canChangeMail(): bool { |
|
| 47 | + return true; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function isDefaultEnabledMail(): bool { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -21,167 +21,167 @@ |
||
| 21 | 21 | use Test\TestCase; |
| 22 | 22 | |
| 23 | 23 | class ListenerTest extends TestCase { |
| 24 | - protected IManager&MockObject $notificationManager; |
|
| 25 | - protected IUserManager&MockObject $userManager; |
|
| 26 | - protected IURLGenerator&MockObject $urlGenerator; |
|
| 27 | - protected Listener $listener; |
|
| 28 | - |
|
| 29 | - protected function setUp(): void { |
|
| 30 | - parent::setUp(); |
|
| 31 | - |
|
| 32 | - $this->notificationManager = $this->createMock(IManager::class); |
|
| 33 | - $this->userManager = $this->createMock(IUserManager::class); |
|
| 34 | - |
|
| 35 | - $this->listener = new Listener( |
|
| 36 | - $this->notificationManager, |
|
| 37 | - $this->userManager |
|
| 38 | - ); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public static function eventProvider(): array { |
|
| 42 | - return [ |
|
| 43 | - ['add', 'notify'], |
|
| 44 | - ['update', 'notify'], |
|
| 45 | - ['pre_update', 'markProcessed'], |
|
| 46 | - ['delete', 'markProcessed'] |
|
| 47 | - ]; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param string $eventType |
|
| 52 | - * @param string $notificationMethod |
|
| 53 | - */ |
|
| 54 | - #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')] |
|
| 55 | - public function testEvaluate(string $eventType, $notificationMethod): void { |
|
| 56 | - /** @var IComment|MockObject $comment */ |
|
| 57 | - $comment = $this->createMock(IComment::class); |
|
| 58 | - $comment->expects($this->any()) |
|
| 59 | - ->method('getObjectType') |
|
| 60 | - ->willReturn('files'); |
|
| 61 | - $comment->expects($this->any()) |
|
| 62 | - ->method('getCreationDateTime') |
|
| 63 | - ->willReturn(new \DateTime()); |
|
| 64 | - $comment->expects($this->once()) |
|
| 65 | - ->method('getMentions') |
|
| 66 | - ->willReturn([ |
|
| 67 | - [ 'type' => 'user', 'id' => 'foobar'], |
|
| 68 | - [ 'type' => 'user', 'id' => 'barfoo'], |
|
| 69 | - [ 'type' => 'user', 'id' => '[email protected]'], |
|
| 70 | - [ 'type' => 'user', 'id' => '[email protected]@foobar.io'], |
|
| 71 | - [ 'type' => 'user', 'id' => '23452-4333-54353-2342'], |
|
| 72 | - [ 'type' => 'user', 'id' => 'yolo'], |
|
| 73 | - ]); |
|
| 74 | - $comment->expects($this->atLeastOnce()) |
|
| 75 | - ->method('getId') |
|
| 76 | - ->willReturn('1234'); |
|
| 77 | - |
|
| 78 | - $event = match ($eventType) { |
|
| 79 | - 'add' => new CommentAddedEvent($comment), |
|
| 80 | - 'pre_update' => new BeforeCommentUpdatedEvent($comment), |
|
| 81 | - 'update' => new CommentUpdatedEvent($comment), |
|
| 82 | - 'delete' => new CommentDeletedEvent($comment), |
|
| 83 | - }; |
|
| 84 | - |
|
| 85 | - /** @var INotification|MockObject $notification */ |
|
| 86 | - $notification = $this->createMock(INotification::class); |
|
| 87 | - $notification->expects($this->any()) |
|
| 88 | - ->method($this->anything()) |
|
| 89 | - ->willReturn($notification); |
|
| 90 | - $notification->expects($this->exactly(6)) |
|
| 91 | - ->method('setUser'); |
|
| 92 | - |
|
| 93 | - $this->notificationManager->expects($this->once()) |
|
| 94 | - ->method('createNotification') |
|
| 95 | - ->willReturn($notification); |
|
| 96 | - $this->notificationManager->expects($this->exactly(6)) |
|
| 97 | - ->method($notificationMethod) |
|
| 98 | - ->with($this->isInstanceOf('\OCP\Notification\INotification')); |
|
| 99 | - |
|
| 100 | - $this->userManager->expects($this->exactly(6)) |
|
| 101 | - ->method('userExists') |
|
| 102 | - ->willReturnMap([ |
|
| 103 | - ['foobar', true], |
|
| 104 | - ['barfoo', true], |
|
| 105 | - ['[email protected]', true], |
|
| 106 | - ['[email protected]@foobar.io', true], |
|
| 107 | - ['23452-4333-54353-2342', true], |
|
| 108 | - ['yolo', true] |
|
| 109 | - ]); |
|
| 110 | - |
|
| 111 | - $this->listener->evaluate($event); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')] |
|
| 115 | - public function testEvaluateNoMentions(string $eventType): void { |
|
| 116 | - /** @var IComment|MockObject $comment */ |
|
| 117 | - $comment = $this->createMock(IComment::class); |
|
| 118 | - $comment->expects($this->any()) |
|
| 119 | - ->method('getObjectType') |
|
| 120 | - ->willReturn('files'); |
|
| 121 | - $comment->expects($this->any()) |
|
| 122 | - ->method('getCreationDateTime') |
|
| 123 | - ->willReturn(new \DateTime()); |
|
| 124 | - $comment->expects($this->once()) |
|
| 125 | - ->method('getMentions') |
|
| 126 | - ->willReturn([]); |
|
| 127 | - |
|
| 128 | - $event = match ($eventType) { |
|
| 129 | - 'add' => new CommentAddedEvent($comment), |
|
| 130 | - 'pre_update' => new BeforeCommentUpdatedEvent($comment), |
|
| 131 | - 'update' => new CommentUpdatedEvent($comment), |
|
| 132 | - 'delete' => new CommentDeletedEvent($comment), |
|
| 133 | - }; |
|
| 134 | - |
|
| 135 | - $this->notificationManager->expects($this->never()) |
|
| 136 | - ->method('createNotification'); |
|
| 137 | - $this->notificationManager->expects($this->never()) |
|
| 138 | - ->method('notify'); |
|
| 139 | - $this->notificationManager->expects($this->never()) |
|
| 140 | - ->method('markProcessed'); |
|
| 141 | - |
|
| 142 | - $this->userManager->expects($this->never()) |
|
| 143 | - ->method('userExists'); |
|
| 144 | - |
|
| 145 | - $this->listener->evaluate($event); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function testEvaluateUserDoesNotExist(): void { |
|
| 149 | - /** @var IComment|MockObject $comment */ |
|
| 150 | - $comment = $this->createMock(IComment::class); |
|
| 151 | - $comment->expects($this->any()) |
|
| 152 | - ->method('getObjectType') |
|
| 153 | - ->willReturn('files'); |
|
| 154 | - $comment->expects($this->any()) |
|
| 155 | - ->method('getCreationDateTime') |
|
| 156 | - ->willReturn(new \DateTime()); |
|
| 157 | - $comment->expects($this->once()) |
|
| 158 | - ->method('getMentions') |
|
| 159 | - ->willReturn([[ 'type' => 'user', 'id' => 'foobar']]); |
|
| 160 | - $comment->expects($this->atLeastOnce()) |
|
| 161 | - ->method('getId') |
|
| 162 | - ->willReturn('1234'); |
|
| 163 | - |
|
| 164 | - $event = new CommentAddedEvent($comment); |
|
| 165 | - |
|
| 166 | - /** @var INotification|MockObject $notification */ |
|
| 167 | - $notification = $this->createMock(INotification::class); |
|
| 168 | - $notification->expects($this->any()) |
|
| 169 | - ->method($this->anything()) |
|
| 170 | - ->willReturn($notification); |
|
| 171 | - $notification->expects($this->never()) |
|
| 172 | - ->method('setUser'); |
|
| 173 | - |
|
| 174 | - $this->notificationManager->expects($this->once()) |
|
| 175 | - ->method('createNotification') |
|
| 176 | - ->willReturn($notification); |
|
| 177 | - $this->notificationManager->expects($this->never()) |
|
| 178 | - ->method('notify'); |
|
| 179 | - |
|
| 180 | - $this->userManager->expects($this->once()) |
|
| 181 | - ->method('userExists') |
|
| 182 | - ->with('foobar') |
|
| 183 | - ->willReturn(false); |
|
| 184 | - |
|
| 185 | - $this->listener->evaluate($event); |
|
| 186 | - } |
|
| 24 | + protected IManager&MockObject $notificationManager; |
|
| 25 | + protected IUserManager&MockObject $userManager; |
|
| 26 | + protected IURLGenerator&MockObject $urlGenerator; |
|
| 27 | + protected Listener $listener; |
|
| 28 | + |
|
| 29 | + protected function setUp(): void { |
|
| 30 | + parent::setUp(); |
|
| 31 | + |
|
| 32 | + $this->notificationManager = $this->createMock(IManager::class); |
|
| 33 | + $this->userManager = $this->createMock(IUserManager::class); |
|
| 34 | + |
|
| 35 | + $this->listener = new Listener( |
|
| 36 | + $this->notificationManager, |
|
| 37 | + $this->userManager |
|
| 38 | + ); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public static function eventProvider(): array { |
|
| 42 | + return [ |
|
| 43 | + ['add', 'notify'], |
|
| 44 | + ['update', 'notify'], |
|
| 45 | + ['pre_update', 'markProcessed'], |
|
| 46 | + ['delete', 'markProcessed'] |
|
| 47 | + ]; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param string $eventType |
|
| 52 | + * @param string $notificationMethod |
|
| 53 | + */ |
|
| 54 | + #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')] |
|
| 55 | + public function testEvaluate(string $eventType, $notificationMethod): void { |
|
| 56 | + /** @var IComment|MockObject $comment */ |
|
| 57 | + $comment = $this->createMock(IComment::class); |
|
| 58 | + $comment->expects($this->any()) |
|
| 59 | + ->method('getObjectType') |
|
| 60 | + ->willReturn('files'); |
|
| 61 | + $comment->expects($this->any()) |
|
| 62 | + ->method('getCreationDateTime') |
|
| 63 | + ->willReturn(new \DateTime()); |
|
| 64 | + $comment->expects($this->once()) |
|
| 65 | + ->method('getMentions') |
|
| 66 | + ->willReturn([ |
|
| 67 | + [ 'type' => 'user', 'id' => 'foobar'], |
|
| 68 | + [ 'type' => 'user', 'id' => 'barfoo'], |
|
| 69 | + [ 'type' => 'user', 'id' => '[email protected]'], |
|
| 70 | + [ 'type' => 'user', 'id' => '[email protected]@foobar.io'], |
|
| 71 | + [ 'type' => 'user', 'id' => '23452-4333-54353-2342'], |
|
| 72 | + [ 'type' => 'user', 'id' => 'yolo'], |
|
| 73 | + ]); |
|
| 74 | + $comment->expects($this->atLeastOnce()) |
|
| 75 | + ->method('getId') |
|
| 76 | + ->willReturn('1234'); |
|
| 77 | + |
|
| 78 | + $event = match ($eventType) { |
|
| 79 | + 'add' => new CommentAddedEvent($comment), |
|
| 80 | + 'pre_update' => new BeforeCommentUpdatedEvent($comment), |
|
| 81 | + 'update' => new CommentUpdatedEvent($comment), |
|
| 82 | + 'delete' => new CommentDeletedEvent($comment), |
|
| 83 | + }; |
|
| 84 | + |
|
| 85 | + /** @var INotification|MockObject $notification */ |
|
| 86 | + $notification = $this->createMock(INotification::class); |
|
| 87 | + $notification->expects($this->any()) |
|
| 88 | + ->method($this->anything()) |
|
| 89 | + ->willReturn($notification); |
|
| 90 | + $notification->expects($this->exactly(6)) |
|
| 91 | + ->method('setUser'); |
|
| 92 | + |
|
| 93 | + $this->notificationManager->expects($this->once()) |
|
| 94 | + ->method('createNotification') |
|
| 95 | + ->willReturn($notification); |
|
| 96 | + $this->notificationManager->expects($this->exactly(6)) |
|
| 97 | + ->method($notificationMethod) |
|
| 98 | + ->with($this->isInstanceOf('\OCP\Notification\INotification')); |
|
| 99 | + |
|
| 100 | + $this->userManager->expects($this->exactly(6)) |
|
| 101 | + ->method('userExists') |
|
| 102 | + ->willReturnMap([ |
|
| 103 | + ['foobar', true], |
|
| 104 | + ['barfoo', true], |
|
| 105 | + ['[email protected]', true], |
|
| 106 | + ['[email protected]@foobar.io', true], |
|
| 107 | + ['23452-4333-54353-2342', true], |
|
| 108 | + ['yolo', true] |
|
| 109 | + ]); |
|
| 110 | + |
|
| 111 | + $this->listener->evaluate($event); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + #[\PHPUnit\Framework\Attributes\DataProvider('eventProvider')] |
|
| 115 | + public function testEvaluateNoMentions(string $eventType): void { |
|
| 116 | + /** @var IComment|MockObject $comment */ |
|
| 117 | + $comment = $this->createMock(IComment::class); |
|
| 118 | + $comment->expects($this->any()) |
|
| 119 | + ->method('getObjectType') |
|
| 120 | + ->willReturn('files'); |
|
| 121 | + $comment->expects($this->any()) |
|
| 122 | + ->method('getCreationDateTime') |
|
| 123 | + ->willReturn(new \DateTime()); |
|
| 124 | + $comment->expects($this->once()) |
|
| 125 | + ->method('getMentions') |
|
| 126 | + ->willReturn([]); |
|
| 127 | + |
|
| 128 | + $event = match ($eventType) { |
|
| 129 | + 'add' => new CommentAddedEvent($comment), |
|
| 130 | + 'pre_update' => new BeforeCommentUpdatedEvent($comment), |
|
| 131 | + 'update' => new CommentUpdatedEvent($comment), |
|
| 132 | + 'delete' => new CommentDeletedEvent($comment), |
|
| 133 | + }; |
|
| 134 | + |
|
| 135 | + $this->notificationManager->expects($this->never()) |
|
| 136 | + ->method('createNotification'); |
|
| 137 | + $this->notificationManager->expects($this->never()) |
|
| 138 | + ->method('notify'); |
|
| 139 | + $this->notificationManager->expects($this->never()) |
|
| 140 | + ->method('markProcessed'); |
|
| 141 | + |
|
| 142 | + $this->userManager->expects($this->never()) |
|
| 143 | + ->method('userExists'); |
|
| 144 | + |
|
| 145 | + $this->listener->evaluate($event); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function testEvaluateUserDoesNotExist(): void { |
|
| 149 | + /** @var IComment|MockObject $comment */ |
|
| 150 | + $comment = $this->createMock(IComment::class); |
|
| 151 | + $comment->expects($this->any()) |
|
| 152 | + ->method('getObjectType') |
|
| 153 | + ->willReturn('files'); |
|
| 154 | + $comment->expects($this->any()) |
|
| 155 | + ->method('getCreationDateTime') |
|
| 156 | + ->willReturn(new \DateTime()); |
|
| 157 | + $comment->expects($this->once()) |
|
| 158 | + ->method('getMentions') |
|
| 159 | + ->willReturn([[ 'type' => 'user', 'id' => 'foobar']]); |
|
| 160 | + $comment->expects($this->atLeastOnce()) |
|
| 161 | + ->method('getId') |
|
| 162 | + ->willReturn('1234'); |
|
| 163 | + |
|
| 164 | + $event = new CommentAddedEvent($comment); |
|
| 165 | + |
|
| 166 | + /** @var INotification|MockObject $notification */ |
|
| 167 | + $notification = $this->createMock(INotification::class); |
|
| 168 | + $notification->expects($this->any()) |
|
| 169 | + ->method($this->anything()) |
|
| 170 | + ->willReturn($notification); |
|
| 171 | + $notification->expects($this->never()) |
|
| 172 | + ->method('setUser'); |
|
| 173 | + |
|
| 174 | + $this->notificationManager->expects($this->once()) |
|
| 175 | + ->method('createNotification') |
|
| 176 | + ->willReturn($notification); |
|
| 177 | + $this->notificationManager->expects($this->never()) |
|
| 178 | + ->method('notify'); |
|
| 179 | + |
|
| 180 | + $this->userManager->expects($this->once()) |
|
| 181 | + ->method('userExists') |
|
| 182 | + ->with('foobar') |
|
| 183 | + ->willReturn(false); |
|
| 184 | + |
|
| 185 | + $this->listener->evaluate($event); |
|
| 186 | + } |
|
| 187 | 187 | } |
@@ -21,69 +21,69 @@ |
||
| 21 | 21 | use Test\TestCase; |
| 22 | 22 | |
| 23 | 23 | class EventHandlerTest extends TestCase { |
| 24 | - protected ActivityListener&MockObject $activityListener; |
|
| 25 | - protected NotificationListener&MockObject $notificationListener; |
|
| 26 | - protected CommentsEventListener $eventHandler; |
|
| 27 | - |
|
| 28 | - protected function setUp(): void { |
|
| 29 | - parent::setUp(); |
|
| 30 | - |
|
| 31 | - $this->activityListener = $this->createMock(ActivityListener::class); |
|
| 32 | - $this->notificationListener = $this->createMock(NotificationListener::class); |
|
| 33 | - |
|
| 34 | - $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function testNotFiles(): void { |
|
| 38 | - /** @var IComment|MockObject $comment */ |
|
| 39 | - $comment = $this->createMock(IComment::class); |
|
| 40 | - $comment->expects($this->once()) |
|
| 41 | - ->method('getObjectType') |
|
| 42 | - ->willReturn('smiles'); |
|
| 43 | - |
|
| 44 | - /** @var CommentsEvent|MockObject $event */ |
|
| 45 | - $event = $this->createMock(CommentsEvent::class); |
|
| 46 | - $event->expects($this->once()) |
|
| 47 | - ->method('getComment') |
|
| 48 | - ->willReturn($comment); |
|
| 49 | - $event->expects($this->never()) |
|
| 50 | - ->method('getEvent'); |
|
| 51 | - |
|
| 52 | - $this->eventHandler->handle($event); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public static function handledProvider(): array { |
|
| 56 | - return [ |
|
| 57 | - ['delete'], |
|
| 58 | - ['update'], |
|
| 59 | - ['pre_update'], |
|
| 60 | - ['add'] |
|
| 61 | - ]; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - #[\PHPUnit\Framework\Attributes\DataProvider('handledProvider')] |
|
| 65 | - public function testHandled(string $eventType): void { |
|
| 66 | - /** @var IComment|MockObject $comment */ |
|
| 67 | - $comment = $this->createMock(IComment::class); |
|
| 68 | - $comment->expects($this->once()) |
|
| 69 | - ->method('getObjectType') |
|
| 70 | - ->willReturn('files'); |
|
| 71 | - |
|
| 72 | - $event = match ($eventType) { |
|
| 73 | - 'add' => new CommentAddedEvent($comment), |
|
| 74 | - 'pre_update' => new BeforeCommentUpdatedEvent($comment), |
|
| 75 | - 'update' => new CommentUpdatedEvent($comment), |
|
| 76 | - 'delete' => new CommentDeletedEvent($comment), |
|
| 77 | - }; |
|
| 78 | - |
|
| 79 | - $this->notificationListener->expects($this->once()) |
|
| 80 | - ->method('evaluate') |
|
| 81 | - ->with($event); |
|
| 82 | - |
|
| 83 | - $this->activityListener->expects($this->any()) |
|
| 84 | - ->method('commentEvent') |
|
| 85 | - ->with($event); |
|
| 86 | - |
|
| 87 | - $this->eventHandler->handle($event); |
|
| 88 | - } |
|
| 24 | + protected ActivityListener&MockObject $activityListener; |
|
| 25 | + protected NotificationListener&MockObject $notificationListener; |
|
| 26 | + protected CommentsEventListener $eventHandler; |
|
| 27 | + |
|
| 28 | + protected function setUp(): void { |
|
| 29 | + parent::setUp(); |
|
| 30 | + |
|
| 31 | + $this->activityListener = $this->createMock(ActivityListener::class); |
|
| 32 | + $this->notificationListener = $this->createMock(NotificationListener::class); |
|
| 33 | + |
|
| 34 | + $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function testNotFiles(): void { |
|
| 38 | + /** @var IComment|MockObject $comment */ |
|
| 39 | + $comment = $this->createMock(IComment::class); |
|
| 40 | + $comment->expects($this->once()) |
|
| 41 | + ->method('getObjectType') |
|
| 42 | + ->willReturn('smiles'); |
|
| 43 | + |
|
| 44 | + /** @var CommentsEvent|MockObject $event */ |
|
| 45 | + $event = $this->createMock(CommentsEvent::class); |
|
| 46 | + $event->expects($this->once()) |
|
| 47 | + ->method('getComment') |
|
| 48 | + ->willReturn($comment); |
|
| 49 | + $event->expects($this->never()) |
|
| 50 | + ->method('getEvent'); |
|
| 51 | + |
|
| 52 | + $this->eventHandler->handle($event); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public static function handledProvider(): array { |
|
| 56 | + return [ |
|
| 57 | + ['delete'], |
|
| 58 | + ['update'], |
|
| 59 | + ['pre_update'], |
|
| 60 | + ['add'] |
|
| 61 | + ]; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + #[\PHPUnit\Framework\Attributes\DataProvider('handledProvider')] |
|
| 65 | + public function testHandled(string $eventType): void { |
|
| 66 | + /** @var IComment|MockObject $comment */ |
|
| 67 | + $comment = $this->createMock(IComment::class); |
|
| 68 | + $comment->expects($this->once()) |
|
| 69 | + ->method('getObjectType') |
|
| 70 | + ->willReturn('files'); |
|
| 71 | + |
|
| 72 | + $event = match ($eventType) { |
|
| 73 | + 'add' => new CommentAddedEvent($comment), |
|
| 74 | + 'pre_update' => new BeforeCommentUpdatedEvent($comment), |
|
| 75 | + 'update' => new CommentUpdatedEvent($comment), |
|
| 76 | + 'delete' => new CommentDeletedEvent($comment), |
|
| 77 | + }; |
|
| 78 | + |
|
| 79 | + $this->notificationListener->expects($this->once()) |
|
| 80 | + ->method('evaluate') |
|
| 81 | + ->with($event); |
|
| 82 | + |
|
| 83 | + $this->activityListener->expects($this->any()) |
|
| 84 | + ->method('commentEvent') |
|
| 85 | + ->with($event); |
|
| 86 | + |
|
| 87 | + $this->eventHandler->handle($event); |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -27,126 +27,126 @@ |
||
| 27 | 27 | use Test\TestCase; |
| 28 | 28 | |
| 29 | 29 | class ListenerTest extends TestCase { |
| 30 | - protected IManager&MockObject $activityManager; |
|
| 31 | - protected IUserSession&MockObject $session; |
|
| 32 | - protected IAppManager&MockObject $appManager; |
|
| 33 | - protected IMountProviderCollection&MockObject $mountProviderCollection; |
|
| 34 | - protected IRootFolder&MockObject $rootFolder; |
|
| 35 | - protected IShareHelper&MockObject $shareHelper; |
|
| 36 | - protected Listener $listener; |
|
| 37 | - |
|
| 38 | - protected function setUp(): void { |
|
| 39 | - parent::setUp(); |
|
| 40 | - |
|
| 41 | - $this->activityManager = $this->createMock(IManager::class); |
|
| 42 | - $this->session = $this->createMock(IUserSession::class); |
|
| 43 | - $this->appManager = $this->createMock(IAppManager::class); |
|
| 44 | - $this->mountProviderCollection = $this->createMock(IMountProviderCollection::class); |
|
| 45 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 46 | - $this->shareHelper = $this->createMock(IShareHelper::class); |
|
| 47 | - |
|
| 48 | - $this->listener = new Listener( |
|
| 49 | - $this->activityManager, |
|
| 50 | - $this->session, |
|
| 51 | - $this->appManager, |
|
| 52 | - $this->mountProviderCollection, |
|
| 53 | - $this->rootFolder, |
|
| 54 | - $this->shareHelper |
|
| 55 | - ); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function testCommentEvent(): void { |
|
| 59 | - $this->appManager->expects($this->any()) |
|
| 60 | - ->method('isEnabledForAnyone') |
|
| 61 | - ->with('activity') |
|
| 62 | - ->willReturn(true); |
|
| 63 | - |
|
| 64 | - $comment = $this->createMock(IComment::class); |
|
| 65 | - $comment->expects($this->any()) |
|
| 66 | - ->method('getObjectType') |
|
| 67 | - ->willReturn('files'); |
|
| 68 | - |
|
| 69 | - $event = new CommentAddedEvent($comment); |
|
| 70 | - |
|
| 71 | - /** @var IUser|MockObject $ownerUser */ |
|
| 72 | - $ownerUser = $this->createMock(IUser::class); |
|
| 73 | - $ownerUser->expects($this->any()) |
|
| 74 | - ->method('getUID') |
|
| 75 | - ->willReturn('937393'); |
|
| 76 | - |
|
| 77 | - /** @var MockObject $mount */ |
|
| 78 | - $mount = $this->createMock(ICachedMountFileInfo::class); |
|
| 79 | - $mount->expects($this->any()) |
|
| 80 | - ->method('getUser') |
|
| 81 | - ->willReturn($ownerUser); // perhaps not the right user, but does not matter in this scenario |
|
| 82 | - |
|
| 83 | - $mounts = [ $mount, $mount ]; // to make sure duplicates are dealt with |
|
| 84 | - |
|
| 85 | - $userMountCache = $this->createMock(IUserMountCache::class); |
|
| 86 | - $userMountCache->expects($this->any()) |
|
| 87 | - ->method('getMountsForFileId') |
|
| 88 | - ->willReturn($mounts); |
|
| 89 | - |
|
| 90 | - $this->mountProviderCollection->expects($this->any()) |
|
| 91 | - ->method('getMountCache') |
|
| 92 | - ->willReturn($userMountCache); |
|
| 93 | - |
|
| 94 | - $node = $this->createMock(Node::class); |
|
| 95 | - $nodes = [ $node ]; |
|
| 96 | - |
|
| 97 | - $ownerFolder = $this->createMock(Folder::class); |
|
| 98 | - $ownerFolder->expects($this->any()) |
|
| 99 | - ->method('getById') |
|
| 100 | - ->willReturn($nodes); |
|
| 101 | - |
|
| 102 | - $this->rootFolder->expects($this->any()) |
|
| 103 | - ->method('getUserFolder') |
|
| 104 | - ->willReturn($ownerFolder); |
|
| 105 | - |
|
| 106 | - $al = [ 'users' => [ |
|
| 107 | - '873304' => 'i/got/it/here', |
|
| 108 | - '254342' => 'there/i/have/it', |
|
| 109 | - 'sandra' => 'and/here/i/placed/it' |
|
| 110 | - ]]; |
|
| 111 | - $this->shareHelper->expects($this->any()) |
|
| 112 | - ->method('getPathsForAccessList') |
|
| 113 | - ->willReturn($al); |
|
| 114 | - |
|
| 115 | - $this->session->expects($this->any()) |
|
| 116 | - ->method('getUser') |
|
| 117 | - ->willReturn($ownerUser); |
|
| 118 | - |
|
| 119 | - /** @var MockObject $activity */ |
|
| 120 | - $activity = $this->createMock(IEvent::class); |
|
| 121 | - $activity->expects($this->exactly(count($al['users']))) |
|
| 122 | - ->method('setAffectedUser'); |
|
| 123 | - $activity->expects($this->once()) |
|
| 124 | - ->method('setApp') |
|
| 125 | - ->with('comments') |
|
| 126 | - ->willReturnSelf(); |
|
| 127 | - $activity->expects($this->once()) |
|
| 128 | - ->method('setType') |
|
| 129 | - ->with('comments') |
|
| 130 | - ->willReturnSelf(); |
|
| 131 | - $activity->expects($this->once()) |
|
| 132 | - ->method('setAuthor') |
|
| 133 | - ->with($ownerUser->getUID()) |
|
| 134 | - ->willReturnSelf(); |
|
| 135 | - $activity->expects($this->once()) |
|
| 136 | - ->method('setObject') |
|
| 137 | - ->with('files', $this->anything()) |
|
| 138 | - ->willReturnSelf(); |
|
| 139 | - $activity->expects($this->once()) |
|
| 140 | - ->method('setMessage') |
|
| 141 | - ->with('add_comment_message', $this->anything()) |
|
| 142 | - ->willReturnSelf(); |
|
| 143 | - |
|
| 144 | - $this->activityManager->expects($this->once()) |
|
| 145 | - ->method('generateEvent') |
|
| 146 | - ->willReturn($activity); |
|
| 147 | - $this->activityManager->expects($this->exactly(count($al['users']))) |
|
| 148 | - ->method('publish'); |
|
| 149 | - |
|
| 150 | - $this->listener->commentEvent($event); |
|
| 151 | - } |
|
| 30 | + protected IManager&MockObject $activityManager; |
|
| 31 | + protected IUserSession&MockObject $session; |
|
| 32 | + protected IAppManager&MockObject $appManager; |
|
| 33 | + protected IMountProviderCollection&MockObject $mountProviderCollection; |
|
| 34 | + protected IRootFolder&MockObject $rootFolder; |
|
| 35 | + protected IShareHelper&MockObject $shareHelper; |
|
| 36 | + protected Listener $listener; |
|
| 37 | + |
|
| 38 | + protected function setUp(): void { |
|
| 39 | + parent::setUp(); |
|
| 40 | + |
|
| 41 | + $this->activityManager = $this->createMock(IManager::class); |
|
| 42 | + $this->session = $this->createMock(IUserSession::class); |
|
| 43 | + $this->appManager = $this->createMock(IAppManager::class); |
|
| 44 | + $this->mountProviderCollection = $this->createMock(IMountProviderCollection::class); |
|
| 45 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 46 | + $this->shareHelper = $this->createMock(IShareHelper::class); |
|
| 47 | + |
|
| 48 | + $this->listener = new Listener( |
|
| 49 | + $this->activityManager, |
|
| 50 | + $this->session, |
|
| 51 | + $this->appManager, |
|
| 52 | + $this->mountProviderCollection, |
|
| 53 | + $this->rootFolder, |
|
| 54 | + $this->shareHelper |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function testCommentEvent(): void { |
|
| 59 | + $this->appManager->expects($this->any()) |
|
| 60 | + ->method('isEnabledForAnyone') |
|
| 61 | + ->with('activity') |
|
| 62 | + ->willReturn(true); |
|
| 63 | + |
|
| 64 | + $comment = $this->createMock(IComment::class); |
|
| 65 | + $comment->expects($this->any()) |
|
| 66 | + ->method('getObjectType') |
|
| 67 | + ->willReturn('files'); |
|
| 68 | + |
|
| 69 | + $event = new CommentAddedEvent($comment); |
|
| 70 | + |
|
| 71 | + /** @var IUser|MockObject $ownerUser */ |
|
| 72 | + $ownerUser = $this->createMock(IUser::class); |
|
| 73 | + $ownerUser->expects($this->any()) |
|
| 74 | + ->method('getUID') |
|
| 75 | + ->willReturn('937393'); |
|
| 76 | + |
|
| 77 | + /** @var MockObject $mount */ |
|
| 78 | + $mount = $this->createMock(ICachedMountFileInfo::class); |
|
| 79 | + $mount->expects($this->any()) |
|
| 80 | + ->method('getUser') |
|
| 81 | + ->willReturn($ownerUser); // perhaps not the right user, but does not matter in this scenario |
|
| 82 | + |
|
| 83 | + $mounts = [ $mount, $mount ]; // to make sure duplicates are dealt with |
|
| 84 | + |
|
| 85 | + $userMountCache = $this->createMock(IUserMountCache::class); |
|
| 86 | + $userMountCache->expects($this->any()) |
|
| 87 | + ->method('getMountsForFileId') |
|
| 88 | + ->willReturn($mounts); |
|
| 89 | + |
|
| 90 | + $this->mountProviderCollection->expects($this->any()) |
|
| 91 | + ->method('getMountCache') |
|
| 92 | + ->willReturn($userMountCache); |
|
| 93 | + |
|
| 94 | + $node = $this->createMock(Node::class); |
|
| 95 | + $nodes = [ $node ]; |
|
| 96 | + |
|
| 97 | + $ownerFolder = $this->createMock(Folder::class); |
|
| 98 | + $ownerFolder->expects($this->any()) |
|
| 99 | + ->method('getById') |
|
| 100 | + ->willReturn($nodes); |
|
| 101 | + |
|
| 102 | + $this->rootFolder->expects($this->any()) |
|
| 103 | + ->method('getUserFolder') |
|
| 104 | + ->willReturn($ownerFolder); |
|
| 105 | + |
|
| 106 | + $al = [ 'users' => [ |
|
| 107 | + '873304' => 'i/got/it/here', |
|
| 108 | + '254342' => 'there/i/have/it', |
|
| 109 | + 'sandra' => 'and/here/i/placed/it' |
|
| 110 | + ]]; |
|
| 111 | + $this->shareHelper->expects($this->any()) |
|
| 112 | + ->method('getPathsForAccessList') |
|
| 113 | + ->willReturn($al); |
|
| 114 | + |
|
| 115 | + $this->session->expects($this->any()) |
|
| 116 | + ->method('getUser') |
|
| 117 | + ->willReturn($ownerUser); |
|
| 118 | + |
|
| 119 | + /** @var MockObject $activity */ |
|
| 120 | + $activity = $this->createMock(IEvent::class); |
|
| 121 | + $activity->expects($this->exactly(count($al['users']))) |
|
| 122 | + ->method('setAffectedUser'); |
|
| 123 | + $activity->expects($this->once()) |
|
| 124 | + ->method('setApp') |
|
| 125 | + ->with('comments') |
|
| 126 | + ->willReturnSelf(); |
|
| 127 | + $activity->expects($this->once()) |
|
| 128 | + ->method('setType') |
|
| 129 | + ->with('comments') |
|
| 130 | + ->willReturnSelf(); |
|
| 131 | + $activity->expects($this->once()) |
|
| 132 | + ->method('setAuthor') |
|
| 133 | + ->with($ownerUser->getUID()) |
|
| 134 | + ->willReturnSelf(); |
|
| 135 | + $activity->expects($this->once()) |
|
| 136 | + ->method('setObject') |
|
| 137 | + ->with('files', $this->anything()) |
|
| 138 | + ->willReturnSelf(); |
|
| 139 | + $activity->expects($this->once()) |
|
| 140 | + ->method('setMessage') |
|
| 141 | + ->with('add_comment_message', $this->anything()) |
|
| 142 | + ->willReturnSelf(); |
|
| 143 | + |
|
| 144 | + $this->activityManager->expects($this->once()) |
|
| 145 | + ->method('generateEvent') |
|
| 146 | + ->willReturn($activity); |
|
| 147 | + $this->activityManager->expects($this->exactly(count($al['users']))) |
|
| 148 | + ->method('publish'); |
|
| 149 | + |
|
| 150 | + $this->listener->commentEvent($event); |
|
| 151 | + } |
|
| 152 | 152 | } |