diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-08 18:18:57 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-08 18:18:57 +0100 |
commit | 173c1640c03c76620d2814efcc0925d393e59176 (patch) | |
tree | 00cf7ac0784ed6f4d2bfe666a4b93402eeb06b2d /apps/dav/tests | |
parent | 6ab5ad059311477adacba9a547ab0ffbd130f075 (diff) | |
parent | bb01efdcbd0f290c7a6f26ca99fd89f09b29735d (diff) | |
download | nextcloud-server-173c1640c03c76620d2814efcc0925d393e59176.tar.gz nextcloud-server-173c1640c03c76620d2814efcc0925d393e59176.zip |
Merge pull request #21540 from owncloud/group-principals
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 | ||||
-rw-r--r-- | apps/dav/tests/unit/dav/systemprincipalbackendtest.php | 131 | ||||
-rw-r--r-- | apps/dav/tests/unit/phpunit.xml | 2 |
4 files changed, 279 insertions, 6 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; + } +} diff --git a/apps/dav/tests/unit/dav/systemprincipalbackendtest.php b/apps/dav/tests/unit/dav/systemprincipalbackendtest.php new file mode 100644 index 00000000000..96b1a8592c2 --- /dev/null +++ b/apps/dav/tests/unit/dav/systemprincipalbackendtest.php @@ -0,0 +1,131 @@ +<?php +/** + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @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/> + * + */ + +namespace OCA\DAV\Tests\DAV; + +use OCA\DAV\DAV\SystemPrincipalBackend; +use Test\TestCase; + +class SystemPrincipalBackendTest extends TestCase { + + /** + * @dataProvider providesPrefix + * @param $expected + * @param $prefix + */ + public function testGetPrincipalsByPrefix($expected, $prefix) { + $backend = new SystemPrincipalBackend(); + $result = $backend->getPrincipalsByPrefix($prefix); + $this->assertEquals($expected, $result); + } + + public function providesPrefix() { + return [ + [[], ''], + [[[ + 'uri' => 'principals/system/system', + '{DAV:}displayname' => 'system', + ]], 'principals/system'], + ]; + } + + /** + * @dataProvider providesPath + * @param $expected + * @param $path + */ + public function testGetPrincipalByPath($expected, $path) { + $backend = new SystemPrincipalBackend(); + $result = $backend->getPrincipalByPath($path); + $this->assertEquals($expected, $result); + } + + public function providesPath() { + return [ + [null, ''], + [null, 'principals'], + [null, 'principals/system'], + [[ + 'uri' => 'principals/system/system', + '{DAV:}displayname' => 'system', + ], 'principals/system/system'], + ]; + } + + /** + * @dataProvider providesPrincipalForGetGroupMemberSet + * @expectedException \Sabre\DAV\Exception + * @expectedExceptionMessage Principal not found + * + * @param string $principal + * @throws \Sabre\DAV\Exception + */ + public function testGetGroupMemberSetExceptional($principal) { + $backend = new SystemPrincipalBackend(); + $backend->getGroupMemberSet($principal); + } + + public function providesPrincipalForGetGroupMemberSet() { + return [ + [null], + ['principals/system'], + ]; + } + + /** + * @throws \Sabre\DAV\Exception + */ + public function testGetGroupMemberSet() { + $backend = new SystemPrincipalBackend(); + $result = $backend->getGroupMemberSet('principals/system/system'); + $this->assertEquals(['principals/system/system'], $result); + } + + /** + * @dataProvider providesPrincipalForGetGroupMembership + * @expectedException \Sabre\DAV\Exception + * @expectedExceptionMessage Principal not found + * + * @param string $principal + * @throws \Sabre\DAV\Exception + */ + public function testGetGroupMembershipExceptional($principal) { + $backend = new SystemPrincipalBackend(); + $backend->getGroupMembership($principal); + } + + public function providesPrincipalForGetGroupMembership() { + return [ + ['principals/system/a'], + ]; + } + + /** + * @throws \Sabre\DAV\Exception + */ + public function testGetGroupMembership() { + $backend = new SystemPrincipalBackend(); + $result = $backend->getGroupMembership('principals/system/system'); + $this->assertEquals([], $result); + } + + +} diff --git a/apps/dav/tests/unit/phpunit.xml b/apps/dav/tests/unit/phpunit.xml index 46c3cdfb345..314855d863b 100644 --- a/apps/dav/tests/unit/phpunit.xml +++ b/apps/dav/tests/unit/phpunit.xml @@ -6,7 +6,7 @@ timeoutForLargeTests="900" > <testsuite name='unit'> - <directory suffix='test.php'>.</directory> + <directory suffix='.php'>.</directory> </testsuite> <!-- filters for code coverage --> <filter> |