summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests/Controller
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-01-17 11:59:05 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-01-17 11:59:15 +0100
commit4915d64de8d0ee862f0fdc92fe9bf856f3e8cbe1 (patch)
tree90a6ae7c6921c5d5fa1f16aafcb58c10da6e4c09 /apps/provisioning_api/tests/Controller
parentac6ee0b8b7d06deb5285b99ed55df5baae9d821f (diff)
downloadnextcloud-server-4915d64de8d0ee862f0fdc92fe9bf856f3e8cbe1.tar.gz
nextcloud-server-4915d64de8d0ee862f0fdc92fe9bf856f3e8cbe1.zip
ignore non existing users when retrieving details of group members
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/provisioning_api/tests/Controller')
-rw-r--r--apps/provisioning_api/tests/Controller/GroupsControllerTest.php84
1 files changed, 76 insertions, 8 deletions
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
index 2ed62a67841..b22953ca043 100644
--- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
@@ -29,6 +29,7 @@ namespace OCA\Provisioning_API\Tests\Controller;
use OC\Accounts\AccountManager;
use OC\Group\Manager;
use OC\SubAdmin;
+use OC\User\NoUserException;
use OCA\Provisioning_API\Controller\GroupsController;
use OCP\IConfig;
use OCP\ILogger;
@@ -36,27 +37,31 @@ use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\UserInterface;
class GroupsControllerTest extends \Test\TestCase {
- /** @var IRequest|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
protected $request;
- /** @var IUserManager|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager;
- /** @var IConfig|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
- /** @var Manager|PHPUnit_Framework_MockObject_MockObject */
+ /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
protected $groupManager;
- /** @var IUserSession|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
protected $userSession;
- /** @var AccountManager|PHPUnit_Framework_MockObject_MockObject */
+ /** @var AccountManager|\PHPUnit_Framework_MockObject_MockObject */
protected $accountManager;
- /** @var ILogger|PHPUnit_Framework_MockObject_MockObject */
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
protected $logger;
+ /** @var SubAdmin|\PHPUnit_Framework_MockObject_MockObject */
+ protected $subAdminManager;
- /** @var GroupsController|PHPUnit_Framework_MockObject_MockObject */
+ /** @var GroupsController|\PHPUnit_Framework_MockObject_MockObject */
protected $api;
+
protected function setUp() {
parent::setUp();
@@ -126,6 +131,10 @@ class GroupsControllerTest extends \Test\TestCase {
$user
->method('getUID')
->willReturn($uid);
+ $backendMock = $this->createMock(UserInterface::class);
+ $user
+ ->method('getBackend')
+ ->willReturn($backendMock);
return $user;
}
@@ -164,6 +173,19 @@ class GroupsControllerTest extends \Test\TestCase {
}));
}
+ private function useAccountManager() {
+ $this->accountManager->expects($this->any())
+ ->method('getUser')
+ ->willReturnCallback(function(IUser $user) {
+ return [
+ AccountManager::PROPERTY_PHONE => ['value' => '0800-call-' . $user->getUID()],
+ AccountManager::PROPERTY_ADDRESS => ['value' => 'Holzweg 99, 0601 Herrera, Panama'],
+ AccountManager::PROPERTY_WEBSITE => ['value' => 'https://' . $user->getUid() . '.pa'],
+ AccountManager::PROPERTY_TWITTER => ['value' => '@' . $user->getUID()],
+ ];
+ });
+ }
+
public function dataGetGroups() {
return [
[null, 0, 0],
@@ -454,4 +476,50 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->deleteGroup('ExistingGroup');
}
+
+ public function testGetGroupUsersDetails() {
+ $gid = 'ncg1';
+
+ $this->asAdmin();
+ $this->useAccountManager();
+
+ $users = [
+ 'ncu1' => $this->createUser('ncu1'), # regular
+ 'ncu2' => $this->createUser('ncu2'), # the zombie
+ ];
+ $users['ncu2']->expects($this->atLeastOnce())
+ ->method('getHome')
+ ->willThrowException(new NoUserException());
+
+ $this->userManager->expects($this->any())
+ ->method('get')
+ ->willReturnCallback(function(string $uid) use ($users) {
+ return isset($users[$uid]) ? $users[$uid] : null;
+ });
+
+ $group = $this->createGroup($gid);
+ $group->expects($this->once())
+ ->method('searchUsers')
+ ->with('', null, 0)
+ ->willReturn(array_values($users));
+
+ $this->groupManager
+ ->method('get')
+ ->with($gid)
+ ->willReturn($group);
+ $this->groupManager->expects($this->any())
+ ->method('getUserGroups')
+ ->willReturn([$group]);
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ $this->subAdminManager->expects($this->any())
+ ->method('isSubAdminOfGroup')
+ ->willReturn(false);
+ $this->subAdminManager->expects($this->any())
+ ->method('getSubAdminsGroups')
+ ->willReturn([]);
+
+
+ $this->api->getGroupUsersDetails($gid);
+ }
}