aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/User/ManagerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/User/ManagerTest.php')
-rw-r--r--apps/user_ldap/tests/User/ManagerTest.php113
1 files changed, 31 insertions, 82 deletions
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);