mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 23:03:00 -04:00
Merge pull request #58990 from mosi-kha/fix/group-displayname-event-oldvalue
fix(group): pass previous display name in GroupChangedEvent
This commit is contained in:
commit
309d12abe1
2 changed files with 39 additions and 1 deletions
|
|
@ -75,11 +75,12 @@ class Group implements IGroup {
|
|||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ namespace Test\Group;
|
|||
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;
|
||||
|
||||
|
|
@ -457,6 +459,41 @@ class GroupTest extends \Test\TestCase {
|
|||
$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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue