aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/User
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/User')
-rw-r--r--tests/lib/User/AvatarUserDummy.php1
-rw-r--r--tests/lib/User/Backend.php1
-rw-r--r--tests/lib/User/DatabaseTest.php10
-rw-r--r--tests/lib/User/Dummy.php1
-rw-r--r--tests/lib/User/ManagerTest.php29
-rw-r--r--tests/lib/User/SessionTest.php89
-rw-r--r--tests/lib/User/UserTest.php68
7 files changed, 102 insertions, 97 deletions
diff --git a/tests/lib/User/AvatarUserDummy.php b/tests/lib/User/AvatarUserDummy.php
index d443a31e3f0..001dabd24c6 100644
--- a/tests/lib/User/AvatarUserDummy.php
+++ b/tests/lib/User/AvatarUserDummy.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/tests/lib/User/Backend.php b/tests/lib/User/Backend.php
index ed17776476a..dc5b245fa06 100644
--- a/tests/lib/User/Backend.php
+++ b/tests/lib/User/Backend.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/tests/lib/User/DatabaseTest.php b/tests/lib/User/DatabaseTest.php
index 900f0ddd3fa..33101173c0a 100644
--- a/tests/lib/User/DatabaseTest.php
+++ b/tests/lib/User/DatabaseTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,6 +8,7 @@
namespace Test\User;
+use OC\User\Database;
use OC\User\User;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
@@ -39,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 {
@@ -58,7 +60,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());
@@ -71,7 +73,7 @@ class DatabaseTest extends Backend {
public function testVerifyPasswordEventFail(): void {
- $this->expectException(\OCP\HintException::class);
+ $this->expectException(HintException::class);
$this->expectExceptionMessage('password change failed');
$user = $this->getUser();
@@ -79,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());
diff --git a/tests/lib/User/Dummy.php b/tests/lib/User/Dummy.php
index ffc5d343200..ec5be8ec60a 100644
--- a/tests/lib/User/Dummy.php
+++ b/tests/lib/User/Dummy.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php
index 5d3966cf4d8..d5872787d0a 100644
--- a/tests/lib/User/ManagerTest.php
+++ b/tests/lib/User/ManagerTest.php
@@ -9,14 +9,17 @@
namespace Test\User;
use OC\AllConfig;
+use OC\USER\BACKEND;
use OC\User\Database;
use OC\User\Manager;
+use OC\User\User;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -178,7 +181,7 @@ class ManagerTest extends TestCase {
$backend->expects($this->any())
->method('implementsActions')
->willReturnCallback(function ($actions) {
- if ($actions === \OC\USER\BACKEND::CHECK_PASSWORD) {
+ if ($actions === BACKEND::CHECK_PASSWORD) {
return true;
} else {
return false;
@@ -189,7 +192,7 @@ class ManagerTest extends TestCase {
$manager->registerBackend($backend);
$user = $manager->checkPassword('foo', 'bar');
- $this->assertTrue($user instanceof \OC\User\User);
+ $this->assertTrue($user instanceof User);
}
public function testCheckPasswordNotSupported(): void {
@@ -365,9 +368,7 @@ class ManagerTest extends TestCase {
];
}
- /**
- * @dataProvider dataCreateUserInvalid
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCreateUserInvalid')]
public function testCreateUserInvalid($uid, $password, $exception): void {
/** @var \Test\Util\User\Dummy|\PHPUnit\Framework\MockObject\MockObject $backend */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
@@ -545,7 +546,7 @@ class ManagerTest extends TestCase {
$backend->expects($this->once())
->method('implementsActions')
- ->with(\OC\USER\BACKEND::COUNT_USERS)
+ ->with(BACKEND::COUNT_USERS)
->willReturn(true);
$backend->expects($this->once())
@@ -574,7 +575,7 @@ class ManagerTest extends TestCase {
$backend1->expects($this->once())
->method('implementsActions')
- ->with(\OC\USER\BACKEND::COUNT_USERS)
+ ->with(BACKEND::COUNT_USERS)
->willReturn(true);
$backend1->expects($this->once())
->method('getBackendName')
@@ -587,7 +588,7 @@ class ManagerTest extends TestCase {
$backend2->expects($this->once())
->method('implementsActions')
- ->with(\OC\USER\BACKEND::COUNT_USERS)
+ ->with(BACKEND::COUNT_USERS)
->willReturn(true);
$backend2->expects($this->once())
->method('getBackendName')
@@ -609,7 +610,7 @@ class ManagerTest extends TestCase {
}
public function testCountUsersOnlyDisabled(): void {
- $manager = \OCP\Server::get(IUserManager::class);
+ $manager = Server::get(IUserManager::class);
// count other users in the db before adding our own
$countBefore = $manager->countDisabledUsers();
@@ -634,7 +635,7 @@ class ManagerTest extends TestCase {
}
public function testCountUsersOnlySeen(): void {
- $manager = \OCP\Server::get(IUserManager::class);
+ $manager = Server::get(IUserManager::class);
// count other users in the db before adding our own
$countBefore = $manager->countSeenUsers();
@@ -660,10 +661,10 @@ class ManagerTest extends TestCase {
}
public function testCallForSeenUsers(): void {
- $manager = \OCP\Server::get(IUserManager::class);
+ $manager = Server::get(IUserManager::class);
// count other users in the db before adding our own
$count = 0;
- $function = function (IUser $user) use (&$count) {
+ $function = function (IUser $user) use (&$count): void {
$count++;
};
$manager->callForAllUsers($function, '', true);
@@ -698,8 +699,8 @@ class ManagerTest extends TestCase {
* @preserveGlobalState disabled
*/
public function testRecentlyActive(): void {
- $config = \OCP\Server::get(IConfig::class);
- $manager = \OCP\Server::get(IUserManager::class);
+ $config = Server::get(IConfig::class);
+ $manager = Server::get(IUserManager::class);
// Create some users
$now = (string)time();
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index 7ed02571460..50c449559a0 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -96,7 +97,7 @@ class SessionTest extends \Test\TestCase {
$this->logger,
$this->dispatcher
])
- ->setMethods([
+ ->onlyMethods([
'setMagicInCookie',
])
->getMock();
@@ -104,16 +105,14 @@ class SessionTest extends \Test\TestCase {
\OC_User::setIncognitoMode(false);
}
- public function isLoggedInData() {
+ public static function isLoggedInData(): array {
return [
[true],
[false],
];
}
- /**
- * @dataProvider isLoggedInData
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('isLoggedInData')]
public function testIsLoggedIn($isLoggedIn): void {
$session = $this->createMock(Memory::class);
@@ -121,7 +120,7 @@ class SessionTest extends \Test\TestCase {
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods([
+ ->onlyMethods([
'getUser'
])
->getMock();
@@ -158,7 +157,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('bar')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$session->expects($this->exactly(2))
->method('set')
->with($this->callback(function ($key) {
@@ -177,7 +176,7 @@ class SessionTest extends \Test\TestCase {
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -205,7 +204,7 @@ class SessionTest extends \Test\TestCase {
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods([
+ ->onlyMethods([
'prepareUserLogin'
])
->getMock();
@@ -216,9 +215,9 @@ class SessionTest extends \Test\TestCase {
->method('dispatchTyped')
->with(
$this->callback(function (PostLoginEvent $e) {
- return $e->getUser()->getUID() === 'foo' &&
- $e->getPassword() === 'bar' &&
- $e->isTokenLogin() === false;
+ return $e->getUser()->getUID() === 'foo'
+ && $e->getPassword() === 'bar'
+ && $e->isTokenLogin() === false;
})
);
@@ -238,13 +237,13 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('bar')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$managerMethods = get_class_methods(Manager::class);
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -278,7 +277,7 @@ class SessionTest extends \Test\TestCase {
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -298,7 +297,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('bar')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$user->expects($this->never())
->method('isEnabled');
@@ -322,7 +321,7 @@ class SessionTest extends \Test\TestCase {
// Keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -360,7 +359,7 @@ class SessionTest extends \Test\TestCase {
// Keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -404,7 +403,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('bar')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$manager->expects($this->once())
->method('checkPasswordNoLogging')
@@ -424,13 +423,13 @@ class SessionTest extends \Test\TestCase {
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser'])
+ ->onlyMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock();
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('doe')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$this->config->expects($this->once())
->method('getSystemValueBool')
->with('token_auth_enforced', false)
@@ -460,13 +459,13 @@ class SessionTest extends \Test\TestCase {
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser'])
+ ->onlyMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock();
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('doe')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$this->config->expects($this->once())
->method('getSystemValueBool')
->with('token_auth_enforced', false)
@@ -486,7 +485,7 @@ class SessionTest extends \Test\TestCase {
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser'])
+ ->onlyMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock();
$userSession->expects($this->once())
@@ -528,13 +527,13 @@ class SessionTest extends \Test\TestCase {
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods(['login', 'isTwoFactorEnforced'])
+ ->onlyMethods(['login', 'isTwoFactorEnforced'])
->getMock();
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('doe')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$this->config->expects($this->once())
->method('getSystemValueBool')
->with('token_auth_enforced', false)
@@ -635,7 +634,7 @@ class SessionTest extends \Test\TestCase {
->with('abcde12345')
->willReturn($dbToken);
$this->session->method('set')
- ->willReturnCallback(function ($key, $value) {
+ ->willReturnCallback(function ($key, $value): void {
if ($key === 'app_password') {
throw new ExpectationFailedException('app_password should not be set in session');
}
@@ -657,7 +656,7 @@ class SessionTest extends \Test\TestCase {
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -667,7 +666,7 @@ class SessionTest extends \Test\TestCase {
->getMock();
$userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie()
- ->setMethods(['setMagicInCookie', 'setLoginName'])
+ ->onlyMethods(['setMagicInCookie', 'setLoginName'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock();
@@ -725,7 +724,7 @@ class SessionTest extends \Test\TestCase {
$setUID = false;
$session
->method('set')
- ->willReturnCallback(function ($k, $v) use (&$setUID) {
+ ->willReturnCallback(function ($k, $v) use (&$setUID): void {
if ($k === 'user_id' && $v === 'foo') {
$setUID = true;
}
@@ -747,7 +746,7 @@ class SessionTest extends \Test\TestCase {
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -757,7 +756,7 @@ class SessionTest extends \Test\TestCase {
->getMock();
$userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie()
- ->setMethods(['setMagicInCookie'])
+ ->onlyMethods(['setMagicInCookie'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock();
@@ -788,7 +787,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('renewSessionToken')
->with($oldSessionId, $sessionId)
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$user->expects($this->never())
->method('getUID')
@@ -812,7 +811,7 @@ class SessionTest extends \Test\TestCase {
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -822,7 +821,7 @@ class SessionTest extends \Test\TestCase {
->getMock();
$userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie()
- ->setMethods(['setMagicInCookie'])
+ ->onlyMethods(['setMagicInCookie'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock();
@@ -865,7 +864,7 @@ class SessionTest extends \Test\TestCase {
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
- ->setMethods($mockedManagerMethods)
+ ->onlyMethods($mockedManagerMethods)
->setConstructorArgs([
$this->config,
$this->createMock(ICacheFactory::class),
@@ -875,7 +874,7 @@ class SessionTest extends \Test\TestCase {
->getMock();
$userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie()
- ->setMethods(['setMagicInCookie'])
+ ->onlyMethods(['setMagicInCookie'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock();
$token = 'goodToken';
@@ -925,7 +924,7 @@ class SessionTest extends \Test\TestCase {
$session->set('user_id', 'foo');
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods([
+ ->onlyMethods([
'validateSession'
])
->getMock();
@@ -972,7 +971,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with($password)
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$this->tokenProvider->expects($this->once())
->method('generateToken')
@@ -1013,7 +1012,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with($password)
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$this->tokenProvider->expects($this->once())
->method('generateToken')
@@ -1130,7 +1129,7 @@ class SessionTest extends \Test\TestCase {
$this->session
->method('set')
- ->willReturnCallback(function ($k, $v) use (&$davAuthenticatedSet, &$lastPasswordConfirmSet) {
+ ->willReturnCallback(function ($k, $v) use (&$davAuthenticatedSet, &$lastPasswordConfirmSet): void {
switch ($k) {
case Auth::DAV_AUTHENTICATED:
$davAuthenticatedSet = $v;
@@ -1155,7 +1154,7 @@ class SessionTest extends \Test\TestCase {
$this->logger,
$this->dispatcher
])
- ->setMethods([
+ ->onlyMethods([
'logClientIn',
'getUser',
])
@@ -1207,7 +1206,7 @@ class SessionTest extends \Test\TestCase {
$this->logger,
$this->dispatcher
])
- ->setMethods([
+ ->onlyMethods([
'logClientIn',
])
->getMock();
@@ -1235,7 +1234,7 @@ class SessionTest extends \Test\TestCase {
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser'])
+ ->onlyMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock();
$userSession->expects($this->once())
@@ -1281,7 +1280,7 @@ class SessionTest extends \Test\TestCase {
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
- ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser'])
+ ->onlyMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock();
$userSession->expects($this->once())
diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php
index 44d28481ed5..05056c92193 100644
--- a/tests/lib/User/UserTest.php
+++ b/tests/lib/User/UserTest.php
@@ -11,9 +11,11 @@ namespace Test\User;
use OC\AllConfig;
use OC\Files\Mount\ObjectHomeMountProvider;
use OC\Hooks\PublicEmitter;
+use OC\User\Database;
use OC\User\User;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\FileInfo;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\IURLGenerator;
@@ -217,7 +219,7 @@ class UserTest extends TestCase {
public function testDeleteWithDifferentHome(): void {
/** @var ObjectHomeMountProvider $homeProvider */
- $homeProvider = \OC::$server->get(ObjectHomeMountProvider::class);
+ $homeProvider = Server::get(ObjectHomeMountProvider::class);
$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn('foo');
@@ -283,7 +285,7 @@ class UserTest extends TestCase {
public function testGetBackendClassName(): void {
$user = new User('foo', new \Test\Util\User\Dummy(), $this->dispatcher);
$this->assertEquals('Dummy', $user->getBackendClassName());
- $user = new User('foo', new \OC\User\Database(), $this->dispatcher);
+ $user = new User('foo', new Database(), $this->dispatcher);
$this->assertEquals('Database', $user->getBackendClassName());
}
@@ -391,7 +393,7 @@ class UserTest extends TestCase {
/**
* @var Backend | MockObject $backend
*/
- $backend = $this->createMock(\OC\User\Database::class);
+ $backend = $this->createMock(Database::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -420,7 +422,7 @@ class UserTest extends TestCase {
/**
* @var Backend | MockObject $backend
*/
- $backend = $this->createMock(\OC\User\Database::class);
+ $backend = $this->createMock(Database::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -441,7 +443,7 @@ class UserTest extends TestCase {
/**
* @var Backend | MockObject $backend
*/
- $backend = $this->createMock(\OC\User\Database::class);
+ $backend = $this->createMock(Database::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -470,7 +472,7 @@ class UserTest extends TestCase {
* @param User $user
* @param string $password
*/
- $hook = function ($user, $password) use ($test, &$hooksCalled) {
+ $hook = function ($user, $password) use ($test, &$hooksCalled): void {
$hooksCalled++;
$test->assertEquals('foo', $user->getUID());
$test->assertEquals('bar', $password);
@@ -496,7 +498,7 @@ class UserTest extends TestCase {
$this->assertEquals(2, $hooksCalled);
}
- public function dataDeleteHooks() {
+ public static function dataDeleteHooks(): array {
return [
[true, 2],
[false, 1],
@@ -504,10 +506,10 @@ class UserTest extends TestCase {
}
/**
- * @dataProvider dataDeleteHooks
* @param bool $result
* @param int $expectedHooks
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDeleteHooks')]
public function testDeleteHooks($result, $expectedHooks): void {
$hooksCalled = 0;
$test = $this;
@@ -536,7 +538,7 @@ class UserTest extends TestCase {
/**
* @param User $user
*/
- $hook = function ($user) use ($test, &$hooksCalled) {
+ $hook = function ($user) use ($test, &$hooksCalled): void {
$hooksCalled++;
$test->assertEquals('foo', $user->getUID());
};
@@ -585,14 +587,14 @@ class UserTest extends TestCase {
->method('markProcessed');
}
- $this->overwriteService(\OCP\Notification\IManager::class, $notificationManager);
- $this->overwriteService(\OCP\Comments\ICommentsManager::class, $commentsManager);
+ $this->overwriteService(INotificationManager::class, $notificationManager);
+ $this->overwriteService(ICommentsManager::class, $commentsManager);
$this->assertSame($result, $user->delete());
$this->restoreService(AllConfig::class);
- $this->restoreService(\OCP\Comments\ICommentsManager::class);
- $this->restoreService(\OCP\Notification\IManager::class);
+ $this->restoreService(ICommentsManager::class);
+ $this->restoreService(INotificationManager::class);
$this->assertEquals($expectedHooks, $hooksCalled);
}
@@ -616,7 +618,7 @@ class UserTest extends TestCase {
$userConfig = [];
$config->expects(self::atLeast(2))
->method('setUserValue')
- ->willReturnCallback(function () {
+ ->willReturnCallback(function (): void {
$userConfig[] = func_get_args();
});
@@ -625,14 +627,14 @@ class UserTest extends TestCase {
->method('deleteReferencesOfActor')
->willThrowException(new \Error('Test exception'));
- $this->overwriteService(\OCP\Comments\ICommentsManager::class, $commentsManager);
+ $this->overwriteService(ICommentsManager::class, $commentsManager);
$this->expectException(\Error::class);
$user = $this->getMockBuilder(User::class)
->onlyMethods(['getHome'])
->setConstructorArgs(['foo', $backend, $this->dispatcher, null, $config])
->getMock();
-
+
$user->expects(self::atLeastOnce())
->method('getHome')
->willReturn('/home/path');
@@ -647,19 +649,17 @@ class UserTest extends TestCase {
$userConfig,
);
- $this->restoreService(\OCP\Comments\ICommentsManager::class);
+ $this->restoreService(ICommentsManager::class);
}
- public function dataGetCloudId(): array {
+ public static function dataGetCloudId(): array {
return [
['https://localhost:8888/nextcloud', 'foo@localhost:8888/nextcloud'],
['http://localhost:8888/nextcloud', 'foo@http://localhost:8888/nextcloud'],
];
}
- /**
- * @dataProvider dataGetCloudId
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetCloudId')]
public function testGetCloudId(string $absoluteUrl, string $cloudId): void {
/** @var Backend|MockObject $backend */
$backend = $this->createMock(\Test\Util\User\Dummy::class);
@@ -685,7 +685,7 @@ class UserTest extends TestCase {
* @param string $feature
* @param string $value
*/
- $hook = function (IUser $user, $feature, $value) use ($test, &$hooksCalled) {
+ $hook = function (IUser $user, $feature, $value) use ($test, &$hooksCalled): void {
$hooksCalled++;
$test->assertEquals('eMailAddress', $feature);
$test->assertEquals('', $value);
@@ -721,7 +721,7 @@ class UserTest extends TestCase {
* @param string $feature
* @param string $value
*/
- $hook = function (IUser $user, $feature, $value) use ($test, &$hooksCalled) {
+ $hook = function (IUser $user, $feature, $value) use ($test, &$hooksCalled): void {
$hooksCalled++;
$test->assertEquals('eMailAddress', $feature);
$test->assertEquals('foo@bar.com', $value);
@@ -784,7 +784,7 @@ class UserTest extends TestCase {
* @param string $feature
* @param string $value
*/
- $hook = function (IUser $user, $feature, $value) use ($test, &$hooksCalled) {
+ $hook = function (IUser $user, $feature, $value) use ($test, &$hooksCalled): void {
$hooksCalled++;
$test->assertEquals('quota', $feature);
$test->assertEquals('23 TB', $value);
@@ -830,12 +830,12 @@ class UserTest extends TestCase {
['files', 'allow_unlimited_quota', '1', '1'],
];
$config->method('getUserValue')
- ->will($this->returnValueMap($userValueMap));
+ ->willReturnMap($userValueMap);
$config->method('getAppValue')
- ->will($this->returnValueMap($appValueMap));
+ ->willReturnMap($appValueMap);
- $quota = $user->getQuota();
- $this->assertEquals('none', $quota);
+ $this->assertEquals('none', $user->getQuota());
+ $this->assertEquals(FileInfo::SPACE_UNLIMITED, $user->getQuotaBytes());
}
public function testGetDefaultUnlimitedQuotaForbidden(): void {
@@ -864,12 +864,12 @@ class UserTest extends TestCase {
['files', 'default_quota', '1 GB', '1 GB'],
];
$config->method('getUserValue')
- ->will($this->returnValueMap($userValueMap));
+ ->willReturnMap($userValueMap);
$config->method('getAppValue')
- ->will($this->returnValueMap($appValueMap));
+ ->willReturnMap($appValueMap);
- $quota = $user->getQuota();
- $this->assertEquals('1 GB', $quota);
+ $this->assertEquals('1 GB', $user->getQuota());
+ $this->assertEquals(1024 * 1024 * 1024, $user->getQuotaBytes());
}
public function testSetQuotaAddressNoChange(): void {
@@ -964,7 +964,7 @@ class UserTest extends TestCase {
null,
$config,
])
- ->setMethods(['isEnabled', 'triggerChange'])
+ ->onlyMethods(['isEnabled', 'triggerChange'])
->getMock();
$user->expects($this->once())
@@ -998,7 +998,7 @@ class UserTest extends TestCase {
null,
$config,
])
- ->setMethods(['isEnabled', 'triggerChange'])
+ ->onlyMethods(['isEnabled', 'triggerChange'])
->getMock();
$user->expects($this->once())