use OC\User\User;
use OCA\DAV\CalDAV\Proxy\Proxy;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
+use OCA\DAV\Connector\Sabre\Principal;
use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\IGroup;
use OCP\L10N\IFactory;
use OCP\Share\IManager;
use PHPUnit\Framework\MockObject\MockObject;
+use Sabre\DAV\Exception;
use Sabre\DAV\PropPatch;
use Test\TestCase;
class PrincipalTest extends TestCase {
- /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserManager | MockObject */
private $userManager;
- /** @var \OCA\DAV\Connector\Sabre\Principal */
+ /** @var Principal */
private $connector;
- /** @var IGroupManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IGroupManager | MockObject */
private $groupManager;
- /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IManager | MockObject */
private $shareManager;
- /** @var IUserSession | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserSession | MockObject */
private $userSession;
- /** @var IAppManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IAppManager | MockObject */
private $appManager;
- /** @var ProxyMapper | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var ProxyMapper | MockObject */
private $proxyMapper;
/** @var KnownUserService|MockObject */
private $knownUserService;
- /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig | MockObject */
private $config;
/** @var IFactory|MockObject */
private $languageFactory;
$this->config = $this->createMock(IConfig::class);
$this->languageFactory = $this->createMock(IFactory::class);
- $this->connector = new \OCA\DAV\Connector\Sabre\Principal(
+ $this->connector = new Principal(
$this->userManager,
$this->groupManager,
$this->shareManager,
parent::setUp();
}
- public function testGetPrincipalsByPrefixWithoutPrefix() {
+ public function testGetPrincipalsByPrefixWithoutPrefix(): void {
$response = $this->connector->getPrincipalsByPrefix('');
$this->assertSame([], $response);
}
- public function testGetPrincipalsByPrefixWithUsers() {
+ public function testGetPrincipalsByPrefixWithUsers(): void {
$fooUser = $this->createMock(User::class);
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getUID')
->willReturn('foo');
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getDisplayName')
->willReturn('Dr. Foo-Bar');
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getEMailAddress')
->willReturn('');
$barUser = $this->createMock(User::class);
$barUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getUID')
->willReturn('bar');
$barUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getEMailAddress')
->willReturn('bar@nextcloud.com');
$this->userManager
$this->assertSame($expectedResponse, $response);
}
- public function testGetPrincipalsByPrefixEmpty() {
+ public function testGetPrincipalsByPrefixEmpty(): void {
$this->userManager
->expects($this->once())
->method('search')
$this->assertSame([], $response);
}
- public function testGetPrincipalsByPathWithoutMail() {
+ public function testGetPrincipalsByPathWithoutMail(): void {
$fooUser = $this->createMock(User::class);
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getUID')
->willReturn('foo');
$this->userManager
$this->assertSame($expectedResponse, $response);
}
- public function testGetPrincipalsByPathWithMail() {
+ public function testGetPrincipalsByPathWithMail(): void {
$fooUser = $this->createMock(User::class);
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getEMailAddress')
->willReturn('foo@nextcloud.com');
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getUID')
->willReturn('foo');
$this->userManager
$this->assertSame($expectedResponse, $response);
}
- public function testGetPrincipalsByPathEmpty() {
+ public function testGetPrincipalsByPathEmpty(): void {
$this->userManager
->expects($this->once())
->method('get')
->willReturn(null);
$response = $this->connector->getPrincipalByPath('principals/users/foo');
- $this->assertSame(null, $response);
+ $this->assertNull($response);
}
- public function testGetGroupMemberSet() {
+ public function testGetGroupMemberSet(): void {
$response = $this->connector->getGroupMemberSet('principals/users/foo');
$this->assertSame([], $response);
}
- public function testGetGroupMemberSetEmpty() {
- $this->expectException(\Sabre\DAV\Exception::class);
+ public function testGetGroupMemberSetEmpty(): void {
+ $this->expectException(Exception::class);
$this->expectExceptionMessage('Principal not found');
$this->userManager
$this->connector->getGroupMemberSet('principals/users/foo/calendar-proxy-read');
}
- public function testGetGroupMemberSetProxyRead() {
+ public function testGetGroupMemberSetProxyRead(): void {
$fooUser = $this->createMock(User::class);
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getUID')
->willReturn('foo');
$this->userManager
$this->assertEquals(['proxyId1'], $this->connector->getGroupMemberSet('principals/users/foo/calendar-proxy-read'));
}
- public function testGetGroupMemberSetProxyWrite() {
+ public function testGetGroupMemberSetProxyWrite(): void {
$fooUser = $this->createMock(User::class);
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getUID')
->willReturn('foo');
$this->userManager
$this->assertEquals(['proxyId2', 'proxyId3'], $this->connector->getGroupMemberSet('principals/users/foo/calendar-proxy-write'));
}
- public function testGetGroupMembership() {
+ public function testGetGroupMembership(): void {
$fooUser = $this->createMock(User::class);
$group1 = $this->createMock(IGroup::class);
$group1->expects($this->once())
}
- public function testGetGroupMembershipEmpty() {
- $this->expectException(\Sabre\DAV\Exception::class);
+ public function testGetGroupMembershipEmpty(): void {
+ $this->expectException(Exception::class);
$this->expectExceptionMessage('Principal not found');
$this->userManager
}
- public function testSetGroupMembership() {
- $this->expectException(\Sabre\DAV\Exception::class);
+ public function testSetGroupMembership(): void {
+ $this->expectException(Exception::class);
$this->expectExceptionMessage('Setting members of the group is not supported yet');
$this->connector->setGroupMemberSet('principals/users/foo', ['foo']);
}
- public function testSetGroupMembershipProxy() {
+ public function testSetGroupMembershipProxy(): void {
$fooUser = $this->createMock(User::class);
$fooUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getUID')
->willReturn('foo');
$barUser = $this->createMock(User::class);
$barUser
- ->expects($this->exactly(1))
+ ->expects($this->once())
->method('getUID')
->willReturn('bar');
$this->userManager
$this->connector->setGroupMemberSet('principals/users/foo/calendar-proxy-write', ['principals/users/bar']);
}
- public function testUpdatePrincipal() {
+ public function testUpdatePrincipal(): void {
$this->assertSame(0, $this->connector->updatePrincipal('foo', new PropPatch([])));
}
- public function testSearchPrincipalsWithEmptySearchProperties() {
+ public function testSearchPrincipalsWithEmptySearchProperties(): void {
$this->assertSame([], $this->connector->searchPrincipals('principals/users', []));
}
- public function testSearchPrincipalsWithWrongPrefixPath() {
+ public function testSearchPrincipalsWithWrongPrefixPath(): void {
$this->assertSame([], $this->connector->searchPrincipals('principals/groups',
['{http://sabredav.org/ns}email-address' => 'foo']));
}
/**
* @dataProvider searchPrincipalsDataProvider
*/
- public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $result) {
+ public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $result): void {
$this->shareManager->expects($this->once())
->method('shareAPIEnabled')
->willReturn($sharingEnabled);
'{DAV:}displayname' => 'User 12'], $test));
}
- public function searchPrincipalsDataProvider() {
+ public function searchPrincipalsDataProvider(): array {
return [
[true, false, 'allof', ['principals/users/user3']],
[true, false, 'anyof', ['principals/users/user2', 'principals/users/user3', 'principals/users/user4']],
];
}
- public function testSearchPrincipalByCalendarUserAddressSet() {
+ public function testSearchPrincipalByCalendarUserAddressSet(): void {
$this->shareManager->expects($this->exactly(2))
->method('shareAPIEnabled')
->willReturn(true);
['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => 'user@example.com']));
}
- public function testSearchPrincipalWithEnumerationDisabledDisplayname() {
+ public function testSearchPrincipalWithEnumerationDisabledDisplayname(): void {
$this->shareManager->expects($this->once())
->method('shareAPIEnabled')
->willReturn(true);
['{DAV:}displayname' => 'User 2']));
}
- public function testSearchPrincipalWithEnumerationDisabledDisplaynameOnFullMatch() {
+ public function testSearchPrincipalWithEnumerationDisabledDisplaynameOnFullMatch(): void {
$this->shareManager->expects($this->once())
->method('shareAPIEnabled')
->willReturn(true);
['{DAV:}displayname' => 'User 2']));
}
- public function testSearchPrincipalWithEnumerationDisabledEmail() {
+ public function testSearchPrincipalWithEnumerationDisabledEmail(): void {
$this->shareManager->expects($this->once())
->method('shareAPIEnabled')
->willReturn(true);
['{http://sabredav.org/ns}email-address' => 'user2@foo.bar']));
}
- public function testSearchPrincipalWithEnumerationDisabledEmailOnFullMatch() {
+ public function testSearchPrincipalWithEnumerationDisabledEmailOnFullMatch(): void {
$this->shareManager->expects($this->once())
->method('shareAPIEnabled')
->willReturn(true);
['{http://sabredav.org/ns}email-address' => 'user2@foo.bar']));
}
- public function testSearchPrincipalWithEnumerationLimitedDisplayname() {
+ public function testSearchPrincipalWithEnumerationLimitedDisplayname(): void {
$this->shareManager->expects($this->at(0))
->method('shareAPIEnabled')
->willReturn(true);
['{DAV:}displayname' => 'User']));
}
- public function testSearchPrincipalWithEnumerationLimitedMail() {
+ public function testSearchPrincipalWithEnumerationLimitedMail(): void {
$this->shareManager->expects($this->at(0))
->method('shareAPIEnabled')
->willReturn(true);
['{http://sabredav.org/ns}email-address' => 'user']));
}
- public function testFindByUriSharingApiDisabled() {
+ public function testFindByUriSharingApiDisabled(): void {
$this->shareManager->expects($this->once())
->method('shareApiEnabled')
->willReturn(false);
/**
* @dataProvider findByUriWithGroupRestrictionDataProvider
*/
- public function testFindByUriWithGroupRestriction($uri, $email, $expects) {
+ public function testFindByUriWithGroupRestriction($uri, $email, $expects): void {
$this->shareManager->expects($this->once())
->method('shareApiEnabled')
->willReturn(true);
$this->assertEquals($expects, $this->connector->findByUri($uri, 'principals/users'));
}
- public function findByUriWithGroupRestrictionDataProvider() {
+ public function findByUriWithGroupRestrictionDataProvider(): array {
return [
['mailto:user2@foo.bar', 'user2@foo.bar', 'principals/users/user2'],
['mailto:user3@foo.bar', 'user3@foo.bar', null],
/**
* @dataProvider findByUriWithoutGroupRestrictionDataProvider
*/
- public function testFindByUriWithoutGroupRestriction($uri, $email, $expects) {
+ public function testFindByUriWithoutGroupRestriction($uri, $email, $expects): void {
$this->shareManager->expects($this->once())
->method('shareApiEnabled')
->willReturn(true);
$this->assertEquals($expects, $this->connector->findByUri($uri, 'principals/users'));
}
- public function findByUriWithoutGroupRestrictionDataProvider() {
+ public function findByUriWithoutGroupRestrictionDataProvider(): array {
return [
['mailto:user2@foo.bar', 'user2@foo.bar', 'principals/users/user2'],
['mailto:user3@foo.bar', 'user3@foo.bar', 'principals/users/user3'],