Skip to content

Commit

Permalink
Add missing mock result for getGroupMembers
Browse files Browse the repository at this point in the history
getGroupMembers did not return any results from the mock so the called
would get null.

Fixes issue with PHP 7.2 where calling count() with null fails.
  • Loading branch information
Vincent Petry authored and Vincent Petry committed Aug 31, 2018
1 parent fd064d5 commit 3f4f910
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions tests/unit/Dav/MembershipNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public function testNodeName() {
}

public function testDeleteAsAdmin() {
$this->setCurrentUserMemberInfo(['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_ADMIN]);
$memberInfo = ['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_ADMIN];
$this->setCurrentUserMemberInfo($memberInfo);
$this->handler->expects($this->once())
->method('removeFromGroup')
->with(self::NODE_USER, 1)
Expand All @@ -155,6 +156,13 @@ public function testDeleteAsAdmin() {
['group_id' => 1, 'user_id' => self::NODE_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_ADMIN]
);

$searchAdmins = new Search();
$searchAdmins->setRoleFilter(CustomGroupsDatabaseHandler::ROLE_ADMIN);
$this->handler->expects($this->once())
->method('getGroupMembers')
->with(1, $searchAdmins)
->willReturn([$memberInfo]);

$called = array();
\OC::$server->getEventDispatcher()->addListener('\OCA\CustomGroups::removeUserFromGroup', function ($event) use (&$called) {
$called[] = '\OCA\CustomGroups::removeUserFromGroup';
Expand All @@ -173,12 +181,20 @@ public function testDeleteAsAdmin() {
* @expectedException \Sabre\DAV\Exception\PreconditionFailed
*/
public function testDeleteAsAdminFailed() {
$this->setCurrentUserMemberInfo(['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_ADMIN]);
$memberInfo = ['group_id' => 1, 'user_id' => self::CURRENT_USER, 'role' => CustomGroupsDatabaseHandler::ROLE_ADMIN];
$this->setCurrentUserMemberInfo($memberInfo);
$this->handler->expects($this->once())
->method('removeFromGroup')
->with(self::NODE_USER, 1)
->willReturn(false);

$searchAdmins = new Search();
$searchAdmins->setRoleFilter(CustomGroupsDatabaseHandler::ROLE_ADMIN);
$this->handler->expects($this->once())
->method('getGroupMembers')
->with(1, $searchAdmins)
->willReturn([$memberInfo]);

$this->node->delete();
}

Expand Down Expand Up @@ -239,6 +255,13 @@ public function testDeleteSelfAsNonAdmin() {
->with(self::NODE_USER, 1)
->willReturn(true);

$searchAdmins = new Search();
$searchAdmins->setRoleFilter(CustomGroupsDatabaseHandler::ROLE_ADMIN);
$this->handler->expects($this->once())
->method('getGroupMembers')
->with(1, $searchAdmins)
->willReturn([['uid' => 'adminuser']]);

// no notification in this case
$this->helper->expects($this->never())
->method('notifyUserRemoved');
Expand Down Expand Up @@ -271,6 +294,13 @@ public function testDeleteAsSuperAdmin() {
->with(self::NODE_USER, 1)
->willReturn(true);

$searchAdmins = new Search();
$searchAdmins->setRoleFilter(CustomGroupsDatabaseHandler::ROLE_ADMIN);
$this->handler->expects($this->once())
->method('getGroupMembers')
->with(1, $searchAdmins)
->willReturn([['uid' => 'adminuser']]);

$this->node->delete();
}

Expand Down

0 comments on commit 3f4f910

Please sign in to comment.