diff options
Diffstat (limited to 'tests/lib/User/DatabaseTest.php')
-rw-r--r-- | tests/lib/User/DatabaseTest.php | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/tests/lib/User/DatabaseTest.php b/tests/lib/User/DatabaseTest.php index 49b691cf9bc..33101173c0a 100644 --- a/tests/lib/User/DatabaseTest.php +++ b/tests/lib/User/DatabaseTest.php @@ -1,34 +1,20 @@ <?php + /** - * ownCloud - * - * @author Robin Appelman - * @copyright 2012 Robin Appelman icewind@owncloud.com - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\User; +use OC\User\Database; use OC\User\User; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; use OCP\HintException; use OCP\Security\Events\ValidatePasswordPolicyEvent; use PHPUnit\Framework\MockObject\MockObject; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Class DatabaseTest @@ -41,6 +27,9 @@ class DatabaseTest extends Backend { /** @var IEventDispatcher|MockObject */ private $eventDispatcher; + /** @var \OC\User\Database */ + protected $backend; + public function getUser() { $user = parent::getUser(); $this->users[] = $user; @@ -52,7 +41,7 @@ class DatabaseTest extends Backend { $this->eventDispatcher = $this->createMock(IEventDispatcher::class); - $this->backend = new \OC\User\Database($this->eventDispatcher); + $this->backend = new Database($this->eventDispatcher); } protected function tearDown(): void { @@ -65,13 +54,13 @@ class DatabaseTest extends Backend { parent::tearDown(); } - public function testVerifyPasswordEvent() { + public function testVerifyPasswordEvent(): void { $user = $this->getUser(); $this->backend->createUser($user, 'pass1'); $this->eventDispatcher->expects($this->once())->method('dispatchTyped') ->willReturnCallback( - function (Event $event) { + function (Event $event): void { $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); /** @var ValidatePasswordPolicyEvent $event */ $this->assertSame('newpass', $event->getPassword()); @@ -83,8 +72,8 @@ class DatabaseTest extends Backend { } - public function testVerifyPasswordEventFail() { - $this->expectException(\OCP\HintException::class); + public function testVerifyPasswordEventFail(): void { + $this->expectException(HintException::class); $this->expectExceptionMessage('password change failed'); $user = $this->getUser(); @@ -92,7 +81,7 @@ class DatabaseTest extends Backend { $this->eventDispatcher->expects($this->once())->method('dispatchTyped') ->willReturnCallback( - function (Event $event) { + function (Event $event): void { $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); /** @var ValidatePasswordPolicyEvent $event */ $this->assertSame('newpass', $event->getPassword()); @@ -104,14 +93,14 @@ class DatabaseTest extends Backend { $this->assertSame($user, $this->backend->checkPassword($user, 'newpass')); } - public function testCreateUserInvalidatesCache() { + public function testCreateUserInvalidatesCache(): void { $user1 = $this->getUniqueID('test_'); $this->assertFalse($this->backend->userExists($user1)); $this->backend->createUser($user1, 'pw'); $this->assertTrue($this->backend->userExists($user1)); } - public function testDeleteUserInvalidatesCache() { + public function testDeleteUserInvalidatesCache(): void { $user1 = $this->getUniqueID('test_'); $this->backend->createUser($user1, 'pw'); $this->assertTrue($this->backend->userExists($user1)); @@ -121,7 +110,7 @@ class DatabaseTest extends Backend { $this->assertTrue($this->backend->userExists($user1)); } - public function testSearch() { + public function testSearch(): void { parent::testSearch(); $user1 = $this->getUser(); @@ -130,8 +119,8 @@ class DatabaseTest extends Backend { $user2 = $this->getUser(); $this->backend->createUser($user2, 'pass1'); - $user1Obj = new User($user1, $this->backend, $this->createMock(EventDispatcherInterface::class)); - $user2Obj = new User($user2, $this->backend, $this->createMock(EventDispatcherInterface::class)); + $user1Obj = new User($user1, $this->backend, $this->createMock(IEventDispatcher::class)); + $user2Obj = new User($user2, $this->backend, $this->createMock(IEventDispatcher::class)); $emailAddr1 = "$user1@nextcloud.com"; $emailAddr2 = "$user2@nextcloud.com"; @@ -155,4 +144,14 @@ class DatabaseTest extends Backend { $result = $this->backend->getDisplayNames('@nextcloud.COM'); $this->assertCount(2, $result); } + + public function testUserCount(): void { + $base = $this->backend->countUsers() ?: 0; + $users = $this->backend->getUsers(); + self::assertEquals($base, count($users)); + + $user = $this->getUser(); + $this->backend->createUser($user, $user); + self::assertEquals($base + 1, $this->backend->countUsers()); + } } |