aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2024-08-21 11:49:56 +0200
committerDaniel Kesselberg <mail@danielkesselberg.de>2024-09-23 13:06:40 +0200
commit5cf67c280f4e36832429a0df5bdbda6108047982 (patch)
tree8f18ce7fa873790c3083f44e2a6b9a27538d382e
parentbec14dc4a50ea71802f395b09a5d428bc25d30fb (diff)
downloadnextcloud-server-5cf67c280f4e36832429a0df5bdbda6108047982.tar.gz
nextcloud-server-5cf67c280f4e36832429a0df5bdbda6108047982.zip
test(admin_audit): add test for user management listenerdebt/noid/user-changed-event
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
-rw-r--r--apps/admin_audit/tests/Listener/UserManagementEventListenerTest.php92
1 files changed, 92 insertions, 0 deletions
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 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\AdminAudit\Tests\Actions;
+
+use OCA\AdminAudit\IAuditLogger;
+use OCA\AdminAudit\Listener\UserManagementEventListener;
+use OCP\IUser;
+use OCP\User\Events\UserChangedEvent;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class UserManagementEventListenerTest extends TestCase {
+ private IAuditLogger&MockObject $logger;
+
+ private UserManagementEventListener $listener;
+
+ private MockObject&IUser $user;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->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);
+ }
+}