* @return array
*/
public function getPrincipalByPath($path) {
- $elements = explode('/', $path);
+ $elements = explode('/', $path, 3);
if ($elements[0] !== 'principals') {
return null;
}
if ($elements[1] !== 'groups') {
return null;
}
- $name = $elements[2];
+ $name = urldecode($elements[2]);
$group = $this->groupManager->get($name);
if (!is_null($group)) {
protected function groupToPrincipal($group) {
$groupId = $group->getGID();
$principal = [
- 'uri' => "principals/groups/$groupId",
+ 'uri' => 'principals/groups/' . urlencode($groupId),
'{DAV:}displayname' => $groupId,
];
namespace OCA\DAV\Tests\unit\Connector\Sabre;
+use OC\User\User;
+use OCP\IGroup;
use OCP\IGroupManager;
use \Sabre\DAV\PropPatch;
use OCP\IUserManager;
private $groupManager;
public function setUp() {
- $this->userManager = $this->getMockBuilder('\OCP\IUserManager')
- ->disableOriginalConstructor()->getMock();
- $this->groupManager = $this->getMockBuilder('\OCP\IGroupManager')
- ->disableOriginalConstructor()->getMock();
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
$this->connector = new \OCA\DAV\Connector\Sabre\Principal(
$this->userManager,
}
public function testGetPrincipalsByPrefixWithUsers() {
- $fooUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $fooUser = $this->createMock(User::class);
$fooUser
->expects($this->exactly(1))
->method('getUID')
->expects($this->exactly(1))
->method('getEMailAddress')
->will($this->returnValue(''));
- $barUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $barUser = $this->createMock(User::class);
$barUser
->expects($this->exactly(1))
->method('getUID')
}
public function testGetPrincipalsByPathWithoutMail() {
- $fooUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $fooUser = $this->createMock(User::class);
$fooUser
->expects($this->exactly(1))
->method('getUID')
}
public function testGetPrincipalsByPathWithMail() {
- $fooUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $fooUser = $this->createMock(User::class);
$fooUser
->expects($this->exactly(1))
->method('getEMailAddress')
}
public function testGetGroupMemberSet() {
- $fooUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $fooUser = $this->createMock(User::class);
$fooUser
->expects($this->exactly(1))
->method('getUID')
}
public function testGetGroupMembership() {
- $fooUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
- $group = $this->getMockBuilder('\OCP\IGroup')
- ->disableOriginalConstructor()->getMock();
- $group->expects($this->once())
+ $fooUser = $this->createMock(User::class);
+ $group1 = $this->createMock(IGroup::class);
+ $group1->expects($this->once())
->method('getGID')
->willReturn('group1');
+ $group2 = $this->createMock(IGroup::class);
+ $group2->expects($this->once())
+ ->method('getGID')
+ ->willReturn('foo/bar');
$this->userManager
->expects($this->once())
->method('get')
$this->groupManager
->expects($this->once())
->method('getUserGroups')
+ ->with($fooUser)
->willReturn([
- $group
+ $group1,
+ $group2,
]);
$expectedResponse = [
- 'principals/groups/group1'
+ 'principals/groups/group1',
+ 'principals/groups/foo%2Fbar',
];
$response = $this->connector->getGroupMembership('principals/users/foo');
$this->assertSame($expectedResponse, $response);
}
public function testFindByUri() {
- $fooUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $fooUser = $this->createMock(User::class);
$fooUser
->expects($this->exactly(1))
->method('getUID')
namespace OCA\DAV\Tests\unit\DAV;
+use OC\Group\Group;
use OCA\DAV\DAV\GroupPrincipalBackend;
use OCP\IGroupManager;
use PHPUnit_Framework_MockObject_MockObject;
private $connector;
public function setUp() {
- $this->groupManager = $this->getMockBuilder('\OCP\IGroupManager')
- ->disableOriginalConstructor()->getMock();
+ $this->groupManager = $this->createMock(IGroupManager::class);
$this->connector = new GroupPrincipalBackend($this->groupManager);
parent::setUp();
$this->assertSame(null, $response);
}
+ public function testGetPrincipalsByPathGroupWithSlash() {
+ $group1 = $this->mockGroup('foo/bar');
+ $this->groupManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('foo/bar')
+ ->will($this->returnValue($group1));
+
+ $expectedResponse = [
+ 'uri' => 'principals/groups/foo%2Fbar',
+ '{DAV:}displayname' => 'foo/bar'
+ ];
+ $response = $this->connector->getPrincipalByPath('principals/groups/foo/bar');
+ $this->assertSame($expectedResponse, $response);
+ }
+
public function testGetGroupMemberSet() {
$response = $this->connector->getGroupMemberSet('principals/groups/foo');
$this->assertSame([], $response);
}
/**
- * @return PHPUnit_Framework_MockObject_MockObject
+ * @return Group|\PHPUnit_Framework_MockObject_MockObject
*/
private function mockGroup($gid) {
- $fooUser = $this->getMockBuilder('\OC\Group\Group')
- ->disableOriginalConstructor()->getMock();
- $fooUser
+ $fooGroup = $this->createMock(Group::class);
+ $fooGroup
->expects($this->exactly(1))
->method('getGID')
->will($this->returnValue($gid));
- return $fooUser;
+ return $fooGroup;
}
}