Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/private/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ public function setDisplayName(string $displayName): bool {
$displayName = trim($displayName);
if ($displayName !== '') {
$this->dispatcher->dispatchTyped(new BeforeGroupChangedEvent($this, 'displayName', $displayName, $this->displayName));
$oldDisplayName = $this->displayName;
foreach ($this->backends as $backend) {
if (($backend instanceof ISetDisplayNameBackend)
&& $backend->setDisplayName($this->gid, $displayName)) {
$this->displayName = $displayName;
$this->dispatcher->dispatchTyped(new GroupChangedEvent($this, 'displayName', $displayName, ''));
$this->dispatcher->dispatchTyped(new GroupChangedEvent($this, 'displayName', $displayName, $oldDisplayName));
return true;
}
}
Expand Down
37 changes: 37 additions & 0 deletions tests/lib/Group/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use OC\Group\Group;
use OC\User\User;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\BeforeGroupChangedEvent;
use OCP\Group\Events\GroupChangedEvent;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;

Expand Down Expand Up @@ -457,6 +459,41 @@ public function testCountUsersNoMethod(): void {
$this->assertSame(false, $users);
}

public function testSetDisplayNameDispatchesOldValue(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
->getMock();
$userManager = $this->getUserManager();

$dispatcher = $this->createMock(IEventDispatcher::class);
$invocation = 0;
$dispatcher->expects($this->exactly(2))
->method('dispatchTyped')
->willReturnCallback(function ($event) use (&$invocation): void {
$invocation++;
if ($invocation === 1) {
$this->assertInstanceOf(BeforeGroupChangedEvent::class, $event);
$this->assertSame('displayName', $event->getFeature());
$this->assertSame('New Name', $event->getValue());
$this->assertSame('Old Name', $event->getOldValue());
return;
}

$this->assertInstanceOf(GroupChangedEvent::class, $event);
$this->assertSame('displayName', $event->getFeature());
$this->assertSame('New Name', $event->getValue());
$this->assertSame('Old Name', $event->getOldValue());
});

$backend->expects($this->once())
->method('setDisplayName')
->with('group1', 'New Name')
->willReturn(true);

$group = new Group('group1', [$backend], $dispatcher, $userManager, null, 'Old Name');
$this->assertTrue($group->setDisplayName('New Name'));
}

public function testDelete(): void {
$backend = $this->getMockBuilder('OC\Group\Database')
->disableOriginalConstructor()
Expand Down
Loading