|
11 | 11 | use OC\SystemTag\SystemTag; |
12 | 12 | use OC\SystemTag\SystemTagManager; |
13 | 13 | use OC\SystemTag\SystemTagObjectMapper; |
| 14 | +use OCP\EventDispatcher\Event; |
14 | 15 | use OCP\EventDispatcher\IEventDispatcher; |
15 | 16 | use OCP\IDBConnection; |
16 | 17 | use OCP\Server; |
17 | 18 | use OCP\SystemTag\ISystemTag; |
18 | 19 | use OCP\SystemTag\ISystemTagManager; |
19 | 20 | use OCP\SystemTag\ISystemTagObjectMapper; |
| 21 | +use OCP\SystemTag\TagAssignedEvent; |
20 | 22 | use OCP\SystemTag\TagNotFoundException; |
| 23 | +use OCP\SystemTag\TagUnassignedEvent; |
21 | 24 | use Test\TestCase; |
22 | 25 |
|
23 | 26 | /** |
@@ -208,16 +211,46 @@ public function testGetObjectsForNonExistingTag(): void { |
208 | 211 | } |
209 | 212 |
|
210 | 213 | public function testAssignUnassignTags(): void { |
| 214 | + $event = null; |
| 215 | + $this->dispatcher->expects($this->any())->method('dispatchTyped')->willReturnCallback(function (Event $e) use (&$event) { |
| 216 | + $event = $e; |
| 217 | + }); |
| 218 | + |
211 | 219 | $this->tagMapper->unassignTags('1', 'testtype', [$this->tag1->getId()]); |
212 | 220 |
|
| 221 | + $this->assertNotNull($event); |
| 222 | + $this->assertEquals(TagUnassignedEvent::class, $event::class); |
| 223 | + $this->assertEquals('testtype', $event->getObjectType()); |
| 224 | + $this->assertCount(1, $event->getObjectIds()); |
| 225 | + $this->assertEquals('1', current($event->getObjectIds())); |
| 226 | + $this->assertCount(1, $event->getTags()); |
| 227 | + $this->assertEquals($this->tag1->getId(), current($event->getTags())); |
| 228 | + |
213 | 229 | $tagIdMapping = $this->tagMapper->getTagIdsForObjects('1', 'testtype'); |
214 | 230 | $this->assertEquals([ |
215 | 231 | 1 => [$this->tag2->getId()], |
216 | 232 | ], $tagIdMapping); |
217 | 233 |
|
218 | 234 | $this->tagMapper->assignTags('1', 'testtype', [$this->tag1->getId()]); |
| 235 | + |
| 236 | + $this->assertNotNull($event); |
| 237 | + $this->assertEquals(TagAssignedEvent::class, $event::class); |
| 238 | + $this->assertEquals('testtype', $event->getObjectType()); |
| 239 | + $this->assertCount(1, $event->getObjectIds()); |
| 240 | + $this->assertEquals('1', current($event->getObjectIds())); |
| 241 | + $this->assertCount(1, $event->getTags()); |
| 242 | + $this->assertEquals($this->tag1->getId(), current($event->getTags())); |
| 243 | + |
219 | 244 | $this->tagMapper->assignTags('1', 'testtype', $this->tag3->getId()); |
220 | 245 |
|
| 246 | + $this->assertNotNull($event); |
| 247 | + $this->assertEquals(TagAssignedEvent::class, $event::class); |
| 248 | + $this->assertEquals('testtype', $event->getObjectType()); |
| 249 | + $this->assertCount(1, $event->getObjectIds()); |
| 250 | + $this->assertEquals('1', current($event->getObjectIds())); |
| 251 | + $this->assertCount(1, $event->getTags()); |
| 252 | + $this->assertEquals($this->tag3->getId(), current($event->getTags())); |
| 253 | + |
221 | 254 | $tagIdMapping = $this->tagMapper->getTagIdsForObjects('1', 'testtype'); |
222 | 255 |
|
223 | 256 | $this->assertEquals([ |
|
0 commit comments