list($prefix, $name) = URLUtil::splitPath($principal);
if ($prefix === 'principals/users') {
- $principal = $this->getPrincipalByPath($principal);
- if (!$principal) {
+ $user = $this->userManager->get($name);
+ if (!$user) {
throw new Exception('Principal not found');
}
- $user = $this->userManager->get($name);
$groups = $this->groupManager->getUserGroups($user);
$groups = array_map(function($group) {
/** @var IGroup $group */
}
return $principal;
}
+
}
use OCP\IGroupManager;
use \Sabre\DAV\PropPatch;
use OCP\IUserManager;
+use Test\TestCase;
-class Principal extends \Test\TestCase {
- /** @var IUserManager */
+class Principal extends TestCase {
+ /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
private $userManager;
/** @var \OCA\DAV\Connector\Sabre\Principal */
private $connector;
- /** @var IGroupManager */
+ /** @var IGroupManager | \PHPUnit_Framework_MockObject_MockObject */
private $groupManager;
public function setUp() {
public function testGetGroupMembership() {
$fooUser = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
- $fooUser
- ->expects($this->exactly(1))
- ->method('getUID')
- ->will($this->returnValue('foo'));
$this->userManager
->expects($this->once())
->method('get')
->with('foo')
- ->will($this->returnValue($fooUser));
+ ->willReturn($fooUser);
+ $this->groupManager
+ ->method('getUserGroups')
+ ->willReturn([]);
$expectedResponse = [
'principals/users/foo/calendar-proxy-read',