diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-08 12:11:02 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-08 12:11:02 +0100 |
commit | f9c08112da9e263ccb98a48c228deb31f3046b61 (patch) | |
tree | 51605b4a4b73f208ac538baf58820c1f3274c1a3 /apps/dav/tests | |
parent | a0345b94650f9ded7b86d53b27624557868747e4 (diff) | |
download | nextcloud-server-f9c08112da9e263ccb98a48c228deb31f3046b61.tar.gz nextcloud-server-f9c08112da9e263ccb98a48c228deb31f3046b61.zip |
Adding group principals to new dav endpoint
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/principal.php | 6 | ||||
-rw-r--r-- | apps/dav/tests/unit/dav/groupprincipaltest.php | 146 |
2 files changed, 147 insertions, 5 deletions
diff --git a/apps/dav/tests/unit/connector/sabre/principal.php b/apps/dav/tests/unit/connector/sabre/principal.php index 9a6ae545b58..160d5744260 100644 --- a/apps/dav/tests/unit/connector/sabre/principal.php +++ b/apps/dav/tests/unit/connector/sabre/principal.php @@ -17,18 +17,14 @@ use OCP\IConfig; class Principal extends \Test\TestCase { /** @var IUserManager */ private $userManager; - /** @var IConfig */ - private $config; /** @var \OCA\DAV\Connector\Sabre\Principal */ private $connector; public function setUp() { $this->userManager = $this->getMockBuilder('\OCP\IUserManager') ->disableOriginalConstructor()->getMock(); - $this->config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor()->getMock(); - $this->connector = new \OCA\DAV\Connector\Sabre\Principal($this->config, $this->userManager); + $this->connector = new \OCA\DAV\Connector\Sabre\Principal($this->userManager); parent::setUp(); } diff --git a/apps/dav/tests/unit/dav/groupprincipaltest.php b/apps/dav/tests/unit/dav/groupprincipaltest.php new file mode 100644 index 00000000000..bb1bd2526ed --- /dev/null +++ b/apps/dav/tests/unit/dav/groupprincipaltest.php @@ -0,0 +1,146 @@ +<?php + +namespace OCA\DAV\Tests\Unit\DAV; + +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() { + $this->groupManager = $this->getMockBuilder('\OCP\IGroupManager') + ->disableOriginalConstructor()->getMock(); + + $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); + } + + 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', [])); + } + + /** + * @return PHPUnit_Framework_MockObject_MockObject + */ + private function mockGroup($gid) { + $fooUser = $this->getMockBuilder('\OC\Group\Group') + ->disableOriginalConstructor()->getMock(); + $fooUser + ->expects($this->exactly(1)) + ->method('getGID') + ->will($this->returnValue($gid)); + return $fooUser; + } +} |