From c88ff19b9b3a1debf84cac159a1bb865410f6cbd Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 8 Apr 2026 11:04:18 -0400 Subject: [PATCH] test(user): add valid username coverage for Manager::createUser Signed-off-by: Josh --- tests/lib/User/ManagerTest.php | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index f606ac4d80503..b7cc937a6dadb 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -332,6 +332,50 @@ public function testCreateUserInvalid($uid, $password, $exception): void { $manager->createUser($uid, $password); } + public static function dataCreateUserValid(): array { + return [ + ['foo', 'bar'], + ['Foo', 'bar'], + ['FOO', 'bar'], + ['123', 'bar'], + ['foo bar', 'bar'], + ['foo_bar', 'bar'], + ['foo.bar', 'bar'], + ['foo@bar', 'bar'], + ["foo-bar", 'bar'], + ["foo'bar", 'bar'], + ['a', 'bar'], + ['test' . str_repeat('a', 59), 'bar'], // 63 chars total, still valid + ]; + } + + #[\PHPUnit\Framework\Attributes\DataProvider('dataCreateUserValid')] + public function testCreateUserValid(string $uid, string $password): void { + $backend = $this->createMock(\Test\Util\User\Dummy::class); + $backend->expects($this->any()) + ->method('implementsActions') + ->willReturn(true); + + $backend->expects($this->once()) + ->method('createUser') + ->with($this->equalTo($uid), $this->equalTo($password)) + ->willReturn(true); + + $backend->expects($this->once()) + ->method('userExists') + ->with($this->equalTo($uid)) + ->willReturn(false); + + $backend->expects($this->never()) + ->method('loginName2UserName'); + + $manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); + $manager->registerBackend($backend); + + $user = $manager->createUser($uid, $password); + $this->assertEquals($uid, $user->getUID()); + } + public function testCreateUserSingleBackendNotExists(): void { $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->any())