diff options
Diffstat (limited to 'apps/user_ldap/tests/User')
-rw-r--r-- | apps/user_ldap/tests/User/DeletedUsersIndexTest.php | 54 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/ManagerTest.php | 113 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/OfflineUserTest.php | 46 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/UserTest.php | 204 |
4 files changed, 128 insertions, 289 deletions
diff --git a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php index 7d0b49b21c8..b245e52fe6e 100644 --- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php +++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php @@ -1,27 +1,9 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\User_LDAP\Tests\User; @@ -29,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 @@ -39,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'); @@ -74,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', @@ -102,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 adeabea73e9..bf9d1f5746f 100644 --- a/apps/user_ldap/tests/User/ManagerTest.php +++ b/apps/user_ldap/tests/User/ManagerTest.php @@ -1,36 +1,15 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Philippe Jung <phil.jung@free.fr> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Roger Szabo <roger.szabo@web.de> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. 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-only */ 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; @@ -41,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; /** @@ -51,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); @@ -112,7 +66,6 @@ class ManagerTest extends \Test\TestCase { /** @noinspection PhpUnhandledExceptionInspection */ $this->manager = new Manager( $this->config, - $this->fileSystemHelper, $this->logger, $this->avatarManager, $this->image, @@ -124,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'], @@ -132,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()) @@ -160,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()) @@ -182,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'; @@ -208,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()) @@ -224,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', @@ -244,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 e1fda3f16ca..223e63421ad 100644 --- a/apps/user_ldap/tests/User/OfflineUserTest.php +++ b/apps/user_ldap/tests/User/OfflineUserTest.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\User_LDAP\Tests\User; @@ -30,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'; @@ -59,7 +37,7 @@ class OfflineUserTest extends TestCase { ); } - public function shareOwnerProvider(): array { + public static function shareOwnerProvider(): array { return [ [[], false], [[IShare::TYPE_USER], true], @@ -69,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 d6530faa9b6..00edd8b3f9b 100644 --- a/apps/user_ldap/tests/User/UserTest.php +++ b/apps/user_ldap/tests/User/UserTest.php @@ -1,36 +1,16 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Roger Szabo <roger.szabo@web.de> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. 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-only */ 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; @@ -40,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; /** @@ -50,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; @@ -87,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); @@ -99,7 +69,6 @@ class UserTest extends \Test\TestCase { $this->dn, $this->access, $this->config, - $this->filesystemhelper, $this->image, $this->logger, $this->avatarManager, @@ -108,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')) @@ -125,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()) @@ -139,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')) @@ -157,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')) @@ -172,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([ @@ -199,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([ @@ -226,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([ @@ -253,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([ @@ -280,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([ @@ -307,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([ @@ -335,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([ @@ -359,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)) @@ -388,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([ @@ -418,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([ @@ -445,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([ @@ -472,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([ @@ -528,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') @@ -550,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), @@ -579,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'); @@ -646,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') @@ -668,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) { @@ -701,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'); @@ -759,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()) @@ -782,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) { @@ -812,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'); @@ -826,7 +772,7 @@ class UserTest extends \Test\TestCase { $this->user->updateAvatar(); } - public function extStorageHomeDataProvider() { + public static function extStorageHomeDataProvider(): array { return [ [ 'myFolder', null ], [ '', null, false ], @@ -834,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') @@ -869,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), @@ -881,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), @@ -899,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()); @@ -911,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 ], @@ -919,7 +863,7 @@ class UserTest extends \Test\TestCase { ]; } - public function testProcessAttributes() { + public function testProcessAttributes(): void { $requiredMethods = [ 'updateQuota', 'updateEmail', @@ -930,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([ @@ -984,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')) @@ -1010,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')) @@ -1034,7 +975,7 @@ class UserTest extends \Test\TestCase { } - public function testGetHomePathConfiguredNotAvailableNotAllowed() { + public function testGetHomePathConfiguredNotAvailableNotAllowed(): void { $this->expectException(\Exception::class); $this->connection->expects($this->any()) @@ -1058,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; @@ -1097,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'); @@ -1112,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) { @@ -1131,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' => [], ], ]; @@ -1170,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) { @@ -1195,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' => [], ] ]; @@ -1234,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]); } |