|
7 | 7 |
|
8 | 8 | namespace OCA\Files_Sharing\Tests; |
9 | 9 |
|
| 10 | +use OC\User\NoUserException; |
10 | 11 | use OCA\Files_Sharing\Config\ConfigLexicon; |
11 | 12 | use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent; |
12 | 13 | use OCA\Files_Sharing\Listener\SharesUpdatedListener; |
@@ -115,6 +116,33 @@ public function testShareAddedFilterOwner() { |
115 | 116 | $this->sharesUpdatedListener->handle($event); |
116 | 117 | } |
117 | 118 |
|
| 119 | + public function testShareAddedSkipsUnresolvableUser(): void { |
| 120 | + $share = $this->createMock(IShare::class); |
| 121 | + $user1 = $this->createUser('user1', ''); |
| 122 | + $user2 = $this->createUser('user2', ''); |
| 123 | + |
| 124 | + $this->manager->method('getUsersForShare') |
| 125 | + ->willReturn([$user1, $user2]); |
| 126 | + |
| 127 | + $event = new ShareCreatedEvent($share); |
| 128 | + |
| 129 | + // user1 is an orphaned recipient that no backend can resolve |
| 130 | + $this->shareRecipientUpdater |
| 131 | + ->expects($this->exactly(2)) |
| 132 | + ->method('updateForAddedShare') |
| 133 | + ->willReturnCallback(function (IUser $user) use ($user1): void { |
| 134 | + if ($user === $user1) { |
| 135 | + throw new NoUserException('Backends provided no user object'); |
| 136 | + } |
| 137 | + }); |
| 138 | + |
| 139 | + // the failure is logged, not thrown |
| 140 | + $this->logger->expects($this->once())->method('debug'); |
| 141 | + |
| 142 | + // must not throw: user2 is still processed |
| 143 | + $this->sharesUpdatedListener->handle($event); |
| 144 | + } |
| 145 | + |
118 | 146 | public function testShareAccessUpdated() { |
119 | 147 | $user1 = $this->createUser('user1', ''); |
120 | 148 | $user2 = $this->createUser('user2', ''); |
|
0 commit comments