createMock(Auth::class);
$authBackend->method('isDavAuthenticated')->willReturn(true);
$request = $this->createMock(IRequest::class);
$config = $this->createMock(IConfig::class);
$this->rateLimiting = $this->createMock(RateLimiting::class);
$this->plugin = new Plugin($authBackend, $request, $config, $this->rateLimiting);
$root = new SimpleCollection('root');
$this->server = new Server($root);
$this->book = $this->createMock(IShareable::class);
$this->book->method('getName')->willReturn('addressbook1.vcf');
$root->addChild($this->book);
$this->plugin->initialize($this->server);
}
public function testSharing(): void {
$this->rateLimiting->expects(self::once())
->method('check');
$this->book->expects(self::once())
->method('updateShares')
->with([[
'href' => 'principal:principals/admin',
'commonName' => null,
'summary' => null,
'readOnly' => false,
]], ['mailto:wilfredo@example.com']);
$body = 'principal:principals/admin mailto:wilfredo@example.com';
$this->executeRequest($body);
}
public function testEmptyShareRequestIsRejected(): void {
$this->rateLimiting->expects(self::once())
->method('check');
$this->book->expects(self::never())
->method('updateShares');
$this->expectException(BadRequest::class);
$this->expectExceptionMessage('{http://owncloud.org/ns}share needs at least one set or remove element');
$body = '';
$this->executeRequest($body);
}
public function testShareRequestWithTooManyElementsIsRejected(): void {
$this->rateLimiting->expects(self::once())
->method('check');
$this->book->expects(self::never())
->method('updateShares');
$this->expectException(BadRequest::class);
$this->expectExceptionMessage('{http://owncloud.org/ns}share is limited to 10 set or remove elements');
$body = ''
. 'principal:principals/user1'
. 'principal:principals/user2'
. 'principal:principals/user3'
. 'principal:principals/user4'
. 'principal:principals/user5'
. 'principal:principals/user6'
. 'principal:principals/user7'
. 'principal:principals/user8'
. 'principal:principals/user9'
. 'principal:principals/user10'
. 'principal:principals/user11'
. 'principal:principals/user12'
. '';
$this->executeRequest($body);
}
private function executeRequest(string $body): void {
$request = new Request('POST', 'addressbook1.vcf');
$request->addHeader('Content-Type', 'application/xml');
$request->setBody($body);
$response = new Response();
$this->plugin->httpPost($request, $response);
}
}