aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/Group_LDAPTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/Group_LDAPTest.php')
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php112
1 files changed, 45 insertions, 67 deletions
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index ad97d5024b1..10182111768 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -34,10 +35,10 @@ use Test\TestCase;
* @package OCA\User_LDAP\Tests
*/
class Group_LDAPTest extends TestCase {
- private MockObject|Access $access;
- private MockObject|GroupPluginManager $pluginManager;
- private MockObject|IConfig $config;
- private MockObject|IUserManager $ncUserManager;
+ private Access&MockObject $access;
+ private GroupPluginManager&MockObject $pluginManager;
+ private IConfig&MockObject $config;
+ private IUserManager&MockObject $ncUserManager;
private GroupLDAP $groupBackend;
public function setUp(): void {
@@ -96,30 +97,19 @@ class Group_LDAPTest extends TestCase {
* @return MockObject|Access
*/
private function getAccessMock() {
- static $conMethods;
- static $accMethods;
-
- if (is_null($conMethods) || is_null($accMethods)) {
- $conMethods = get_class_methods(Connection::class);
- $accMethods = get_class_methods(Access::class);
- }
$lw = $this->createMock(ILDAPWrapper::class);
-
$connector = $this->getMockBuilder(Connection::class)
- ->setMethods($conMethods)
->setConstructorArgs([$lw, '', null])
->getMock();
$this->access = $this->createMock(Access::class);
-
$this->access->connection = $connector;
-
$this->access->userManager = $this->createMock(Manager::class);
return $this->access;
}
- private function enableGroups() {
+ private function enableGroups(): void {
$this->access->connection->expects($this->any())
->method('__get')
->willReturnCallback(function ($name) {
@@ -179,7 +169,7 @@ class Group_LDAPTest extends TestCase {
public function testCountUsersWithPlugin(): void {
/** @var GroupPluginManager|MockObject $pluginManager */
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'countUsersInGroup'])
+ ->onlyMethods(['implementsActions', 'countUsersInGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -470,7 +460,7 @@ class Group_LDAPTest extends TestCase {
$this->groupBackend->inGroup($uid, $gid);
}
- public function groupWithMembersProvider() {
+ public static function groupWithMembersProvider(): array {
return [
[
'someGroup',
@@ -485,9 +475,7 @@ class Group_LDAPTest extends TestCase {
];
}
- /**
- * @dataProvider groupWithMembersProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('groupWithMembersProvider')]
public function testInGroupMember(string $gid, string $groupDn, array $memberDNs): void {
$uid = 'someUser';
$userDn = $memberDNs[0];
@@ -526,9 +514,7 @@ class Group_LDAPTest extends TestCase {
$this->assertTrue($this->groupBackend->inGroup($uid, $gid));
}
- /**
- * @dataProvider groupWithMembersProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('groupWithMembersProvider')]
public function testInGroupMemberNot(string $gid, string $groupDn, array $memberDNs): void {
$uid = 'unelatedUser';
$userDn = 'uid=unrelatedUser,ou=unrelatedTeam,ou=unrelatedDepartment,dc=someDomain,dc=someTld';
@@ -567,14 +553,12 @@ class Group_LDAPTest extends TestCase {
$this->assertFalse($this->groupBackend->inGroup($uid, $gid));
}
- /**
- * @dataProvider groupWithMembersProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('groupWithMembersProvider')]
public function testInGroupMemberUid(string $gid, string $groupDn, array $memberDNs): void {
$memberUids = [];
$userRecords = [];
foreach ($memberDNs as $dn) {
- $memberUids[] = ldap_explode_dn($dn, false)[0];
+ $memberUids[] = ldap_explode_dn($dn, 0)[0];
$userRecords[] = ['dn' => [$dn]];
}
@@ -777,8 +761,7 @@ class Group_LDAPTest extends TestCase {
->method('username2dn')
->willReturn($dn);
$this->access->expects($this->exactly(5))
- ->method('readAttribute')
- ->will($this->onConsecutiveCalls($expectedGroups, [], [], [], []));
+ ->method('readAttribute')->willReturnOnConsecutiveCalls($expectedGroups, [], [], [], []);
$this->access->expects($this->any())
->method('dn2groupname')
->willReturnArgument(0);
@@ -876,8 +859,8 @@ class Group_LDAPTest extends TestCase {
$this->initBackend();
$returnedGroups = $this->groupBackend->getUserGroups('userX');
$this->assertCount(2, $returnedGroups);
- $this->assertTrue(in_array('groupB', $returnedGroups));
- $this->assertTrue(in_array('groupF', $returnedGroups));
+ $this->assertContains('groupB', $returnedGroups);
+ $this->assertContains('groupF', $returnedGroups);
}
/**
@@ -903,8 +886,8 @@ class Group_LDAPTest extends TestCase {
$this->initBackend();
$returnedGroups = $this->groupBackend->getUserGroups('userX');
$this->assertCount(2, $returnedGroups);
- $this->assertTrue(in_array('groupB', $returnedGroups));
- $this->assertTrue(in_array('groupF', $returnedGroups));
+ $this->assertContains('groupB', $returnedGroups);
+ $this->assertContains('groupF', $returnedGroups);
}
public function testGetUserGroupsUnrecognizedOfflineUser(): void {
@@ -946,20 +929,18 @@ class Group_LDAPTest extends TestCase {
$this->initBackend();
$returnedGroups = $this->groupBackend->getUserGroups('userX');
$this->assertCount(2, $returnedGroups);
- $this->assertTrue(in_array('groupB', $returnedGroups));
- $this->assertTrue(in_array('groupF', $returnedGroups));
+ $this->assertContains('groupB', $returnedGroups);
+ $this->assertContains('groupF', $returnedGroups);
}
- public function nestedGroupsProvider(): array {
+ public static function nestedGroupsProvider(): array {
return [
[true],
[false],
];
}
- /**
- * @dataProvider nestedGroupsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('nestedGroupsProvider')]
public function testGetGroupsByMember(bool $nestedGroups): void {
$groupFilter = '(&(objectclass=nextcloudGroup)(nextcloudEnabled=TRUE))';
$this->access->connection->expects($this->any())
@@ -1076,7 +1057,7 @@ class Group_LDAPTest extends TestCase {
public function testCreateGroupWithPlugin(): void {
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'createGroup'])
+ ->onlyMethods(['implementsActions', 'createGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1090,7 +1071,7 @@ class Group_LDAPTest extends TestCase {
->willReturn('result');
$this->initBackend();
- $this->assertEquals($this->groupBackend->createGroup('gid'), true);
+ $this->assertTrue($this->groupBackend->createGroup('gid'));
}
@@ -1098,7 +1079,7 @@ class Group_LDAPTest extends TestCase {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'createGroup'])
+ ->onlyMethods(['implementsActions', 'createGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1112,7 +1093,7 @@ class Group_LDAPTest extends TestCase {
public function testDeleteGroupWithPlugin(): void {
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'deleteGroup'])
+ ->onlyMethods(['implementsActions', 'deleteGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1126,7 +1107,7 @@ class Group_LDAPTest extends TestCase {
->willReturn(true);
$mapper = $this->getMockBuilder(GroupMapping::class)
- ->setMethods(['unmap'])
+ ->onlyMethods(['unmap'])
->disableOriginalConstructor()
->getMock();
@@ -1143,7 +1124,7 @@ class Group_LDAPTest extends TestCase {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'deleteGroup'])
+ ->onlyMethods(['implementsActions', 'deleteGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1157,7 +1138,7 @@ class Group_LDAPTest extends TestCase {
public function testAddToGroupWithPlugin(): void {
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'addToGroup'])
+ ->onlyMethods(['implementsActions', 'addToGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1171,7 +1152,7 @@ class Group_LDAPTest extends TestCase {
->willReturn('result');
$this->initBackend();
- $this->assertEquals($this->groupBackend->addToGroup('uid', 'gid'), 'result');
+ $this->assertEquals('result', $this->groupBackend->addToGroup('uid', 'gid'));
}
@@ -1179,7 +1160,7 @@ class Group_LDAPTest extends TestCase {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'addToGroup'])
+ ->onlyMethods(['implementsActions', 'addToGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1193,7 +1174,7 @@ class Group_LDAPTest extends TestCase {
public function testRemoveFromGroupWithPlugin(): void {
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'removeFromGroup'])
+ ->onlyMethods(['implementsActions', 'removeFromGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1207,7 +1188,7 @@ class Group_LDAPTest extends TestCase {
->willReturn('result');
$this->initBackend();
- $this->assertEquals($this->groupBackend->removeFromGroup('uid', 'gid'), 'result');
+ $this->assertEquals('result', $this->groupBackend->removeFromGroup('uid', 'gid'));
}
@@ -1215,7 +1196,7 @@ class Group_LDAPTest extends TestCase {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'removeFromGroup'])
+ ->onlyMethods(['implementsActions', 'removeFromGroup'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1230,7 +1211,7 @@ class Group_LDAPTest extends TestCase {
public function testGetGroupDetailsWithPlugin(): void {
/** @var GroupPluginManager|MockObject $pluginManager */
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'getGroupDetails'])
+ ->onlyMethods(['implementsActions', 'getGroupDetails'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1244,14 +1225,14 @@ class Group_LDAPTest extends TestCase {
->willReturn('result');
$this->initBackend();
- $this->assertEquals($this->groupBackend->getGroupDetails('gid'), 'result');
+ $this->assertEquals('result', $this->groupBackend->getGroupDetails('gid'));
}
public function testGetGroupDetailsFailing(): void {
$this->expectException(\Exception::class);
$this->pluginManager = $this->getMockBuilder(GroupPluginManager::class)
- ->setMethods(['implementsActions', 'getGroupDetails'])
+ ->onlyMethods(['implementsActions', 'getGroupDetails'])
->getMock();
$this->pluginManager->expects($this->once())
@@ -1263,7 +1244,7 @@ class Group_LDAPTest extends TestCase {
$this->groupBackend->getGroupDetails('gid');
}
- public function groupMemberProvider() {
+ public static function groupMemberProvider(): array {
$base = 'dc=species,dc=earth';
$birdsDn = [
@@ -1331,11 +1312,8 @@ class Group_LDAPTest extends TestCase {
];
}
- /**
- * @param string[] $expectedMembers
- * @dataProvider groupMemberProvider
- */
- public function testGroupMembers(array $expectedResult, ?array $groupsInfo = null): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('groupMemberProvider')]
+ public function testGroupMembers(array $expectedResult, array $groupsInfo): void {
$this->access->expects($this->any())
->method('readAttribute')
->willReturnCallback(function ($group) use ($groupsInfo) {
@@ -1360,21 +1338,21 @@ class Group_LDAPTest extends TestCase {
foreach ($expectedResult as $groupDN => $expectedMembers) {
$resultingMembers = $this->invokePrivate($this->groupBackend, '_groupMembers', [$groupDN]);
- $this->assertEqualsCanonicalizing($expectedMembers, $resultingMembers);
+ sort($expectedMembers);
+ sort($resultingMembers);
+ $this->assertEquals($expectedMembers, $resultingMembers);
}
}
- public function displayNameProvider() {
+ public static function displayNameProvider(): array {
return [
['Graphic Novelists', ['Graphic Novelists']],
['', false],
];
}
- /**
- * @dataProvider displayNameProvider
- */
- public function testGetDisplayName(string $expected, $ldapResult): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('displayNameProvider')]
+ public function testGetDisplayName(string $expected, bool|array $ldapResult): void {
$gid = 'graphic_novelists';
$this->access->expects($this->atLeastOnce())