mirror of
https://github.com/nextcloud/server.git
synced 2026-02-13 07:45:08 -05:00
Fix unit test - optimize code
This commit is contained in:
parent
8b8edc1f5d
commit
992ccc899a
2 changed files with 11 additions and 11 deletions
|
|
@ -133,12 +133,11 @@ class Principal implements BackendInterface {
|
|||
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 */
|
||||
|
|
@ -212,4 +211,5 @@ class Principal implements BackendInterface {
|
|||
}
|
||||
return $principal;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,14 @@ namespace OCA\DAV\Tests\Unit\Connector\Sabre;
|
|||
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() {
|
||||
|
|
@ -201,15 +202,14 @@ class Principal extends \Test\TestCase {
|
|||
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',
|
||||
|
|
|
|||
Loading…
Reference in a new issue