|
11 | 11 | use OC\Group\Group; |
12 | 12 | use OC\User\User; |
13 | 13 | use OCP\EventDispatcher\IEventDispatcher; |
| 14 | +use OCP\Group\Events\BeforeGroupChangedEvent; |
| 15 | +use OCP\Group\Events\GroupChangedEvent; |
14 | 16 | use OCP\IUser; |
15 | 17 | use PHPUnit\Framework\MockObject\MockObject; |
16 | 18 |
|
@@ -457,6 +459,41 @@ public function testCountUsersNoMethod(): void { |
457 | 459 | $this->assertSame(false, $users); |
458 | 460 | } |
459 | 461 |
|
| 462 | + public function testSetDisplayNameDispatchesOldValue(): void { |
| 463 | + $backend = $this->getMockBuilder('OC\Group\Database') |
| 464 | + ->disableOriginalConstructor() |
| 465 | + ->getMock(); |
| 466 | + $userManager = $this->getUserManager(); |
| 467 | + |
| 468 | + $dispatcher = $this->createMock(IEventDispatcher::class); |
| 469 | + $invocation = 0; |
| 470 | + $dispatcher->expects($this->exactly(2)) |
| 471 | + ->method('dispatchTyped') |
| 472 | + ->willReturnCallback(function ($event) use (&$invocation): void { |
| 473 | + $invocation++; |
| 474 | + if ($invocation === 1) { |
| 475 | + $this->assertInstanceOf(BeforeGroupChangedEvent::class, $event); |
| 476 | + $this->assertSame('displayName', $event->getFeature()); |
| 477 | + $this->assertSame('New Name', $event->getValue()); |
| 478 | + $this->assertSame('Old Name', $event->getOldValue()); |
| 479 | + return; |
| 480 | + } |
| 481 | + |
| 482 | + $this->assertInstanceOf(GroupChangedEvent::class, $event); |
| 483 | + $this->assertSame('displayName', $event->getFeature()); |
| 484 | + $this->assertSame('New Name', $event->getValue()); |
| 485 | + $this->assertSame('Old Name', $event->getOldValue()); |
| 486 | + }); |
| 487 | + |
| 488 | + $backend->expects($this->once()) |
| 489 | + ->method('setDisplayName') |
| 490 | + ->with('group1', 'New Name') |
| 491 | + ->willReturn(true); |
| 492 | + |
| 493 | + $group = new Group('group1', [$backend], $dispatcher, $userManager, null, 'Old Name'); |
| 494 | + $this->assertTrue($group->setDisplayName('New Name')); |
| 495 | + } |
| 496 | + |
460 | 497 | public function testDelete(): void { |
461 | 498 | $backend = $this->getMockBuilder('OC\Group\Database') |
462 | 499 | ->disableOriginalConstructor() |
|
0 commit comments