aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/User
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/User')
-rw-r--r--apps/user_ldap/tests/User/DeletedUsersIndexTest.php30
-rw-r--r--apps/user_ldap/tests/User/ManagerTest.php84
-rw-r--r--apps/user_ldap/tests/User/OfflineUserTest.php25
-rw-r--r--apps/user_ldap/tests/User/UserTest.php175
4 files changed, 116 insertions, 198 deletions
diff --git a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
index 32fa5bc38bf..b245e52fe6e 100644
--- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
+++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -9,7 +11,9 @@ use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\Server;
use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class DeletedUsersIndexTest
@@ -19,26 +23,18 @@ use OCP\Share\IManager;
* @package OCA\User_LDAP\Tests\User
*/
class DeletedUsersIndexTest extends \Test\TestCase {
- /** @var DeletedUsersIndex */
- protected $dui;
-
- /** @var IConfig */
- protected $config;
-
- /** @var IDBConnection */
- protected $db;
-
- /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
- protected $mapping;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $shareManager;
+ protected DeletedUsersIndex $dui;
+ protected IConfig $config;
+ protected IDBConnection $db;
+ protected UserMapping&MockObject $mapping;
+ protected IManager&MockObject $shareManager;
protected function setUp(): void {
parent::setUp();
// no mocks for those as tests go against DB
- $this->config = \OC::$server->getConfig();
- $this->db = \OC::$server->getDatabaseConnection();
+ $this->config = Server::get(IConfig::class);
+ $this->db = Server::get(IDBConnection::class);
// ensure a clean database
$this->config->deleteAppFromAllUsers('user_ldap');
@@ -54,7 +50,7 @@ class DeletedUsersIndexTest extends \Test\TestCase {
parent::tearDown();
}
- public function testMarkAndFetchUser() {
+ public function testMarkAndFetchUser(): void {
$uids = [
'cef3775c-71d2-48eb-8984-39a4051b0b95',
'8c4bbb40-33ed-42d0-9b14-85b0ab76c1cc',
@@ -82,7 +78,7 @@ class DeletedUsersIndexTest extends \Test\TestCase {
$this->assertEmpty($uids);
}
- public function testUnmarkUser() {
+ public function testUnmarkUser(): void {
$uids = [
'22a162c7-a9ee-487c-9f33-0563795583fb',
'1fb4e0da-4a75-47f3-8fa7-becc7e35c9c5',
diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php
index 597a2e69a0a..bf9d1f5746f 100644
--- a/apps/user_ldap/tests/User/ManagerTest.php
+++ b/apps/user_ldap/tests/User/ManagerTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,7 +10,6 @@ namespace OCA\User_LDAP\Tests\User;
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
-use OCA\User_LDAP\FilesystemHelper;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\User;
@@ -20,6 +20,7 @@ use OCP\Image;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@@ -30,50 +31,24 @@ use Psr\Log\LoggerInterface;
* @package OCA\User_LDAP\Tests\User
*/
class ManagerTest extends \Test\TestCase {
- /** @var Access|\PHPUnit\Framework\MockObject\MockObject */
- protected $access;
-
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
-
- /** @var FilesystemHelper|\PHPUnit\Framework\MockObject\MockObject */
- protected $fileSystemHelper;
-
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- protected $logger;
-
- /** @var IAvatarManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $avatarManager;
-
- /** @var Image|\PHPUnit\Framework\MockObject\MockObject */
- protected $image;
-
- /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
- protected $dbc;
-
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $ncUserManager;
-
- /** @var INotificationManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $notificationManager;
-
- /** @var ILDAPWrapper|\PHPUnit\Framework\MockObject\MockObject */
- protected $ldapWrapper;
-
- /** @var Connection */
- protected $connection;
-
- /** @var Manager */
- protected $manager;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $shareManager;
+ protected Access&MockObject $access;
+ protected IConfig&MockObject $config;
+ protected LoggerInterface&MockObject $logger;
+ protected IAvatarManager&MockObject $avatarManager;
+ protected Image&MockObject $image;
+ protected IDBConnection&MockObject $dbc;
+ protected IUserManager&MockObject $ncUserManager;
+ protected INotificationManager&MockObject $notificationManager;
+ protected ILDAPWrapper&MockObject $ldapWrapper;
+ protected Connection $connection;
+ protected IManager&MockObject $shareManager;
+ protected Manager $manager;
protected function setUp(): void {
parent::setUp();
$this->access = $this->createMock(Access::class);
$this->config = $this->createMock(IConfig::class);
- $this->fileSystemHelper = $this->createMock(FilesystemHelper::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->avatarManager = $this->createMock(IAvatarManager::class);
$this->image = $this->createMock(Image::class);
@@ -91,7 +66,6 @@ class ManagerTest extends \Test\TestCase {
/** @noinspection PhpUnhandledExceptionInspection */
$this->manager = new Manager(
$this->config,
- $this->fileSystemHelper,
$this->logger,
$this->avatarManager,
$this->image,
@@ -103,7 +77,7 @@ class ManagerTest extends \Test\TestCase {
$this->manager->setLdapAccess($this->access);
}
- public function dnProvider() {
+ public static function dnProvider(): array {
return [
['cn=foo,dc=foobar,dc=bar'],
['uid=foo,o=foobar,c=bar'],
@@ -111,10 +85,8 @@ class ManagerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dnProvider
- */
- public function testGetByDNExisting(string $inputDN) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dnProvider')]
+ public function testGetByDNExisting(string $inputDN): void {
$uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
$this->access->expects($this->once())
@@ -139,7 +111,7 @@ class ManagerTest extends \Test\TestCase {
$this->assertInstanceOf(User::class, $user);
}
- public function testGetByDNNotExisting() {
+ public function testGetByDNNotExisting(): void {
$inputDN = 'cn=gone,dc=foobar,dc=bar';
$this->access->expects($this->once())
@@ -161,7 +133,7 @@ class ManagerTest extends \Test\TestCase {
$this->assertNull($user);
}
- public function testGetByUidExisting() {
+ public function testGetByUidExisting(): void {
$dn = 'cn=foo,dc=foobar,dc=bar';
$uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
@@ -187,7 +159,7 @@ class ManagerTest extends \Test\TestCase {
$this->assertInstanceOf(User::class, $user);
}
- public function testGetByUidNotExisting() {
+ public function testGetByUidNotExisting(): void {
$uid = 'gone';
$this->access->expects($this->never())
@@ -203,17 +175,15 @@ class ManagerTest extends \Test\TestCase {
$this->assertNull($user);
}
- public function attributeRequestProvider() {
+ public static function attributeRequestProvider(): array {
return [
[false],
[true],
];
}
- /**
- * @dataProvider attributeRequestProvider
- */
- public function testGetAttributes($minimal) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('attributeRequestProvider')]
+ public function testGetAttributes($minimal): void {
$this->connection->setConfiguration([
'ldapEmailAttribute' => 'MAIL',
'ldapUserAvatarRule' => 'default',
@@ -223,10 +193,10 @@ class ManagerTest extends \Test\TestCase {
$attributes = $this->manager->getAttributes($minimal);
- $this->assertTrue(in_array('dn', $attributes));
- $this->assertTrue(in_array(strtolower($this->access->getConnection()->ldapEmailAttribute), $attributes));
- $this->assertTrue(!in_array($this->access->getConnection()->ldapEmailAttribute, $attributes)); #cases check
- $this->assertFalse(in_array('', $attributes));
+ $this->assertContains('dn', $attributes);
+ $this->assertContains(strtolower($this->access->getConnection()->ldapEmailAttribute), $attributes);
+ $this->assertNotContains($this->access->getConnection()->ldapEmailAttribute, $attributes); #cases check
+ $this->assertNotContains('', $attributes);
$this->assertSame(!$minimal, in_array('jpegphoto', $attributes));
$this->assertSame(!$minimal, in_array('thumbnailphoto', $attributes));
$valueCounts = array_count_values($attributes);
diff --git a/apps/user_ldap/tests/User/OfflineUserTest.php b/apps/user_ldap/tests/User/OfflineUserTest.php
index 8ac0e617d80..223e63421ad 100644
--- a/apps/user_ldap/tests/User/OfflineUserTest.php
+++ b/apps/user_ldap/tests/User/OfflineUserTest.php
@@ -13,20 +13,15 @@ use OCA\User_LDAP\User\OfflineUser;
use OCP\IConfig;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class OfflineUserTest extends TestCase {
-
- /** @var OfflineUser */
- protected $offlineUser;
- /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
- protected $mapping;
- /** @var string */
- protected $uid;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $shareManager;
+ protected UserMapping&MockObject $mapping;
+ protected string $uid;
+ protected IConfig&MockObject $config;
+ protected IManager&MockObject $shareManager;
+ protected OfflineUser $offlineUser;
public function setUp(): void {
$this->uid = 'deborah';
@@ -42,7 +37,7 @@ class OfflineUserTest extends TestCase {
);
}
- public function shareOwnerProvider(): array {
+ public static function shareOwnerProvider(): array {
return [
[[], false],
[[IShare::TYPE_USER], true],
@@ -52,10 +47,8 @@ class OfflineUserTest extends TestCase {
];
}
- /**
- * @dataProvider shareOwnerProvider
- */
- public function testHasActiveShares(array $existingShareTypes, bool $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('shareOwnerProvider')]
+ public function testHasActiveShares(array $existingShareTypes, bool $expected): void {
$shareMock = $this->createMock(IShare::class);
$this->shareManager->expects($this->atLeastOnce())
diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php
index ec5cf03f402..00edd8b3f9b 100644
--- a/apps/user_ldap/tests/User/UserTest.php
+++ b/apps/user_ldap/tests/User/UserTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,7 +10,7 @@ namespace OCA\User_LDAP\Tests\User;
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
-use OCA\User_LDAP\FilesystemHelper;
+use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\User\User;
use OCP\IAvatar;
use OCP\IAvatarManager;
@@ -19,6 +20,8 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
+use OCP\Util;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@@ -29,35 +32,24 @@ use Psr\Log\LoggerInterface;
* @package OCA\User_LDAP\Tests\User
*/
class UserTest extends \Test\TestCase {
- /** @var Access|\PHPUnit\Framework\MockObject\MockObject */
- protected $access;
- /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
- protected $connection;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
- /** @var FilesystemHelper|\PHPUnit\Framework\MockObject\MockObject */
- protected $filesystemhelper;
- /** @var INotificationManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $notificationManager;
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $userManager;
- /** @var Image|\PHPUnit\Framework\MockObject\MockObject */
- protected $image;
- /** @var IAvatarManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $avatarManager;
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- protected $logger;
- /** @var string */
- protected $uid = 'alice';
- /** @var string */
- protected $dn = 'uid=alice,dc=foo,dc=bar';
- /** @var User */
- protected $user;
+ protected Access&MockObject $access;
+ protected Connection&MockObject $connection;
+ protected IConfig&MockObject $config;
+ protected INotificationManager&MockObject $notificationManager;
+ protected IUserManager&MockObject $userManager;
+ protected Image&MockObject $image;
+ protected IAvatarManager&MockObject $avatarManager;
+ protected LoggerInterface&MockObject $logger;
+ protected string $uid = 'alice';
+ protected string $dn = 'uid=alice,dc=foo,dc=bar';
+ protected User $user;
protected function setUp(): void {
parent::setUp();
- $this->connection = $this->createMock(Connection::class);
+ $this->connection = $this->getMockBuilder(Connection::class)
+ ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
+ ->getMock();
$this->access = $this->createMock(Access::class);
$this->access->connection = $this->connection;
@@ -66,7 +58,6 @@ class UserTest extends \Test\TestCase {
->willReturn($this->connection);
$this->config = $this->createMock(IConfig::class);
- $this->filesystemhelper = $this->createMock(FilesystemHelper::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->avatarManager = $this->createMock(IAvatarManager::class);
$this->image = $this->createMock(Image::class);
@@ -78,7 +69,6 @@ class UserTest extends \Test\TestCase {
$this->dn,
$this->access,
$this->config,
- $this->filesystemhelper,
$this->image,
$this->logger,
$this->avatarManager,
@@ -87,12 +77,12 @@ class UserTest extends \Test\TestCase {
);
}
- public function testGetDNandUsername() {
+ public function testGetDNandUsername(): void {
$this->assertSame($this->dn, $this->user->getDN());
$this->assertSame($this->uid, $this->user->getUsername());
}
- public function testUpdateEmailProvided() {
+ public function testUpdateEmailProvided(): void {
$this->connection->expects($this->once())
->method('__get')
->with($this->equalTo('ldapEmailAttribute'))
@@ -104,11 +94,9 @@ class UserTest extends \Test\TestCase {
$this->equalTo('email'))
->willReturn(['alice@foo.bar']);
- $coreUser = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $coreUser = $this->createMock(IUser::class);
$coreUser->expects($this->once())
- ->method('setEMailAddress')
+ ->method('setSystemEMailAddress')
->with('alice@foo.bar');
$this->userManager->expects($this->any())
@@ -118,7 +106,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateEmail();
}
- public function testUpdateEmailNotProvided() {
+ public function testUpdateEmailNotProvided(): void {
$this->connection->expects($this->once())
->method('__get')
->with($this->equalTo('ldapEmailAttribute'))
@@ -136,7 +124,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateEmail();
}
- public function testUpdateEmailNotConfigured() {
+ public function testUpdateEmailNotConfigured(): void {
$this->connection->expects($this->once())
->method('__get')
->with($this->equalTo('ldapEmailAttribute'))
@@ -151,7 +139,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateEmail();
}
- public function testUpdateQuotaAllProvided() {
+ public function testUpdateQuotaAllProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -178,7 +166,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateQuota();
}
- public function testUpdateQuotaToDefaultAllProvided() {
+ public function testUpdateQuotaToDefaultAllProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -205,7 +193,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateQuota();
}
- public function testUpdateQuotaToNoneAllProvided() {
+ public function testUpdateQuotaToNoneAllProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -232,7 +220,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateQuota();
}
- public function testUpdateQuotaDefaultProvided() {
+ public function testUpdateQuotaDefaultProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -259,7 +247,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateQuota();
}
- public function testUpdateQuotaIndividualProvided() {
+ public function testUpdateQuotaIndividualProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -286,7 +274,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateQuota();
}
- public function testUpdateQuotaNoneProvided() {
+ public function testUpdateQuotaNoneProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -314,7 +302,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateQuota();
}
- public function testUpdateQuotaNoneConfigured() {
+ public function testUpdateQuotaNoneConfigured(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -338,7 +326,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateQuota();
}
- public function testUpdateQuotaFromValue() {
+ public function testUpdateQuotaFromValue(): void {
$readQuota = '19 GB';
$this->connection->expects($this->exactly(2))
@@ -367,7 +355,7 @@ class UserTest extends \Test\TestCase {
/**
* Unparseable quota will fallback to use the LDAP default
*/
- public function testUpdateWrongQuotaAllProvided() {
+ public function testUpdateWrongQuotaAllProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -397,7 +385,7 @@ class UserTest extends \Test\TestCase {
/**
* No user quota and wrong default will set 'default' as quota
*/
- public function testUpdateWrongDefaultQuotaProvided() {
+ public function testUpdateWrongDefaultQuotaProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -424,7 +412,7 @@ class UserTest extends \Test\TestCase {
/**
* Wrong user quota and wrong default will set 'default' as quota
*/
- public function testUpdateWrongQuotaAndDefaultAllProvided() {
+ public function testUpdateWrongQuotaAndDefaultAllProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -451,7 +439,7 @@ class UserTest extends \Test\TestCase {
/**
* No quota attribute set and wrong default will set 'default' as quota
*/
- public function testUpdateWrongDefaultQuotaNotProvided() {
+ public function testUpdateWrongDefaultQuotaNotProvided(): void {
$this->connection->expects($this->exactly(2))
->method('__get')
->willReturnMap([
@@ -507,14 +495,10 @@ class UserTest extends \Test\TestCase {
->method('setUserValue')
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
- $this->filesystemhelper->expects($this->once())
- ->method('isLoaded')
- ->willReturn(true);
-
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->once())
->method('set')
- ->with($this->isInstanceOf($this->image));
+ ->with($this->image);
$this->avatarManager->expects($this->once())
->method('getAvatar')
@@ -529,7 +513,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateAvatar();
}
- public function testUpdateAvatarKnownJpegPhotoProvided() {
+ public function testUpdateAvatarKnownJpegPhotoProvided(): void {
$this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo($this->dn),
@@ -558,9 +542,6 @@ class UserTest extends \Test\TestCase {
$this->config->expects($this->never())
->method('setUserValue');
- $this->filesystemhelper->expects($this->never())
- ->method('isLoaded');
-
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->never())
->method('set');
@@ -625,14 +606,10 @@ class UserTest extends \Test\TestCase {
->method('setUserValue')
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
- $this->filesystemhelper->expects($this->once())
- ->method('isLoaded')
- ->willReturn(true);
-
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->once())
->method('set')
- ->with($this->isInstanceOf($this->image));
+ ->with($this->image);
$this->avatarManager->expects($this->once())
->method('getAvatar')
@@ -647,7 +624,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateAvatar();
}
- public function testUpdateAvatarCorruptPhotoProvided() {
+ public function testUpdateAvatarCorruptPhotoProvided(): void {
$this->access->expects($this->any())
->method('readAttribute')
->willReturnCallback(function ($dn, $attr) {
@@ -680,9 +657,6 @@ class UserTest extends \Test\TestCase {
$this->config->expects($this->never())
->method('setUserValue');
- $this->filesystemhelper->expects($this->never())
- ->method('isLoaded');
-
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->never())
->method('set');
@@ -738,14 +712,10 @@ class UserTest extends \Test\TestCase {
$this->config->expects($this->never())
->method('setUserValue');
- $this->filesystemhelper->expects($this->once())
- ->method('isLoaded')
- ->willReturn(true);
-
$avatar = $this->createMock(IAvatar::class);
$avatar->expects($this->once())
->method('set')
- ->with($this->isInstanceOf($this->image))
+ ->with($this->image)
->willThrowException(new \Exception());
$this->avatarManager->expects($this->once())
@@ -761,7 +731,7 @@ class UserTest extends \Test\TestCase {
$this->assertFalse($this->user->updateAvatar());
}
- public function testUpdateAvatarNotProvided() {
+ public function testUpdateAvatarNotProvided(): void {
$this->access->expects($this->any())
->method('readAttribute')
->willReturnCallback(function ($dn, $attr) {
@@ -791,9 +761,6 @@ class UserTest extends \Test\TestCase {
$this->config->expects($this->never())
->method('setUserValue');
- $this->filesystemhelper->expects($this->never())
- ->method('isLoaded');
-
$this->avatarManager->expects($this->never())
->method('getAvatar');
@@ -805,7 +772,7 @@ class UserTest extends \Test\TestCase {
$this->user->updateAvatar();
}
- public function extStorageHomeDataProvider() {
+ public static function extStorageHomeDataProvider(): array {
return [
[ 'myFolder', null ],
[ '', null, false ],
@@ -813,10 +780,8 @@ class UserTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider extStorageHomeDataProvider
- */
- public function testUpdateExtStorageHome(string $expected, ?string $valueFromLDAP = null, bool $isSet = true) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('extStorageHomeDataProvider')]
+ public function testUpdateExtStorageHome(string $expected, ?string $valueFromLDAP = null, bool $isSet = true): void {
if ($valueFromLDAP === null) {
$this->connection->expects($this->once())
->method('__get')
@@ -848,7 +813,7 @@ class UserTest extends \Test\TestCase {
$this->assertSame($expected, $actual);
}
- public function testMarkLogin() {
+ public function testMarkLogin(): void {
$this->config->expects($this->once())
->method('setUserValue')
->with($this->equalTo($this->uid),
@@ -860,7 +825,7 @@ class UserTest extends \Test\TestCase {
$this->user->markLogin();
}
- public function testGetAvatarImageProvided() {
+ public function testGetAvatarImageProvided(): void {
$this->access->expects($this->once())
->method('readAttribute')
->with($this->equalTo($this->dn),
@@ -878,7 +843,7 @@ class UserTest extends \Test\TestCase {
$this->user->getAvatarImage();
}
- public function testGetAvatarImageDisabled() {
+ public function testGetAvatarImageDisabled(): void {
$this->access->expects($this->never())
->method('readAttribute')
->with($this->equalTo($this->dn), $this->anything());
@@ -890,7 +855,7 @@ class UserTest extends \Test\TestCase {
$this->assertFalse($this->user->getAvatarImage());
}
- public function imageDataProvider() {
+ public static function imageDataProvider(): array {
return [
[ false, false ],
[ 'corruptData', false ],
@@ -898,7 +863,7 @@ class UserTest extends \Test\TestCase {
];
}
- public function testProcessAttributes() {
+ public function testProcessAttributes(): void {
$requiredMethods = [
'updateQuota',
'updateEmail',
@@ -909,21 +874,20 @@ class UserTest extends \Test\TestCase {
'updateExtStorageHome',
];
- /** @var User|\PHPUnit\Framework\MockObject\MockObject $userMock */
+ /** @var User&MockObject $userMock */
$userMock = $this->getMockBuilder(User::class)
->setConstructorArgs([
$this->uid,
$this->dn,
$this->access,
$this->config,
- $this->filesystemhelper,
$this->image,
$this->logger,
$this->avatarManager,
$this->userManager,
$this->notificationManager
])
- ->setMethods($requiredMethods)
+ ->onlyMethods($requiredMethods)
->getMock();
$this->connection->setConfiguration([
@@ -963,17 +927,15 @@ class UserTest extends \Test\TestCase {
\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
}
- public function emptyHomeFolderAttributeValueProvider() {
+ public static function emptyHomeFolderAttributeValueProvider(): array {
return [
'empty' => [''],
'prefixOnly' => ['attr:'],
];
}
- /**
- * @dataProvider emptyHomeFolderAttributeValueProvider
- */
- public function testGetHomePathNotConfigured($attributeValue) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('emptyHomeFolderAttributeValueProvider')]
+ public function testGetHomePathNotConfigured(string $attributeValue): void {
$this->connection->expects($this->any())
->method('__get')
->with($this->equalTo('homeFolderNamingRule'))
@@ -989,7 +951,7 @@ class UserTest extends \Test\TestCase {
$this->assertFalse($this->user->getHomePath());
}
- public function testGetHomePathConfiguredNotAvailableAllowed() {
+ public function testGetHomePathConfiguredNotAvailableAllowed(): void {
$this->connection->expects($this->any())
->method('__get')
->with($this->equalTo('homeFolderNamingRule'))
@@ -1013,7 +975,7 @@ class UserTest extends \Test\TestCase {
}
- public function testGetHomePathConfiguredNotAvailableNotAllowed() {
+ public function testGetHomePathConfiguredNotAvailableNotAllowed(): void {
$this->expectException(\Exception::class);
$this->connection->expects($this->any())
@@ -1037,20 +999,17 @@ class UserTest extends \Test\TestCase {
$this->user->getHomePath();
}
- public function displayNameProvider() {
+ public static function displayNameProvider(): array {
return [
['Roland Deschain', '', 'Roland Deschain', false],
['Roland Deschain', '', 'Roland Deschain', true],
- ['Roland Deschain', null, 'Roland Deschain', false],
['Roland Deschain', 'gunslinger@darktower.com', 'Roland Deschain (gunslinger@darktower.com)', false],
['Roland Deschain', 'gunslinger@darktower.com', 'Roland Deschain (gunslinger@darktower.com)', true],
];
}
- /**
- * @dataProvider displayNameProvider
- */
- public function testComposeAndStoreDisplayName($part1, $part2, $expected, $expectTriggerChange) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('displayNameProvider')]
+ public function testComposeAndStoreDisplayName(string $part1, string $part2, string $expected, bool $expectTriggerChange): void {
$this->config->expects($this->once())
->method('setUserValue');
$oldName = $expectTriggerChange ? 'xxGunslingerxx' : null;
@@ -1076,7 +1035,7 @@ class UserTest extends \Test\TestCase {
$this->assertSame($expected, $displayName);
}
- public function testComposeAndStoreDisplayNameNoOverwrite() {
+ public function testComposeAndStoreDisplayNameNoOverwrite(): void {
$displayName = 'Randall Flagg';
$this->config->expects($this->never())
->method('setUserValue');
@@ -1091,7 +1050,7 @@ class UserTest extends \Test\TestCase {
$this->assertSame($composedDisplayName, $displayName);
}
- public function testHandlePasswordExpiryWarningDefaultPolicy() {
+ public function testHandlePasswordExpiryWarningDefaultPolicy(): void {
$this->connection->expects($this->any())
->method('__get')
->willReturnCallback(function ($name) {
@@ -1110,7 +1069,7 @@ class UserTest extends \Test\TestCase {
if ($base === $this->dn) {
return [
[
- 'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
+ 'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis') . 'Z'],
'pwdgraceusetime' => [],
],
];
@@ -1149,12 +1108,12 @@ class UserTest extends \Test\TestCase {
->method('notify');
\OC_Hook::clear();//disconnect irrelevant hooks
- \OCP\Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
+ Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
/** @noinspection PhpUnhandledExceptionInspection */
\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
}
- public function testHandlePasswordExpiryWarningCustomPolicy() {
+ public function testHandlePasswordExpiryWarningCustomPolicy(): void {
$this->connection->expects($this->any())
->method('__get')
->willReturnCallback(function ($name) {
@@ -1174,7 +1133,7 @@ class UserTest extends \Test\TestCase {
return [
[
'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'],
- 'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
+ 'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis') . 'Z'],
'pwdgraceusetime' => [],
]
];
@@ -1213,7 +1172,7 @@ class UserTest extends \Test\TestCase {
->method('notify');
\OC_Hook::clear();//disconnect irrelevant hooks
- \OCP\Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
+ Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
/** @noinspection PhpUnhandledExceptionInspection */
\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
}