2016-01-08 14:11:02 +03:00
|
|
|
<?php
|
2016-01-12 17:02:16 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2016-05-25 17:04:15 +03:00
|
|
|
|
|
|
|
namespace OCA\DAV\Tests\unit\DAV;
|
2016-01-08 14:11:02 +03:00
|
|
|
|
2017-01-09 23:20:55 +03:00
|
|
|
use OC\Group\Group;
|
2016-01-08 14:11:02 +03:00
|
|
|
use OCA\DAV\DAV\GroupPrincipalBackend;
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
use PHPUnit_Framework_MockObject_MockObject;
|
|
|
|
use \Sabre\DAV\PropPatch;
|
|
|
|
|
|
|
|
class GroupPrincipalTest extends \Test\TestCase {
|
|
|
|
|
|
|
|
/** @var IGroupManager | PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $groupManager;
|
|
|
|
|
|
|
|
/** @var GroupPrincipalBackend */
|
|
|
|
private $connector;
|
|
|
|
|
|
|
|
public function setUp() {
|
2017-01-09 23:20:55 +03:00
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2016-01-08 14:11:02 +03:00
|
|
|
|
|
|
|
$this->connector = new GroupPrincipalBackend($this->groupManager);
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixWithoutPrefix() {
|
|
|
|
$response = $this->connector->getPrincipalsByPrefix('');
|
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixWithUsers() {
|
|
|
|
$group1 = $this->mockGroup('foo');
|
|
|
|
$group2 = $this->mockGroup('bar');
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue([$group1, $group2]));
|
|
|
|
|
|
|
|
$expectedResponse = [
|
|
|
|
0 => [
|
|
|
|
'uri' => 'principals/groups/foo',
|
|
|
|
'{DAV:}displayname' => 'foo'
|
|
|
|
],
|
|
|
|
1 => [
|
|
|
|
'uri' => 'principals/groups/bar',
|
|
|
|
'{DAV:}displayname' => 'bar',
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$response = $this->connector->getPrincipalsByPrefix('principals/groups');
|
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPrefixEmpty() {
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with('')
|
|
|
|
->will($this->returnValue([]));
|
|
|
|
|
|
|
|
$response = $this->connector->getPrincipalsByPrefix('principals/groups');
|
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathWithoutMail() {
|
|
|
|
$group1 = $this->mockGroup('foo');
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue($group1));
|
|
|
|
|
|
|
|
$expectedResponse = [
|
|
|
|
'uri' => 'principals/groups/foo',
|
|
|
|
'{DAV:}displayname' => 'foo'
|
|
|
|
];
|
|
|
|
$response = $this->connector->getPrincipalByPath('principals/groups/foo');
|
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathWithMail() {
|
|
|
|
$fooUser = $this->mockGroup('foo');
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue($fooUser));
|
|
|
|
|
|
|
|
$expectedResponse = [
|
|
|
|
'uri' => 'principals/groups/foo',
|
|
|
|
'{DAV:}displayname' => 'foo',
|
|
|
|
];
|
|
|
|
$response = $this->connector->getPrincipalByPath('principals/groups/foo');
|
|
|
|
$this->assertSame($expectedResponse, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPrincipalsByPathEmpty() {
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->returnValue(null));
|
|
|
|
|
|
|
|
$response = $this->connector->getPrincipalByPath('principals/groups/foo');
|
|
|
|
$this->assertSame(null, $response);
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:20:55 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-01-08 14:11:02 +03:00
|
|
|
public function testGetGroupMemberSet() {
|
|
|
|
$response = $this->connector->getGroupMemberSet('principals/groups/foo');
|
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetGroupMembership() {
|
|
|
|
$response = $this->connector->getGroupMembership('principals/groups/foo');
|
|
|
|
$this->assertSame([], $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception
|
|
|
|
* @expectedExceptionMessage Setting members of the group is not supported yet
|
|
|
|
*/
|
|
|
|
public function testSetGroupMembership() {
|
|
|
|
$this->connector->setGroupMemberSet('principals/groups/foo', ['foo']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdatePrincipal() {
|
|
|
|
$this->assertSame(0, $this->connector->updatePrincipal('foo', new PropPatch(array())));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearchPrincipals() {
|
|
|
|
$this->assertSame([], $this->connector->searchPrincipals('principals/groups', []));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-09 23:20:55 +03:00
|
|
|
* @return Group|\PHPUnit_Framework_MockObject_MockObject
|
2016-01-08 14:11:02 +03:00
|
|
|
*/
|
|
|
|
private function mockGroup($gid) {
|
2017-01-09 23:20:55 +03:00
|
|
|
$fooGroup = $this->createMock(Group::class);
|
|
|
|
$fooGroup
|
2016-01-08 14:11:02 +03:00
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getGID')
|
|
|
|
->will($this->returnValue($gid));
|
2017-01-09 23:20:55 +03:00
|
|
|
return $fooGroup;
|
2016-01-08 14:11:02 +03:00
|
|
|
}
|
|
|
|
}
|