|
18 | 18 | use OCP\SystemTag\ISystemTag; |
19 | 19 | use OCP\SystemTag\ISystemTagManager; |
20 | 20 | use OCP\SystemTag\ISystemTagObjectMapper; |
| 21 | +use OCP\SystemTag\MapperEvent; |
21 | 22 | use OCP\SystemTag\TagAssignedEvent; |
22 | 23 | use OCP\SystemTag\TagNotFoundException; |
23 | 24 | use OCP\SystemTag\TagUnassignedEvent; |
@@ -258,6 +259,28 @@ public function testAssignUnassignTags(): void { |
258 | 259 | ], $tagIdMapping); |
259 | 260 | } |
260 | 261 |
|
| 262 | + public function testSetObjectIdsForTagDispatchesUnassignEventOncePerObject(): void { |
| 263 | + $unassignedObjectIds = []; |
| 264 | + $this->dispatcher->expects($this->any())->method('dispatch')->willReturnCallback( |
| 265 | + function (string $eventName, Event $event) use (&$unassignedObjectIds): void { |
| 266 | + if ($eventName === MapperEvent::EVENT_UNASSIGN) { |
| 267 | + $unassignedObjectIds[] = $event->getObjectId(); |
| 268 | + } |
| 269 | + } |
| 270 | + ); |
| 271 | + |
| 272 | + // tag1 is assigned to objects '1' and '2', keep only '2' |
| 273 | + $this->tagMapper->setObjectIdsForTag((string)$this->tag1->getId(), 'testtype', ['2']); |
| 274 | + |
| 275 | + $this->assertEquals(['1'], $unassignedObjectIds); |
| 276 | + |
| 277 | + // same expectation when the new object list is empty |
| 278 | + $unassignedObjectIds = []; |
| 279 | + $this->tagMapper->setObjectIdsForTag((string)$this->tag1->getId(), 'testtype', []); |
| 280 | + |
| 281 | + $this->assertEquals(['2'], $unassignedObjectIds); |
| 282 | + } |
| 283 | + |
261 | 284 | public function testReAssignUnassignTags(): void { |
262 | 285 | // reassign tag1 |
263 | 286 | $this->tagMapper->assignTags('1', 'testtype', [$this->tag1->getId()]); |
|
0 commit comments