From 5cf67c280f4e36832429a0df5bdbda6108047982 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Wed, 21 Aug 2024 11:49:56 +0200 Subject: test(admin_audit): add test for user management listener Signed-off-by: Daniel Kesselberg --- .../Listener/UserManagementEventListenerTest.php | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 apps/admin_audit/tests/Listener/UserManagementEventListenerTest.php diff --git a/apps/admin_audit/tests/Listener/UserManagementEventListenerTest.php b/apps/admin_audit/tests/Listener/UserManagementEventListenerTest.php new file mode 100644 index 00000000000..c8cb0281113 --- /dev/null +++ b/apps/admin_audit/tests/Listener/UserManagementEventListenerTest.php @@ -0,0 +1,92 @@ +logger = $this->createMock(IAuditLogger::class); + $this->listener = new UserManagementEventListener($this->logger); + + $this->user = $this->createMock(IUser::class); + $this->user->method('getUID')->willReturn('alice'); + $this->user->method('getDisplayName')->willReturn('Alice'); + } + + public function testSkipUnsupported(): void { + $this->logger->expects($this->never()) + ->method('info'); + + $event = new UserChangedEvent( + $this->user, + 'unsupported', + 'value', + ); + + $this->listener->handle($event); + } + + public function testUserEnabled(): void { + $this->logger->expects($this->once()) + ->method('info') + ->with('User enabled: "alice"', ['app' => 'admin_audit']); + + $event = new UserChangedEvent( + $this->user, + 'enabled', + true, + false, + ); + + $this->listener->handle($event); + } + + public function testUserDisabled(): void { + $this->logger->expects($this->once()) + ->method('info') + ->with('User disabled: "alice"', ['app' => 'admin_audit']); + + $event = new UserChangedEvent( + $this->user, + 'enabled', + false, + true, + ); + + $this->listener->handle($event); + } + + public function testEmailChanged(): void { + $this->logger->expects($this->once()) + ->method('info') + ->with('Email address changed for user alice', ['app' => 'admin_audit']); + + $event = new UserChangedEvent( + $this->user, + 'eMailAddress', + 'alice@alice.com', + '', + ); + + $this->listener->handle($event); + } +} -- cgit v1.2.3