Skip to content

Commit

Permalink
Fix user_ldap unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Apr 1, 2022
1 parent 91d6e88 commit d7a2910
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions apps/user_ldap/lib/GroupPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function createGroup($gid) {
}

public function canDeleteGroup(): bool {
return !$this->suppressDeletion && ($this->which[GroupInterface::DELETE_GROUP] !== null);
return !$this->suppressDeletion && $this->implementsActions(GroupInterface::DELETE_GROUP);
}

/**
Expand All @@ -102,11 +102,10 @@ public function setSuppressDeletion(bool $value): bool {

/**
* Delete a group
* @param string $gid Group Id of the group to delete
* @return bool
*
* @throws \Exception
*/
public function deleteGroup($gid) {
public function deleteGroup(string $gid): bool {
$plugin = $this->which[GroupInterface::DELETE_GROUP];

if ($plugin) {
Expand Down
16 changes: 8 additions & 8 deletions apps/user_ldap/tests/GroupLDAPPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testCreateGroup() {
$pluginManager->createGroup('group');
}


public function testCreateGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements createGroup in this LDAP Backend.');
Expand All @@ -108,13 +108,13 @@ public function testDeleteGroup() {
->method('deleteGroup')
->with(
$this->equalTo('group')
);
)->willReturn(true);

$pluginManager->register($plugin);
$pluginManager->deleteGroup('group');
$this->assertTrue($pluginManager->deleteGroup('group'));
}


public function testDeleteGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements deleteGroup in this LDAP Backend.');
Expand Down Expand Up @@ -145,7 +145,7 @@ public function testAddToGroup() {
$pluginManager->addToGroup('uid', 'gid');
}


public function testAddToGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements addToGroup in this LDAP Backend.');
Expand Down Expand Up @@ -176,7 +176,7 @@ public function testRemoveFromGroup() {
$pluginManager->removeFromGroup('uid', 'gid');
}


public function testRemoveFromGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements removeFromGroup in this LDAP Backend.');
Expand Down Expand Up @@ -207,7 +207,7 @@ public function testCountUsersInGroup() {
$pluginManager->countUsersInGroup('gid', 'search');
}


public function testCountUsersInGroupNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements countUsersInGroup in this LDAP Backend.');
Expand Down Expand Up @@ -237,7 +237,7 @@ public function testgetGroupDetails() {
$pluginManager->getGroupDetails('gid');
}


public function testgetGroupDetailsNotRegistered() {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('No plugin implements getGroupDetails in this LDAP Backend.');
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/tests/Group_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ public function testDeleteGroupWithPlugin() {
$pluginManager->expects($this->once())
->method('deleteGroup')
->with('gid')
->willReturn('result');
->willReturn(true);

$mapper = $this->getMockBuilder(GroupMapping::class)
->setMethods(['unmap'])
Expand All @@ -1108,7 +1108,7 @@ public function testDeleteGroupWithPlugin() {

$ldap = new GroupLDAP($access, $pluginManager);

$this->assertEquals($ldap->deleteGroup('gid'), 'result');
$this->assertTrue($ldap->deleteGroup('gid'));
}


Expand Down

0 comments on commit d7a2910

Please sign in to comment.