mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
test: Migrate CardDAV tests to PHPUnit10
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
21f36fc332
commit
6cccdf98f4
23 changed files with 487 additions and 691 deletions
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -20,20 +22,11 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class BackendTest extends TestCase {
|
||||
/** @var IManager|MockObject */
|
||||
protected $activityManager;
|
||||
|
||||
/** @var IGroupManager|MockObject */
|
||||
protected $groupManager;
|
||||
|
||||
/** @var IUserSession|MockObject */
|
||||
protected $userSession;
|
||||
|
||||
/** @var IAppManager|MockObject */
|
||||
protected $appManager;
|
||||
|
||||
/** @var IUserManager|MockObject */
|
||||
protected $userManager;
|
||||
protected IManager&MockObject $activityManager;
|
||||
protected IGroupManager&MockObject $groupManager;
|
||||
protected IUserSession&MockObject $userSession;
|
||||
protected IAppManager&MockObject $appManager;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -45,10 +38,9 @@ class BackendTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $methods
|
||||
* @return Backend|MockObject
|
||||
*/
|
||||
protected function getBackend(array $methods = []) {
|
||||
protected function getBackend(array $methods = []): Backend {
|
||||
if (empty($methods)) {
|
||||
return new Backend(
|
||||
$this->activityManager,
|
||||
|
|
@ -71,7 +63,7 @@ class BackendTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function dataCallTriggerAddressBookActivity(): array {
|
||||
public static function dataCallTriggerAddressBookActivity(): array {
|
||||
return [
|
||||
['onAddressbookCreate', [['data']], Addressbook::SUBJECT_ADD, [['data'], [], []]],
|
||||
['onAddressbookUpdate', [['data'], ['shares'], ['changed-properties']], Addressbook::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
|
||||
|
|
@ -95,7 +87,7 @@ class BackendTest extends TestCase {
|
|||
call_user_func_array([$backend, $method], $payload);
|
||||
}
|
||||
|
||||
public function dataTriggerAddressBookActivity(): array {
|
||||
public static function dataTriggerAddressBookActivity(): array {
|
||||
return [
|
||||
// Add addressbook
|
||||
[Addressbook::SUBJECT_ADD, [], [], [], '', '', null, []],
|
||||
|
|
@ -160,12 +152,6 @@ class BackendTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataTriggerAddressBookActivity
|
||||
* @param string $action
|
||||
* @param array $data
|
||||
* @param array $shares
|
||||
* @param array $changedProperties
|
||||
* @param string $currentUser
|
||||
* @param string $author
|
||||
* @param string[]|null $shareUsers
|
||||
* @param string[] $users
|
||||
*/
|
||||
|
|
@ -219,13 +205,13 @@ class BackendTest extends TestCase {
|
|||
->method('userExists')
|
||||
->willReturn(true);
|
||||
|
||||
$event->expects($this->exactly(sizeof($users)))
|
||||
$event->expects($this->exactly(count($users)))
|
||||
->method('setAffectedUser')
|
||||
->willReturnSelf();
|
||||
$event->expects($this->exactly(sizeof($users)))
|
||||
$event->expects($this->exactly(count($users)))
|
||||
->method('setSubject')
|
||||
->willReturnSelf();
|
||||
$this->activityManager->expects($this->exactly(sizeof($users)))
|
||||
$this->activityManager->expects($this->exactly(count($users)))
|
||||
->method('publish')
|
||||
->with($event);
|
||||
} else {
|
||||
|
|
@ -261,7 +247,7 @@ class BackendTest extends TestCase {
|
|||
], [], []]);
|
||||
}
|
||||
|
||||
public function dataTriggerCardActivity(): array {
|
||||
public static function dataTriggerCardActivity(): array {
|
||||
$cardData = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 3.4.8//EN\r\nUID:test-user\r\nFN:test-user\r\nN:test-user;;;;\r\nEND:VCARD\r\n\r\n";
|
||||
|
||||
return [
|
||||
|
|
@ -330,12 +316,6 @@ class BackendTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataTriggerCardActivity
|
||||
* @param string $action
|
||||
* @param array $addressBookData
|
||||
* @param array $shares
|
||||
* @param array $cardData
|
||||
* @param string $currentUser
|
||||
* @param string $author
|
||||
* @param string[]|null $shareUsers
|
||||
* @param string[] $users
|
||||
*/
|
||||
|
|
@ -385,13 +365,13 @@ class BackendTest extends TestCase {
|
|||
->with($author)
|
||||
->willReturnSelf();
|
||||
|
||||
$event->expects($this->exactly(sizeof($users)))
|
||||
$event->expects($this->exactly(count($users)))
|
||||
->method('setAffectedUser')
|
||||
->willReturnSelf();
|
||||
$event->expects($this->exactly(sizeof($users)))
|
||||
$event->expects($this->exactly(count($users)))
|
||||
->method('setSubject')
|
||||
->willReturnSelf();
|
||||
$this->activityManager->expects($this->exactly(sizeof($users)))
|
||||
$this->activityManager->expects($this->exactly(count($users)))
|
||||
->method('publish')
|
||||
->with($event);
|
||||
} else {
|
||||
|
|
@ -409,7 +389,7 @@ class BackendTest extends TestCase {
|
|||
$this->assertEmpty($this->invokePrivate($backend, 'triggerCardActivity', [Card::SUBJECT_UPDATE, ['principaluri' => 'principals/system/system'], [], []]));
|
||||
}
|
||||
|
||||
public function dataGetUsersForShares(): array {
|
||||
public static function dataGetUsersForShares(): array {
|
||||
return [
|
||||
[
|
||||
[],
|
||||
|
|
@ -454,9 +434,6 @@ class BackendTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataGetUsersForShares
|
||||
* @param array $shares
|
||||
* @param array $groups
|
||||
* @param array $expected
|
||||
*/
|
||||
public function testGetUsersForShares(array $shares, array $groups, array $expected): void {
|
||||
$backend = $this->getBackend();
|
||||
|
|
@ -498,10 +475,9 @@ class BackendTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $uid
|
||||
* @return IUser|MockObject
|
||||
*/
|
||||
protected function getUserMock(string $uid) {
|
||||
protected function getUserMock(string $uid): IUser {
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())
|
||||
->method('getUID')
|
||||
|
|
|
|||
|
|
@ -12,32 +12,20 @@ use OCA\DAV\CardDAV\AddressBookImpl;
|
|||
use OCA\DAV\CardDAV\CardDavBackend;
|
||||
use OCA\DAV\Db\PropertyMapper;
|
||||
use OCP\IURLGenerator;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Sabre\VObject\Component\VCard;
|
||||
use Sabre\VObject\Property\Text;
|
||||
//use Sabre\VObject\Property\;
|
||||
use Test\TestCase;
|
||||
|
||||
class AddressBookImplTest extends TestCase {
|
||||
/** @var AddressBookImpl */
|
||||
private $addressBookImpl;
|
||||
|
||||
/** @var array */
|
||||
private $addressBookInfo;
|
||||
|
||||
/** @var AddressBook | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $addressBook;
|
||||
|
||||
/** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $backend;
|
||||
|
||||
/** @var PropertyMapper | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $propertyMapper;
|
||||
|
||||
/** @var VCard | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $vCard;
|
||||
private array $addressBookInfo;
|
||||
private AddressBook&MockObject $addressBook;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private CardDavBackend&MockObject $backend;
|
||||
private PropertyMapper&MockObject $propertyMapper;
|
||||
private VCard&MockObject $vCard;
|
||||
private AddressBookImpl $addressBookImpl;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -48,10 +36,8 @@ class AddressBookImplTest extends TestCase {
|
|||
'principaluri' => 'principals/system/system',
|
||||
'{DAV:}displayname' => 'display name',
|
||||
];
|
||||
$this->addressBook = $this->getMockBuilder(AddressBook::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->addressBook = $this->createMock(AddressBook::class);
|
||||
$this->backend = $this->createMock(CardDavBackend::class);
|
||||
$this->vCard = $this->createMock(VCard::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->propertyMapper = $this->createMock(PropertyMapper::class);
|
||||
|
|
@ -77,7 +63,7 @@ class AddressBookImplTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testSearch(): void {
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | AddressBookImpl $addressBookImpl */
|
||||
/** @var MockObject&AddressBookImpl $addressBookImpl */
|
||||
$addressBookImpl = $this->getMockBuilder(AddressBookImpl::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -89,7 +75,7 @@ class AddressBookImplTest extends TestCase {
|
|||
null
|
||||
]
|
||||
)
|
||||
->setMethods(['vCard2Array', 'readCard'])
|
||||
->onlyMethods(['vCard2Array', 'readCard'])
|
||||
->getMock();
|
||||
|
||||
$pattern = 'pattern';
|
||||
|
|
@ -107,10 +93,10 @@ class AddressBookImplTest extends TestCase {
|
|||
$addressBookImpl->expects($this->exactly(2))->method('readCard')
|
||||
->willReturn($this->vCard);
|
||||
$addressBookImpl->expects($this->exactly(2))->method('vCard2Array')
|
||||
->withConsecutive(
|
||||
['foo.vcf', $this->vCard],
|
||||
['bar.vcf', $this->vCard]
|
||||
)->willReturn('vCard');
|
||||
->willReturnMap([
|
||||
['foo.vcf', $this->vCard, 'vCard'],
|
||||
['bar.vcf', $this->vCard, 'vCard'],
|
||||
]);
|
||||
|
||||
$result = $addressBookImpl->search($pattern, $searchProperties, []);
|
||||
$this->assertTrue((is_array($result)));
|
||||
|
|
@ -119,13 +105,11 @@ class AddressBookImplTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataTestCreate
|
||||
*
|
||||
* @param array $properties
|
||||
*/
|
||||
public function testCreate($properties): void {
|
||||
public function testCreate(array $properties): void {
|
||||
$uid = 'uid';
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | AddressBookImpl $addressBookImpl */
|
||||
/** @var MockObject&AddressBookImpl $addressBookImpl */
|
||||
$addressBookImpl = $this->getMockBuilder(AddressBookImpl::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -137,7 +121,7 @@ class AddressBookImplTest extends TestCase {
|
|||
null
|
||||
]
|
||||
)
|
||||
->setMethods(['vCard2Array', 'createUid', 'createEmptyVCard'])
|
||||
->onlyMethods(['vCard2Array', 'createUid', 'createEmptyVCard'])
|
||||
->getMock();
|
||||
|
||||
$expectedProperties = 0;
|
||||
|
|
@ -164,7 +148,7 @@ class AddressBookImplTest extends TestCase {
|
|||
$this->assertTrue($addressBookImpl->createOrUpdate($properties));
|
||||
}
|
||||
|
||||
public function dataTestCreate() {
|
||||
public static function dataTestCreate(): array {
|
||||
return [
|
||||
[[]],
|
||||
[['FN' => 'John Doe']],
|
||||
|
|
@ -177,7 +161,7 @@ class AddressBookImplTest extends TestCase {
|
|||
$uri = 'bla.vcf';
|
||||
$properties = ['URI' => $uri, 'UID' => $uid, 'FN' => 'John Doe'];
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | AddressBookImpl $addressBookImpl */
|
||||
/** @var MockObject&AddressBookImpl $addressBookImpl */
|
||||
$addressBookImpl = $this->getMockBuilder(AddressBookImpl::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -189,7 +173,7 @@ class AddressBookImplTest extends TestCase {
|
|||
null
|
||||
]
|
||||
)
|
||||
->setMethods(['vCard2Array', 'createUid', 'createEmptyVCard', 'readCard'])
|
||||
->onlyMethods(['vCard2Array', 'createUid', 'createEmptyVCard', 'readCard'])
|
||||
->getMock();
|
||||
|
||||
$addressBookImpl->expects($this->never())->method('createUid');
|
||||
|
|
@ -216,7 +200,7 @@ class AddressBookImplTest extends TestCase {
|
|||
$vCard = new vCard;
|
||||
$textProperty = $vCard->createProperty('KEY', 'value');
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | AddressBookImpl $addressBookImpl */
|
||||
/** @var MockObject&AddressBookImpl $addressBookImpl */
|
||||
$addressBookImpl = $this->getMockBuilder(AddressBookImpl::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -228,7 +212,7 @@ class AddressBookImplTest extends TestCase {
|
|||
null
|
||||
]
|
||||
)
|
||||
->setMethods(['vCard2Array', 'createUid', 'createEmptyVCard', 'readCard'])
|
||||
->onlyMethods(['vCard2Array', 'createUid', 'createEmptyVCard', 'readCard'])
|
||||
->getMock();
|
||||
|
||||
$this->backend->expects($this->once())->method('getCard')
|
||||
|
|
@ -248,11 +232,8 @@ class AddressBookImplTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataTestGetPermissions
|
||||
*
|
||||
* @param array $permissions
|
||||
* @param int $expected
|
||||
*/
|
||||
public function testGetPermissions($permissions, $expected): void {
|
||||
public function testGetPermissions(array $permissions, int $expected): void {
|
||||
$this->addressBook->expects($this->once())->method('getACL')
|
||||
->willReturn($permissions);
|
||||
|
||||
|
|
@ -261,7 +242,7 @@ class AddressBookImplTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestGetPermissions() {
|
||||
public static function dataTestGetPermissions(): array {
|
||||
return [
|
||||
[[], 0],
|
||||
[[['privilege' => '{DAV:}read']], 1],
|
||||
|
|
@ -299,7 +280,7 @@ class AddressBookImplTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testCreateUid(): void {
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | AddressBookImpl $addressBookImpl */
|
||||
/** @var MockObject&AddressBookImpl $addressBookImpl */
|
||||
$addressBookImpl = $this->getMockBuilder(AddressBookImpl::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -311,7 +292,7 @@ class AddressBookImplTest extends TestCase {
|
|||
null
|
||||
]
|
||||
)
|
||||
->setMethods(['getUid'])
|
||||
->onlyMethods(['getUid'])
|
||||
->getMock();
|
||||
|
||||
$addressBookImpl->expects($this->exactly(2))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -28,19 +29,20 @@ class AddressBookTest extends TestCase {
|
|||
'uri' => 'default',
|
||||
];
|
||||
$l10n = $this->createMock(IL10N::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n, $logger);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
|
||||
|
||||
$card = new Card($backend, $addressBookInfo, ['id' => 5, 'carddata' => 'RANDOM VCF DATA', 'uri' => 'something', 'addressbookid' => 23]);
|
||||
|
||||
$backend->expects($this->once())->method('moveCard')->with(23, 666, 'something', 'user1')->willReturn(true);
|
||||
$backend->expects($this->once())->method('moveCard')
|
||||
->with(23, 666, 'something', 'user1')
|
||||
->willReturn(true);
|
||||
|
||||
$addressBook->moveInto('new', 'old', $card);
|
||||
}
|
||||
|
||||
public function testDelete(): void {
|
||||
/** @var MockObject | CardDavBackend $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
|
||||
$backend = $this->createMock(CardDavBackend::class);
|
||||
$backend->expects($this->once())->method('updateShares');
|
||||
$backend->expects($this->any())->method('getShares')->willReturn([
|
||||
['href' => 'principal:user2']
|
||||
|
|
@ -54,7 +56,7 @@ class AddressBookTest extends TestCase {
|
|||
];
|
||||
$l10n = $this->createMock(IL10N::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n, $logger);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
|
||||
$addressBook->delete();
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +65,7 @@ class AddressBookTest extends TestCase {
|
|||
$this->expectException(Forbidden::class);
|
||||
|
||||
/** @var MockObject | CardDavBackend $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
|
||||
$backend = $this->createMock(CardDavBackend::class);
|
||||
$backend->expects($this->never())->method('updateShares');
|
||||
$backend->expects($this->any())->method('getShares')->willReturn([
|
||||
['href' => 'principal:group2']
|
||||
|
|
@ -77,14 +79,14 @@ class AddressBookTest extends TestCase {
|
|||
];
|
||||
$l10n = $this->createMock(IL10N::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n, $logger);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
|
||||
$addressBook->delete();
|
||||
}
|
||||
|
||||
|
||||
public function testPropPatchShared(): void {
|
||||
/** @var MockObject | CardDavBackend $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
|
||||
$backend = $this->createMock(CardDavBackend::class);
|
||||
$backend->expects($this->never())->method('updateAddressBook');
|
||||
$addressBookInfo = [
|
||||
'{http://owncloud.org/ns}owner-principal' => 'user1',
|
||||
|
|
@ -95,13 +97,13 @@ class AddressBookTest extends TestCase {
|
|||
];
|
||||
$l10n = $this->createMock(IL10N::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n, $logger);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
|
||||
$addressBook->propPatch(new PropPatch(['{DAV:}displayname' => 'Test address book']));
|
||||
}
|
||||
|
||||
public function testPropPatchNotShared(): void {
|
||||
/** @var MockObject | CardDavBackend $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
|
||||
$backend = $this->createMock(CardDavBackend::class);
|
||||
$backend->expects($this->atLeast(1))->method('updateAddressBook');
|
||||
$addressBookInfo = [
|
||||
'{DAV:}displayname' => 'Test address book',
|
||||
|
|
@ -111,16 +113,16 @@ class AddressBookTest extends TestCase {
|
|||
];
|
||||
$l10n = $this->createMock(IL10N::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n, $logger);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
|
||||
$addressBook->propPatch(new PropPatch(['{DAV:}displayname' => 'Test address book']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providesReadOnlyInfo
|
||||
*/
|
||||
public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet): void {
|
||||
public function testAcl(bool $expectsWrite, ?bool $readOnlyValue, bool $hasOwnerSet): void {
|
||||
/** @var MockObject | CardDavBackend $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
|
||||
$backend = $this->createMock(CardDavBackend::class);
|
||||
$backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
|
||||
$addressBookInfo = [
|
||||
'{DAV:}displayname' => 'Test address book',
|
||||
|
|
@ -136,7 +138,7 @@ class AddressBookTest extends TestCase {
|
|||
}
|
||||
$l10n = $this->createMock(IL10N::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n, $logger);
|
||||
$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
|
||||
$acl = $addressBook->getACL();
|
||||
$childAcl = $addressBook->getChildACL();
|
||||
|
||||
|
|
@ -171,7 +173,7 @@ class AddressBookTest extends TestCase {
|
|||
$this->assertEquals($expectedAcl, $childAcl);
|
||||
}
|
||||
|
||||
public function providesReadOnlyInfo(): array {
|
||||
public static function providesReadOnlyInfo(): array {
|
||||
return [
|
||||
'read-only property not set' => [true, null, true],
|
||||
'read-only property is false' => [true, false, true],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -14,25 +15,19 @@ use OCA\DAV\DAV\GroupPrincipalBackend;
|
|||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Sabre\VObject\Component\VCalendar;
|
||||
use Sabre\VObject\Reader;
|
||||
use Test\TestCase;
|
||||
|
||||
class BirthdayServiceTest extends TestCase {
|
||||
/** @var BirthdayService */
|
||||
private $service;
|
||||
/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $calDav;
|
||||
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cardDav;
|
||||
/** @var GroupPrincipalBackend | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $groupPrincipalBackend;
|
||||
/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $config;
|
||||
/** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $dbConnection;
|
||||
/** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l10n;
|
||||
private CalDavBackend&MockObject $calDav;
|
||||
private CardDavBackend&MockObject $cardDav;
|
||||
private GroupPrincipalBackend&MockObject $groupPrincipalBackend;
|
||||
private IConfig&MockObject $config;
|
||||
private IDBConnection&MockObject $dbConnection;
|
||||
private IL10N&MockObject $l10n;
|
||||
private BirthdayService $service;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -57,16 +52,8 @@ class BirthdayServiceTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider providesVCards
|
||||
* @param string $expectedSummary
|
||||
* @param string $expectedDTStart
|
||||
* @param string $expectedRrule
|
||||
* @param string $expectedFieldType
|
||||
* @param string $expectedUnknownYear
|
||||
* @param string $expectedOriginalYear
|
||||
* @param string|null $expectedReminder
|
||||
* @param string | null $data
|
||||
*/
|
||||
public function testBuildBirthdayFromContact($expectedSummary, $expectedDTStart, $expectedRrule, $expectedFieldType, $expectedUnknownYear, $expectedOriginalYear, $expectedReminder, $data, $fieldType, $prefix, $supports4Bytes, $configuredReminder): void {
|
||||
public function testBuildBirthdayFromContact(?string $expectedSummary, ?string $expectedDTStart, ?string $expectedRrule, ?string $expectedFieldType, ?string $expectedUnknownYear, ?string $expectedOriginalYear, ?string $expectedReminder, ?string $data, string $fieldType, string $prefix, bool $supports4Bytes, ?string $configuredReminder): void {
|
||||
$this->dbConnection->method('supports4ByteText')->willReturn($supports4Bytes);
|
||||
$cal = $this->service->buildDateFromContact($data, $fieldType, $prefix, $configuredReminder);
|
||||
|
||||
|
|
@ -152,13 +139,17 @@ class BirthdayServiceTest extends TestCase {
|
|||
->willReturn([
|
||||
'id' => 1234
|
||||
]);
|
||||
$this->calDav->expects($this->exactly(3))
|
||||
$calls = [
|
||||
[1234, 'default-gump.vcf.ics'],
|
||||
[1234, 'default-gump.vcf-death.ics'],
|
||||
[1234, 'default-gump.vcf-anniversary.ics'],
|
||||
];
|
||||
$this->calDav->expects($this->exactly(count($calls)))
|
||||
->method('deleteCalendarObject')
|
||||
->withConsecutive(
|
||||
[1234, 'default-gump.vcf.ics'],
|
||||
[1234, 'default-gump.vcf-death.ics'],
|
||||
[1234, 'default-gump.vcf-anniversary.ics'],
|
||||
);
|
||||
->willReturnCallback(function ($calendarId, $objectUri) use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, [$calendarId, $objectUri]);
|
||||
});
|
||||
$this->cardDav->expects($this->once())->method('getShares')->willReturn([]);
|
||||
|
||||
$this->service->onCardDeleted(666, 'gump.vcf');
|
||||
|
|
@ -173,7 +164,7 @@ class BirthdayServiceTest extends TestCase {
|
|||
$this->cardDav->expects($this->never())->method('getAddressBookById');
|
||||
|
||||
$service = $this->getMockBuilder(BirthdayService::class)
|
||||
->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
|
||||
->onlyMethods(['buildDateFromContact', 'birthdayEvenChanged'])
|
||||
->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config, $this->dbConnection, $this->l10n])
|
||||
->getMock();
|
||||
|
||||
|
|
@ -200,9 +191,9 @@ class BirthdayServiceTest extends TestCase {
|
|||
$this->cardDav->expects($this->once())->method('getShares')->willReturn([]);
|
||||
$this->calDav->expects($this->never())->method('getCalendarByUri');
|
||||
|
||||
/** @var BirthdayService | \PHPUnit\Framework\MockObject\MockObject $service */
|
||||
/** @var BirthdayService&MockObject $service */
|
||||
$service = $this->getMockBuilder(BirthdayService::class)
|
||||
->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
|
||||
->onlyMethods(['buildDateFromContact', 'birthdayEvenChanged'])
|
||||
->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config, $this->dbConnection, $this->l10n])
|
||||
->getMock();
|
||||
|
||||
|
|
@ -212,7 +203,7 @@ class BirthdayServiceTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider providesCardChanges
|
||||
*/
|
||||
public function testOnCardChanged($expectedOp): void {
|
||||
public function testOnCardChanged(string $expectedOp): void {
|
||||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('dav', 'generateBirthdayCalendar', 'yes')
|
||||
|
|
@ -220,11 +211,10 @@ class BirthdayServiceTest extends TestCase {
|
|||
|
||||
$this->config->expects($this->exactly(2))
|
||||
->method('getUserValue')
|
||||
->withConsecutive(
|
||||
['user01', 'dav', 'generateBirthdayCalendar', 'yes'],
|
||||
['user01', 'dav', 'birthdayCalendarReminderOffset', 'PT9H'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls('yes', 'PT9H');
|
||||
->willReturnMap([
|
||||
['user01', 'dav', 'generateBirthdayCalendar', 'yes', 'yes'],
|
||||
['user01', 'dav', 'birthdayCalendarReminderOffset', 'PT9H', 'PT9H'],
|
||||
]);
|
||||
|
||||
$this->cardDav->expects($this->once())->method('getAddressBookById')
|
||||
->with(666)
|
||||
|
|
@ -239,31 +229,45 @@ class BirthdayServiceTest extends TestCase {
|
|||
]);
|
||||
$this->cardDav->expects($this->once())->method('getShares')->willReturn([]);
|
||||
|
||||
/** @var BirthdayService | \PHPUnit\Framework\MockObject\MockObject $service */
|
||||
/** @var BirthdayService&MockObject $service */
|
||||
$service = $this->getMockBuilder(BirthdayService::class)
|
||||
->setMethods(['buildDateFromContact', 'birthdayEvenChanged'])
|
||||
->onlyMethods(['buildDateFromContact', 'birthdayEvenChanged'])
|
||||
->setConstructorArgs([$this->calDav, $this->cardDav, $this->groupPrincipalBackend, $this->config, $this->dbConnection, $this->l10n])
|
||||
->getMock();
|
||||
|
||||
if ($expectedOp === 'delete') {
|
||||
$this->calDav->expects($this->exactly(3))->method('getCalendarObject')->willReturn('');
|
||||
$service->expects($this->exactly(3))->method('buildDateFromContact')->willReturn(null);
|
||||
$this->calDav->expects($this->exactly(3))->method('deleteCalendarObject')->withConsecutive(
|
||||
|
||||
$calls = [
|
||||
[1234, 'default-gump.vcf.ics'],
|
||||
[1234, 'default-gump.vcf-death.ics'],
|
||||
[1234, 'default-gump.vcf-anniversary.ics']
|
||||
);
|
||||
];
|
||||
$this->calDav->expects($this->exactly(count($calls)))
|
||||
->method('deleteCalendarObject')
|
||||
->willReturnCallback(function ($calendarId, $objectUri) use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, [$calendarId, $objectUri]);
|
||||
});
|
||||
}
|
||||
if ($expectedOp === 'create') {
|
||||
$vCal = new VCalendar();
|
||||
$vCal->PRODID = '-//Nextcloud testing//mocked object//';
|
||||
|
||||
$service->expects($this->exactly(3))->method('buildDateFromContact')->willReturn($vCal);
|
||||
$this->calDav->expects($this->exactly(3))->method('createCalendarObject')->withConsecutive(
|
||||
|
||||
$createCalendarObjectCalls = [
|
||||
[1234, 'default-gump.vcf.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nPRODID:-//Nextcloud testing//mocked object//\r\nEND:VCALENDAR\r\n"],
|
||||
[1234, 'default-gump.vcf-death.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nPRODID:-//Nextcloud testing//mocked object//\r\nEND:VCALENDAR\r\n"],
|
||||
[1234, 'default-gump.vcf-anniversary.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nPRODID:-//Nextcloud testing//mocked object//\r\nEND:VCALENDAR\r\n"]
|
||||
);
|
||||
];
|
||||
$this->calDav->expects($this->exactly(count($createCalendarObjectCalls)))
|
||||
->method('createCalendarObject')
|
||||
->willReturnCallback(function ($calendarId, $objectUri, $calendarData) use (&$createCalendarObjectCalls) {
|
||||
$expected = array_shift($createCalendarObjectCalls);
|
||||
$this->assertEquals($expected, [$calendarId, $objectUri, $calendarData]);
|
||||
});
|
||||
}
|
||||
if ($expectedOp === 'update') {
|
||||
$vCal = new VCalendar();
|
||||
|
|
@ -272,11 +276,18 @@ class BirthdayServiceTest extends TestCase {
|
|||
$service->expects($this->exactly(3))->method('buildDateFromContact')->willReturn($vCal);
|
||||
$service->expects($this->exactly(3))->method('birthdayEvenChanged')->willReturn(true);
|
||||
$this->calDav->expects($this->exactly(3))->method('getCalendarObject')->willReturn(['calendardata' => '']);
|
||||
$this->calDav->expects($this->exactly(3))->method('updateCalendarObject')->withConsecutive(
|
||||
|
||||
$updateCalendarObjectCalls = [
|
||||
[1234, 'default-gump.vcf.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nPRODID:-//Nextcloud testing//mocked object//\r\nEND:VCALENDAR\r\n"],
|
||||
[1234, 'default-gump.vcf-death.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nPRODID:-//Nextcloud testing//mocked object//\r\nEND:VCALENDAR\r\n"],
|
||||
[1234, 'default-gump.vcf-anniversary.ics', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nPRODID:-//Nextcloud testing//mocked object//\r\nEND:VCALENDAR\r\n"]
|
||||
);
|
||||
];
|
||||
$this->calDav->expects($this->exactly(count($updateCalendarObjectCalls)))
|
||||
->method('updateCalendarObject')
|
||||
->willReturnCallback(function ($calendarId, $objectUri, $calendarData) use (&$updateCalendarObjectCalls) {
|
||||
$expected = array_shift($updateCalendarObjectCalls);
|
||||
$this->assertEquals($expected, [$calendarId, $objectUri, $calendarData]);
|
||||
});
|
||||
}
|
||||
|
||||
$service->onCardChanged(666, 'gump.vcf', '');
|
||||
|
|
@ -284,11 +295,8 @@ class BirthdayServiceTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider providesBirthday
|
||||
* @param $expected
|
||||
* @param $old
|
||||
* @param $new
|
||||
*/
|
||||
public function testBirthdayEvenChanged($expected, $old, $new): void {
|
||||
public function testBirthdayEvenChanged(bool $expected, string $old, string $new): void {
|
||||
$new = Reader::read($new);
|
||||
$this->assertEquals($expected, $this->service->birthdayEvenChanged($old, $new));
|
||||
}
|
||||
|
|
@ -354,18 +362,22 @@ class BirthdayServiceTest extends TestCase {
|
|||
->with(42, 0)
|
||||
->willReturn([['uri' => '1.ics'], ['uri' => '2.ics'], ['uri' => '3.ics']]);
|
||||
|
||||
$this->calDav->expects($this->exactly(3))
|
||||
$calls = [
|
||||
[42, '1.ics', 0],
|
||||
[42, '2.ics', 0],
|
||||
[42, '3.ics', 0],
|
||||
];
|
||||
$this->calDav->expects($this->exactly(count($calls)))
|
||||
->method('deleteCalendarObject')
|
||||
->withConsecutive(
|
||||
[42, '1.ics', 0],
|
||||
[42, '2.ics', 0],
|
||||
[42, '3.ics', 0],
|
||||
);
|
||||
->willReturnCallback(function ($calendarId, $objectUri, $calendarType) use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, [$calendarId, $objectUri, $calendarType]);
|
||||
});
|
||||
|
||||
$this->service->resetForUser('user123');
|
||||
}
|
||||
|
||||
public function providesBirthday() {
|
||||
public static function providesBirthday(): array {
|
||||
return [
|
||||
[true,
|
||||
'',
|
||||
|
|
@ -382,7 +394,7 @@ class BirthdayServiceTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
public function providesCardChanges() {
|
||||
public static function providesCardChanges(): array {
|
||||
return[
|
||||
['delete'],
|
||||
['create'],
|
||||
|
|
@ -390,7 +402,7 @@ class BirthdayServiceTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
public function providesVCards() {
|
||||
public static function providesVCards(): array {
|
||||
return [
|
||||
// $expectedSummary, $expectedDTStart, $expectedRrule, $expectedFieldType, $expectedUnknownYear, $expectedOriginalYear, $expectedReminder, $data, $fieldType, $prefix, $supports4Byte, $configuredReminder
|
||||
[null, null, null, null, null, null, null, 'yasfewf', '', '', true, null],
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ use OCP\IUserSession;
|
|||
use OCP\L10N\IFactory;
|
||||
use OCP\Server;
|
||||
use OCP\Share\IManager as ShareManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Sabre\DAV\Exception\BadRequest;
|
||||
use Sabre\DAV\PropPatch;
|
||||
|
|
@ -45,29 +46,15 @@ use function time;
|
|||
* @package OCA\DAV\Tests\unit\CardDAV
|
||||
*/
|
||||
class CardDavBackendTest extends TestCase {
|
||||
/** @var CardDavBackend */
|
||||
private $backend;
|
||||
|
||||
/** @var Principal | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $principal;
|
||||
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userManager;
|
||||
|
||||
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $groupManager;
|
||||
|
||||
/** @var IEventDispatcher|MockObject */
|
||||
private $dispatcher;
|
||||
private Principal&MockObject $principal;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private IGroupManager&MockObject $groupManager;
|
||||
private IEventDispatcher&MockObject $dispatcher;
|
||||
private Backend $sharingBackend;
|
||||
/** @var IDBConnection */
|
||||
private $db;
|
||||
|
||||
/** @var string */
|
||||
private $dbCardsTable = 'cards';
|
||||
|
||||
/** @var string */
|
||||
private $dbCardsPropertiesTable = 'cards_properties';
|
||||
private IDBConnection $db;
|
||||
private CardDavBackend $backend;
|
||||
private string $dbCardsTable = 'cards';
|
||||
private string $dbCardsPropertiesTable = 'cards_properties';
|
||||
|
||||
public const UNIT_TEST_USER = 'principals/users/carddav-unit-test';
|
||||
public const UNIT_TEST_USER1 = 'principals/users/carddav-unit-test1';
|
||||
|
|
@ -122,7 +109,7 @@ class CardDavBackendTest extends TestCase {
|
|||
$this->createMock(IConfig::class),
|
||||
$this->createMock(IFactory::class)
|
||||
])
|
||||
->setMethods(['getPrincipalByPath', 'getGroupMembership', 'findByUri'])
|
||||
->onlyMethods(['getPrincipalByPath', 'getGroupMembership', 'findByUri'])
|
||||
->getMock();
|
||||
$this->principal->method('getPrincipalByPath')
|
||||
->willReturn([
|
||||
|
|
@ -151,16 +138,20 @@ class CardDavBackendTest extends TestCase {
|
|||
);
|
||||
// start every test with a empty cards_properties and cards table
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->delete('cards_properties')->execute();
|
||||
$query->delete('cards_properties')->executeStatement();
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->delete('cards')->execute();
|
||||
$query->delete('cards')->executeStatement();
|
||||
|
||||
$this->tearDown();
|
||||
$this->principal->method('getGroupMembership')
|
||||
->withAnyParameters()
|
||||
->willReturn([self::UNIT_TEST_GROUP]);
|
||||
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
||||
foreach ($books as $book) {
|
||||
$this->backend->deleteAddressBook($book['id']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
parent::tearDown();
|
||||
|
||||
if (is_null($this->backend)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -172,6 +163,8 @@ class CardDavBackendTest extends TestCase {
|
|||
foreach ($books as $book) {
|
||||
$this->backend->deleteAddressBook($book['id']);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testAddressBookOperations(): void {
|
||||
|
|
@ -236,10 +229,11 @@ class CardDavBackendTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testCardOperations(): void {
|
||||
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */
|
||||
/** @var CardDavBackend&MockObject $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher, $this->sharingBackend])
|
||||
->onlyMethods(['updateProperties', 'purgeProperties'])->getMock();
|
||||
->onlyMethods(['updateProperties', 'purgeProperties'])
|
||||
->getMock();
|
||||
|
||||
// create a new address book
|
||||
$backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
||||
|
|
@ -249,12 +243,16 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
$uri = $this->getUniqueID('card');
|
||||
// updateProperties is expected twice, once for createCard and once for updateCard
|
||||
$backend->expects($this->exactly(2))
|
||||
$calls = [
|
||||
[$bookId, $uri, $this->vcardTest0],
|
||||
[$bookId, $uri, $this->vcardTest1],
|
||||
];
|
||||
$backend->expects($this->exactly(count($calls)))
|
||||
->method('updateProperties')
|
||||
->withConsecutive(
|
||||
[$bookId, $uri, $this->vcardTest0],
|
||||
[$bookId, $uri, $this->vcardTest1],
|
||||
);
|
||||
->willReturnCallback(function () use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
});
|
||||
|
||||
// Expect event
|
||||
$this->dispatcher
|
||||
|
|
@ -294,7 +292,8 @@ class CardDavBackendTest extends TestCase {
|
|||
public function testMultiCard(): void {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher, $this->sharingBackend])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
->onlyMethods(['updateProperties'])
|
||||
->getMock();
|
||||
|
||||
// create a new address book
|
||||
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
||||
|
|
@ -347,7 +346,8 @@ class CardDavBackendTest extends TestCase {
|
|||
public function testMultipleUIDOnDifferentAddressbooks(): void {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher, $this->sharingBackend])
|
||||
->onlyMethods(['updateProperties'])->getMock();
|
||||
->onlyMethods(['updateProperties'])
|
||||
->getMock();
|
||||
|
||||
// create 2 new address books
|
||||
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
||||
|
|
@ -369,7 +369,8 @@ class CardDavBackendTest extends TestCase {
|
|||
public function testMultipleUIDDenied(): void {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher, $this->sharingBackend])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
->onlyMethods(['updateProperties'])
|
||||
->getMock();
|
||||
|
||||
// create a new address book
|
||||
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
||||
|
|
@ -390,7 +391,8 @@ class CardDavBackendTest extends TestCase {
|
|||
public function testNoValidUID(): void {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher, $this->sharingBackend])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
->onlyMethods(['updateProperties'])
|
||||
->getMock();
|
||||
|
||||
// create a new address book
|
||||
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
||||
|
|
@ -428,12 +430,17 @@ class CardDavBackendTest extends TestCase {
|
|||
->method('getCardId')
|
||||
->with($bookId, $uri)
|
||||
->willThrowException(new \InvalidArgumentException());
|
||||
$this->backend->expects($this->exactly(2))
|
||||
|
||||
$calls = [
|
||||
[$bookId, $uri, 1],
|
||||
[$bookId, $uri, 3],
|
||||
];
|
||||
$this->backend->expects($this->exactly(count($calls)))
|
||||
->method('addChange')
|
||||
->withConsecutive(
|
||||
[$bookId, $uri, 1],
|
||||
[$bookId, $uri, 3]
|
||||
);
|
||||
->willReturnCallback(function () use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
});
|
||||
$this->backend->expects($this->never())
|
||||
->method('purgeProperties');
|
||||
|
||||
|
|
@ -447,7 +454,8 @@ class CardDavBackendTest extends TestCase {
|
|||
public function testSyncSupport(): void {
|
||||
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
||||
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher, $this->sharingBackend])
|
||||
->setMethods(['updateProperties'])->getMock();
|
||||
->onlyMethods(['updateProperties'])
|
||||
->getMock();
|
||||
|
||||
// create a new address book
|
||||
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
||||
|
|
@ -639,13 +647,8 @@ class CardDavBackendTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataTestSearch
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param array $properties
|
||||
* @param array $options
|
||||
* @param array $expected
|
||||
*/
|
||||
public function testSearch($pattern, $properties, $options, $expected): void {
|
||||
public function testSearch(string $pattern, array $properties, array $options, array $expected): void {
|
||||
/** @var VCard $vCards */
|
||||
$vCards = [];
|
||||
$vCards[0] = new VCard();
|
||||
|
|
@ -756,7 +759,7 @@ class CardDavBackendTest extends TestCase {
|
|||
$this->assertSame(count($expected), count($found));
|
||||
}
|
||||
|
||||
public function dataTestSearch() {
|
||||
public static function dataTestSearch(): array {
|
||||
return [
|
||||
['John', ['FN'], [], [['uri0', 'John Doe'], ['uri1', 'John M. Doe']]],
|
||||
['M. Doe', ['FN'], [], [['uri1', 'John M. Doe']]],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -13,16 +14,17 @@ use OCA\DAV\Db\PropertyMapper;
|
|||
use OCP\Contacts\IManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ContactsManagerTest extends TestCase {
|
||||
public function test(): void {
|
||||
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject $cm */
|
||||
$cm = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock();
|
||||
/** @var IManager&MockObject $cm */
|
||||
$cm = $this->createMock(IManager::class);
|
||||
$cm->expects($this->exactly(2))->method('registerAddressBook');
|
||||
$urlGenerator = $this->getMockBuilder(IURLGenerator::class)->disableOriginalConstructor()->getMock();
|
||||
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backEnd */
|
||||
$backEnd = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
|
||||
$urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
/** @var CardDavBackend&MockObject $backEnd */
|
||||
$backEnd = $this->createMock(CardDavBackend::class);
|
||||
$backEnd->method('getAddressBooksForUser')->willReturn([
|
||||
['{DAV:}displayname' => 'Test address book', 'uri' => 'default'],
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -22,17 +22,10 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class ConverterTest extends TestCase {
|
||||
|
||||
/** @var IAccountManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $accountManager;
|
||||
/** @var IUserManager|(IUserManager&MockObject)|MockObject */
|
||||
private IUserManager|MockObject $userManager;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $logger;
|
||||
private IAccountManager&MockObject $accountManager;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -44,7 +37,7 @@ class ConverterTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return IAccountProperty|MockObject
|
||||
* @return IAccountProperty&MockObject
|
||||
*/
|
||||
protected function getAccountPropertyMock(string $name, ?string $value, string $scope) {
|
||||
$property = $this->createMock(IAccountProperty::class);
|
||||
|
|
@ -77,10 +70,11 @@ class ConverterTest extends TestCase {
|
|||
yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_TWITTER, '', IAccountManager::SCOPE_LOCAL);
|
||||
});
|
||||
|
||||
$accountManager = $this->getMockBuilder(IAccountManager::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$accountManager = $this->createMock(IAccountManager::class);
|
||||
|
||||
$accountManager->expects($this->any())->method('getAccount')->willReturn($account);
|
||||
$accountManager->expects($this->any())
|
||||
->method('getAccount')
|
||||
->willReturn($account);
|
||||
|
||||
return $accountManager;
|
||||
}
|
||||
|
|
@ -126,7 +120,7 @@ class ConverterTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
protected function compareData($expected, $data) {
|
||||
protected function compareData(array $expected, array $data): void {
|
||||
foreach ($expected as $key => $value) {
|
||||
$found = false;
|
||||
foreach ($data[1] as $d) {
|
||||
|
|
@ -141,7 +135,7 @@ class ConverterTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function providesNewUsers() {
|
||||
public static function providesNewUsers(): array {
|
||||
return [
|
||||
[
|
||||
null
|
||||
|
|
@ -197,17 +191,15 @@ class ConverterTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider providesNames
|
||||
* @param $expected
|
||||
* @param $fullName
|
||||
*/
|
||||
public function testNameSplitter($expected, $fullName): void {
|
||||
public function testNameSplitter(string $expected, string $fullName): void {
|
||||
$converter = new Converter($this->accountManager, $this->userManager, $this->urlGenerator, $this->logger);
|
||||
$r = $converter->splitFullName($fullName);
|
||||
$r = implode(';', $r);
|
||||
$this->assertEquals($expected, $r);
|
||||
}
|
||||
|
||||
public function providesNames() {
|
||||
public static function providesNames(): array {
|
||||
return [
|
||||
['Sauron;;;;', 'Sauron'],
|
||||
['Baggins;Bilbo;;;', 'Bilbo Baggins'],
|
||||
|
|
@ -216,16 +208,13 @@ class ConverterTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $displayName
|
||||
* @param $eMailAddress
|
||||
* @param $cloudId
|
||||
* @return IUser | \PHPUnit\Framework\MockObject\MockObject
|
||||
* @return IUser&MockObject
|
||||
*/
|
||||
protected function getUserMock(string $displayName, ?string $eMailAddress, ?string $cloudId) {
|
||||
$image0 = $this->getMockBuilder(IImage::class)->disableOriginalConstructor()->getMock();
|
||||
$image0 = $this->createMock(IImage::class);
|
||||
$image0->method('mimeType')->willReturn('image/jpeg');
|
||||
$image0->method('data')->willReturn('123456789');
|
||||
$user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->method('getUID')->willReturn('12345');
|
||||
$user->method('getDisplayName')->willReturn($displayName);
|
||||
$user->method('getEMailAddress')->willReturn($eMailAddress);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -13,6 +14,7 @@ use OCA\DAV\CardDAV\PhotoCache;
|
|||
use OCP\AppFramework\Http;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\SimpleFS\ISimpleFile;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Sabre\CardDAV\Card;
|
||||
use Sabre\DAV\Node;
|
||||
use Sabre\DAV\Server;
|
||||
|
|
@ -22,18 +24,12 @@ use Sabre\HTTP\ResponseInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class ImageExportPluginTest extends TestCase {
|
||||
/** @var ResponseInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $response;
|
||||
/** @var RequestInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $request;
|
||||
/** @var ImageExportPlugin|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $plugin;
|
||||
/** @var Server */
|
||||
private $server;
|
||||
/** @var Tree|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $tree;
|
||||
/** @var PhotoCache|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cache;
|
||||
private ResponseInterface&MockObject $response;
|
||||
private RequestInterface&MockObject $request;
|
||||
private Server&MockObject $server;
|
||||
private Tree&MockObject $tree;
|
||||
private PhotoCache&MockObject $cache;
|
||||
private ImageExportPlugin $plugin;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -45,24 +41,20 @@ class ImageExportPluginTest extends TestCase {
|
|||
$this->server->tree = $this->tree;
|
||||
$this->cache = $this->createMock(PhotoCache::class);
|
||||
|
||||
$this->plugin = $this->getMockBuilder(ImageExportPlugin::class)
|
||||
->setMethods(['getPhoto'])
|
||||
->setConstructorArgs([$this->cache])
|
||||
->getMock();
|
||||
$this->plugin = new ImageExportPlugin($this->cache);
|
||||
$this->plugin->initialize($this->server);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providesQueryParams
|
||||
* @param $param
|
||||
*/
|
||||
public function testQueryParams($param): void {
|
||||
public function testQueryParams(array $param): void {
|
||||
$this->request->expects($this->once())->method('getQueryParameters')->willReturn($param);
|
||||
$result = $this->plugin->httpGet($this->request, $this->response);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function providesQueryParams() {
|
||||
public static function providesQueryParams(): array {
|
||||
return [
|
||||
[[]],
|
||||
[['1']],
|
||||
|
|
@ -87,7 +79,7 @@ class ImageExportPluginTest extends TestCase {
|
|||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function dataTestCard() {
|
||||
public static function dataTestCard(): array {
|
||||
return [
|
||||
[null, false],
|
||||
[null, true],
|
||||
|
|
@ -98,11 +90,8 @@ class ImageExportPluginTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataTestCard
|
||||
*
|
||||
* @param $size
|
||||
* @param bool $photo
|
||||
*/
|
||||
public function testCard($size, $photo): void {
|
||||
public function testCard(?int $size, bool $photo): void {
|
||||
$query = ['photo' => null];
|
||||
if ($size !== null) {
|
||||
$query['size'] = $size;
|
||||
|
|
@ -145,14 +134,18 @@ class ImageExportPluginTest extends TestCase {
|
|||
->with(1, 'card', $size, $card)
|
||||
->willReturn($file);
|
||||
|
||||
$this->response->expects($this->exactly(4))
|
||||
$setHeaderCalls = [
|
||||
['Cache-Control', 'private, max-age=3600, must-revalidate'],
|
||||
['Etag', '"myEtag"'],
|
||||
['Content-Type', 'image/jpeg'],
|
||||
['Content-Disposition', 'attachment; filename=card.jpg'],
|
||||
];
|
||||
$this->response->expects($this->exactly(count($setHeaderCalls)))
|
||||
->method('setHeader')
|
||||
->withConsecutive(
|
||||
['Cache-Control', 'private, max-age=3600, must-revalidate'],
|
||||
['Etag', '"myEtag"'],
|
||||
['Content-Type', 'image/jpeg'],
|
||||
['Content-Disposition', 'attachment; filename=card.jpg'],
|
||||
);
|
||||
->willReturnCallback(function () use (&$setHeaderCalls) {
|
||||
$expected = array_shift($setHeaderCalls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
});
|
||||
|
||||
$this->response->expects($this->once())
|
||||
->method('setStatus')
|
||||
|
|
@ -161,12 +154,16 @@ class ImageExportPluginTest extends TestCase {
|
|||
->method('setBody')
|
||||
->with('imgdata');
|
||||
} else {
|
||||
$this->response->expects($this->exactly(2))
|
||||
$setHeaderCalls = [
|
||||
['Cache-Control', 'private, max-age=3600, must-revalidate'],
|
||||
['Etag', '"myEtag"'],
|
||||
];
|
||||
$this->response->expects($this->exactly(count($setHeaderCalls)))
|
||||
->method('setHeader')
|
||||
->withConsecutive(
|
||||
['Cache-Control', 'private, max-age=3600, must-revalidate'],
|
||||
['Etag', '"myEtag"'],
|
||||
);
|
||||
->willReturnCallback(function () use (&$setHeaderCalls) {
|
||||
$expected = array_shift($setHeaderCalls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
});
|
||||
$this->cache->method('get')
|
||||
->with(1, 'card', $size, $card)
|
||||
->willThrowException(new NotFoundException());
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ use Test\TestCase;
|
|||
|
||||
class CardDavRateLimitingPluginTest extends TestCase {
|
||||
|
||||
private Limiter|MockObject $limiter;
|
||||
private CardDavBackend|MockObject $cardDavBackend;
|
||||
private IUserManager|MockObject $userManager;
|
||||
private LoggerInterface|MockObject $logger;
|
||||
private IAppConfig|MockObject $config;
|
||||
private Limiter&MockObject $limiter;
|
||||
private CardDavBackend&MockObject $cardDavBackend;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private IAppConfig&MockObject $config;
|
||||
private string $userId = 'user123';
|
||||
private CardDavRateLimitingPlugin $plugin;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -12,6 +13,7 @@ use OCA\DAV\DAV\Sharing\IShareable;
|
|||
use OCA\DAV\DAV\Sharing\Plugin;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Sabre\DAV\Server;
|
||||
use Sabre\DAV\SimpleCollection;
|
||||
use Sabre\HTTP\Request;
|
||||
|
|
@ -19,31 +21,25 @@ use Sabre\HTTP\Response;
|
|||
use Test\TestCase;
|
||||
|
||||
class PluginTest extends TestCase {
|
||||
|
||||
/** @var Plugin */
|
||||
private $plugin;
|
||||
/** @var Server */
|
||||
private $server;
|
||||
/** @var IShareable | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $book;
|
||||
private Plugin $plugin;
|
||||
private Server $server;
|
||||
private IShareable&MockObject $book;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
/** @var Auth | \PHPUnit\Framework\MockObject\MockObject $authBackend */
|
||||
$authBackend = $this->getMockBuilder(Auth::class)->disableOriginalConstructor()->getMock();
|
||||
$authBackend->method('isDavAuthenticated')->willReturn(true);
|
||||
|
||||
/** @var IRequest $request */
|
||||
$request = $this->getMockBuilder(IRequest::class)->disableOriginalConstructor()->getMock();
|
||||
$authBackend = $this->createMock(Auth::class);
|
||||
$authBackend->method('isDavAuthenticated')
|
||||
->willReturn(true);
|
||||
$request = $this->createMock(IRequest::class);
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$this->plugin = new Plugin($authBackend, $request, $config);
|
||||
|
||||
$root = new SimpleCollection('root');
|
||||
$this->server = new \Sabre\DAV\Server($root);
|
||||
/** @var SimpleCollection $node */
|
||||
$this->book = $this->getMockBuilder(IShareable::class)->disableOriginalConstructor()->getMock();
|
||||
$this->book->method('getName')->willReturn('addressbook1.vcf');
|
||||
$this->book = $this->createMock(IShareable::class);
|
||||
$this->book->method('getName')
|
||||
->willReturn('addressbook1.vcf');
|
||||
$root->addChild($this->book);
|
||||
$this->plugin->initialize($this->server);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use OCP\IConfig;
|
|||
use OCP\IDBConnection;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
|
@ -28,15 +29,18 @@ use Test\TestCase;
|
|||
|
||||
class SyncServiceTest extends TestCase {
|
||||
|
||||
protected CardDavBackend $backend;
|
||||
protected IUserManager $userManager;
|
||||
protected IDBConnection $dbConnection;
|
||||
protected CardDavBackend&MockObject $backend;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected IDBConnection&MockObject $dbConnection;
|
||||
protected LoggerInterface $logger;
|
||||
protected Converter $converter;
|
||||
protected IClient $client;
|
||||
protected IConfig $config;
|
||||
protected Converter&MockObject $converter;
|
||||
protected IClient&MockObject $client;
|
||||
protected IConfig&MockObject $config;
|
||||
protected SyncService $service;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$addressBook = [
|
||||
'id' => 1,
|
||||
'uri' => 'system',
|
||||
|
|
@ -293,8 +297,8 @@ END:VCARD';
|
|||
}
|
||||
|
||||
public function testEnsureSystemAddressBookExists(): void {
|
||||
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
|
||||
/** @var CardDavBackend&MockObject $backend */
|
||||
$backend = $this->createMock(CardDavBackend::class);
|
||||
$backend->expects($this->exactly(1))->method('createAddressBook');
|
||||
$backend->expects($this->exactly(2))
|
||||
->method('getAddressBooksByUri')
|
||||
|
|
@ -303,10 +307,9 @@ END:VCARD';
|
|||
[],
|
||||
);
|
||||
|
||||
/** @var IUserManager $userManager */
|
||||
$userManager = $this->getMockBuilder(IUserManager::class)->disableOriginalConstructor()->getMock();
|
||||
$userManager = $this->createMock(IUserManager::class);
|
||||
$dbConnection = $this->createMock(IDBConnection::class);
|
||||
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$converter = $this->createMock(Converter::class);
|
||||
$clientService = $this->createMock(IClientService::class);
|
||||
$config = $this->createMock(IConfig::class);
|
||||
|
|
@ -315,7 +318,7 @@ END:VCARD';
|
|||
$ss->ensureSystemAddressBookExists('principals/users/adam', 'contacts', []);
|
||||
}
|
||||
|
||||
public function dataActivatedUsers() {
|
||||
public static function dataActivatedUsers(): array {
|
||||
return [
|
||||
[true, 1, 1, 1],
|
||||
[false, 0, 0, 3],
|
||||
|
|
@ -324,15 +327,9 @@ END:VCARD';
|
|||
|
||||
/**
|
||||
* @dataProvider dataActivatedUsers
|
||||
*
|
||||
* @param boolean $activated
|
||||
* @param integer $createCalls
|
||||
* @param integer $updateCalls
|
||||
* @param integer $deleteCalls
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateAndDeleteUser($activated, $createCalls, $updateCalls, $deleteCalls): void {
|
||||
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */
|
||||
public function testUpdateAndDeleteUser(bool $activated, int $createCalls, int $updateCalls, int $deleteCalls): void {
|
||||
/** @var CardDavBackend | MockObject $backend */
|
||||
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
|
||||
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
|
|
@ -348,12 +345,9 @@ END:VCARD';
|
|||
->with('principals/system/system', 'system')
|
||||
->willReturn(['id' => -1]);
|
||||
|
||||
/** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject $userManager */
|
||||
$userManager = $this->getMockBuilder(IUserManager::class)->disableOriginalConstructor()->getMock();
|
||||
$userManager = $this->createMock(IUserManager::class);
|
||||
$dbConnection = $this->createMock(IDBConnection::class);
|
||||
|
||||
/** @var IUser | \PHPUnit\Framework\MockObject\MockObject $user */
|
||||
$user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->method('getBackendClassName')->willReturn('unittest');
|
||||
$user->method('getUID')->willReturn('test-user');
|
||||
$user->method('getCloudId')->willReturn('cloudId');
|
||||
|
|
@ -475,7 +469,7 @@ END:VCARD';
|
|||
);
|
||||
}
|
||||
|
||||
public function providerUseAbsoluteUriReport(): array {
|
||||
public static function providerUseAbsoluteUriReport(): array {
|
||||
return [
|
||||
['https://server.internal', 'https://server.internal/remote.php/dav/addressbooks/system/system/system'],
|
||||
['https://server.internal/', 'https://server.internal/remote.php/dav/addressbooks/system/system/system'],
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ use Sabre\VObject\Reader;
|
|||
use Test\TestCase;
|
||||
|
||||
class SystemAddressBookTest extends TestCase {
|
||||
private MockObject|BackendInterface $cardDavBackend;
|
||||
private BackendInterface&MockObject $cardDavBackend;
|
||||
private array $addressBookInfo;
|
||||
private IL10N|MockObject $l10n;
|
||||
private IConfig|MockObject $config;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IConfig&MockObject $config;
|
||||
private IUserSession $userSession;
|
||||
private IRequest|MockObject $request;
|
||||
private IRequest&MockObject $request;
|
||||
private array $server;
|
||||
private TrustedServers|MockObject $trustedServers;
|
||||
private IGroupManager|MockObject $groupManager;
|
||||
private TrustedServers&MockObject $trustedServers;
|
||||
private IGroupManager&MockObject $groupManager;
|
||||
private SystemAddressbook $addressBook;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ use Test\TestCase;
|
|||
class CardDavValidatePluginTest extends TestCase {
|
||||
|
||||
private CardDavValidatePlugin $plugin;
|
||||
private IAppConfig|MockObject $config;
|
||||
private RequestInterface|MockObject $request;
|
||||
private ResponseInterface|MockObject $response;
|
||||
private IAppConfig&MockObject $config;
|
||||
private RequestInterface&MockObject $request;
|
||||
private ResponseInterface&MockObject $response;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -36,7 +36,7 @@ class CardDavValidatePluginTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testPutSizeLessThenLimit(): void {
|
||||
|
||||
|
||||
// construct method responses
|
||||
$this->config
|
||||
->method('getValueInt')
|
||||
|
|
@ -50,11 +50,11 @@ class CardDavValidatePluginTest extends TestCase {
|
|||
$this->assertTrue(
|
||||
$this->plugin->beforePut($this->request, $this->response)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testPutSizeMoreThenLimit(): void {
|
||||
|
||||
|
||||
// construct method responses
|
||||
$this->config
|
||||
->method('getValueInt')
|
||||
|
|
@ -67,7 +67,7 @@ class CardDavValidatePluginTest extends TestCase {
|
|||
$this->expectException(Forbidden::class);
|
||||
// test condition
|
||||
$this->plugin->beforePut($this->request, $this->response);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,23 +28,12 @@ class DeleteCalendarTest extends TestCase {
|
|||
public const USER = 'user';
|
||||
public const NAME = 'calendar';
|
||||
|
||||
/** @var CalDavBackend|MockObject */
|
||||
private $calDav;
|
||||
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var IL10N|MockObject */
|
||||
private $l10n;
|
||||
|
||||
/** @var IUserManager|MockObject */
|
||||
private $userManager;
|
||||
|
||||
/** @var DeleteCalendar */
|
||||
private $command;
|
||||
|
||||
/** @var MockObject|LoggerInterface */
|
||||
private $logger;
|
||||
private CalDavBackend&MockObject $calDav;
|
||||
private IConfig&MockObject $config;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private DeleteCalendar $command;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -20,9 +20,8 @@ use Test\TestCase;
|
|||
* @package OCA\DAV\Tests\Command
|
||||
*/
|
||||
class ListAddressbooksTest extends TestCase {
|
||||
|
||||
private IUserManager|MockObject $userManager;
|
||||
private CardDavBackend|MockObject $cardDavBackend;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private CardDavBackend&MockObject $cardDavBackend;
|
||||
private ListAddressbooks $command;
|
||||
|
||||
public const USERNAME = 'username';
|
||||
|
|
@ -72,7 +71,7 @@ class ListAddressbooksTest extends TestCase {
|
|||
$this->assertStringContainsString('User <' . self::USERNAME . "> has no addressbooks\n", $commandTester->getDisplay());
|
||||
}
|
||||
|
||||
public function dataExecute() {
|
||||
public static function dataExecute(): array {
|
||||
return [
|
||||
[false, '✓'],
|
||||
[true, 'x']
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -9,6 +11,7 @@ use OCA\DAV\CalDAV\BirthdayService;
|
|||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\Command\ListCalendars;
|
||||
use OCP\IUserManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Test\TestCase;
|
||||
|
||||
|
|
@ -18,15 +21,9 @@ use Test\TestCase;
|
|||
* @package OCA\DAV\Tests\Command
|
||||
*/
|
||||
class ListCalendarsTest extends TestCase {
|
||||
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject $l10n */
|
||||
private $calDav;
|
||||
|
||||
/** @var ListCalendars */
|
||||
private $command;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private CalDavBackend&MockObject $calDav;
|
||||
private ListCalendars $command;
|
||||
|
||||
public const USERNAME = 'username';
|
||||
|
||||
|
|
@ -75,7 +72,7 @@ class ListCalendarsTest extends TestCase {
|
|||
$this->assertStringContainsString('User <' . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay());
|
||||
}
|
||||
|
||||
public function dataExecute() {
|
||||
public static function dataExecute(): array {
|
||||
return [
|
||||
[false, '✓'],
|
||||
[true, 'x']
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -24,29 +26,14 @@ use Test\TestCase;
|
|||
* @package OCA\DAV\Tests\Command
|
||||
*/
|
||||
class MoveCalendarTest extends TestCase {
|
||||
/** @var IUserManager|MockObject $userManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IGroupManager|MockObject $groupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var \OCP\Share\IManager|MockObject $shareManager */
|
||||
private $shareManager;
|
||||
|
||||
/** @var IConfig|MockObject $l10n */
|
||||
private $config;
|
||||
|
||||
/** @var IL10N|MockObject $l10n */
|
||||
private $l10n;
|
||||
|
||||
/** @var CalDavBackend|MockObject $l10n */
|
||||
private $calDav;
|
||||
|
||||
/** @var MoveCalendar */
|
||||
private $command;
|
||||
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private IGroupManager&MockObject $groupManager;
|
||||
private \OCP\Share\IManager&MockObject $shareManager;
|
||||
private IConfig&MockObject $config;
|
||||
private IL10N&MockObject $l10n;
|
||||
private CalDavBackend&MockObject $calDav;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private MoveCalendar $command;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -70,7 +57,7 @@ class MoveCalendarTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataExecute() {
|
||||
public static function dataExecute(): array {
|
||||
return [
|
||||
[false, true],
|
||||
[true, false]
|
||||
|
|
@ -79,23 +66,16 @@ class MoveCalendarTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataExecute
|
||||
*
|
||||
* @param $userOriginExists
|
||||
* @param $userDestinationExists
|
||||
*/
|
||||
public function testWithBadUserOrigin($userOriginExists, $userDestinationExists): void {
|
||||
public function testWithBadUserOrigin(bool $userOriginExists, bool $userDestinationExists): void {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$this->userManager->expects($this->exactly($userOriginExists ? 2 : 1))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['user'],
|
||||
['user2'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$userOriginExists,
|
||||
$userDestinationExists,
|
||||
);
|
||||
->willReturnMap([
|
||||
['user', $userOriginExists],
|
||||
['user2', $userDestinationExists],
|
||||
]);
|
||||
|
||||
$commandTester = new CommandTester($this->command);
|
||||
$commandTester->execute([
|
||||
|
|
@ -112,11 +92,10 @@ class MoveCalendarTest extends TestCase {
|
|||
|
||||
$this->userManager->expects($this->exactly(2))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['user'],
|
||||
['user2'],
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturnMap([
|
||||
['user', true],
|
||||
['user2', true],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->once())->method('getCalendarByUri')
|
||||
->with('principals/users/user', 'personal')
|
||||
|
|
@ -137,20 +116,20 @@ class MoveCalendarTest extends TestCase {
|
|||
|
||||
$this->userManager->expects($this->exactly(2))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['user'],
|
||||
['user2'],
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturnMap([
|
||||
['user', true],
|
||||
['user2', true],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->exactly(2))
|
||||
->method('getCalendarByUri')
|
||||
->withConsecutive(
|
||||
['principals/users/user', 'personal'],
|
||||
['principals/users/user2', 'personal'],
|
||||
)
|
||||
->willReturn([
|
||||
'id' => 1234,
|
||||
->willReturnMap([
|
||||
['principals/users/user', 'personal', [
|
||||
'id' => 1234,
|
||||
]],
|
||||
['principals/users/user2', 'personal', [
|
||||
'id' => 1234,
|
||||
]],
|
||||
]);
|
||||
|
||||
$commandTester = new CommandTester($this->command);
|
||||
|
|
@ -164,24 +143,19 @@ class MoveCalendarTest extends TestCase {
|
|||
public function testMove(): void {
|
||||
$this->userManager->expects($this->exactly(2))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['user'],
|
||||
['user2'],
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturnMap([
|
||||
['user', true],
|
||||
['user2', true],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->exactly(2))
|
||||
->method('getCalendarByUri')
|
||||
->withConsecutive(
|
||||
['principals/users/user', 'personal'],
|
||||
['principals/users/user2', 'personal'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[
|
||||
->willReturnMap([
|
||||
['principals/users/user', 'personal', [
|
||||
'id' => 1234,
|
||||
],
|
||||
null,
|
||||
);
|
||||
]],
|
||||
['principals/users/user2', 'personal', null],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->once())->method('getShares')
|
||||
->with(1234)
|
||||
|
|
@ -197,7 +171,7 @@ class MoveCalendarTest extends TestCase {
|
|||
$this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
|
||||
}
|
||||
|
||||
public function dataTestMoveWithDestinationNotPartOfGroup(): array {
|
||||
public static function dataTestMoveWithDestinationNotPartOfGroup(): array {
|
||||
return [
|
||||
[true],
|
||||
[false]
|
||||
|
|
@ -210,25 +184,20 @@ class MoveCalendarTest extends TestCase {
|
|||
public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly): void {
|
||||
$this->userManager->expects($this->exactly(2))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['user'],
|
||||
['user2'],
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturnMap([
|
||||
['user', true],
|
||||
['user2', true],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->exactly(2))
|
||||
->method('getCalendarByUri')
|
||||
->withConsecutive(
|
||||
['principals/users/user', 'personal'],
|
||||
['principals/users/user2', 'personal'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[
|
||||
->willReturnMap([
|
||||
['principals/users/user', 'personal', [
|
||||
'id' => 1234,
|
||||
'uri' => 'personal',
|
||||
],
|
||||
null,
|
||||
);
|
||||
]],
|
||||
['principals/users/user2', 'personal', null],
|
||||
]);
|
||||
|
||||
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
|
||||
->willReturn($shareWithGroupMembersOnly);
|
||||
|
|
@ -254,25 +223,20 @@ class MoveCalendarTest extends TestCase {
|
|||
public function testMoveWithDestinationPartOfGroup(): void {
|
||||
$this->userManager->expects($this->exactly(2))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['user'],
|
||||
['user2'],
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturnMap([
|
||||
['user', true],
|
||||
['user2', true],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->exactly(2))
|
||||
->method('getCalendarByUri')
|
||||
->withConsecutive(
|
||||
['principals/users/user', 'personal'],
|
||||
['principals/users/user2', 'personal'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[
|
||||
->willReturnMap([
|
||||
['principals/users/user', 'personal', [
|
||||
'id' => 1234,
|
||||
'uri' => 'personal',
|
||||
],
|
||||
null,
|
||||
);
|
||||
]],
|
||||
['principals/users/user2', 'personal', null],
|
||||
]);
|
||||
|
||||
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
|
||||
->willReturn(true);
|
||||
|
|
@ -300,26 +264,21 @@ class MoveCalendarTest extends TestCase {
|
|||
public function testMoveWithDestinationNotPartOfGroupAndForce(): void {
|
||||
$this->userManager->expects($this->exactly(2))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['user'],
|
||||
['user2'],
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturnMap([
|
||||
['user', true],
|
||||
['user2', true],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->exactly(2))
|
||||
->method('getCalendarByUri')
|
||||
->withConsecutive(
|
||||
['principals/users/user', 'personal'],
|
||||
['principals/users/user2', 'personal'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[
|
||||
->willReturnMap([
|
||||
['principals/users/user', 'personal', [
|
||||
'id' => 1234,
|
||||
'uri' => 'personal',
|
||||
'{DAV:}displayname' => 'Personal'
|
||||
],
|
||||
null,
|
||||
);
|
||||
]],
|
||||
['principals/users/user2', 'personal', null],
|
||||
]);
|
||||
|
||||
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
|
||||
->willReturn(true);
|
||||
|
|
@ -345,7 +304,7 @@ class MoveCalendarTest extends TestCase {
|
|||
$this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
|
||||
}
|
||||
|
||||
public function dataTestMoveWithCalendarAlreadySharedToDestination(): array {
|
||||
public static function dataTestMoveWithCalendarAlreadySharedToDestination(): array {
|
||||
return [
|
||||
[true],
|
||||
[false]
|
||||
|
|
@ -358,26 +317,21 @@ class MoveCalendarTest extends TestCase {
|
|||
public function testMoveWithCalendarAlreadySharedToDestination(bool $force): void {
|
||||
$this->userManager->expects($this->exactly(2))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
['user'],
|
||||
['user2'],
|
||||
)
|
||||
->willReturn(true);
|
||||
->willReturnMap([
|
||||
['user', true],
|
||||
['user2', true],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->exactly(2))
|
||||
->method('getCalendarByUri')
|
||||
->withConsecutive(
|
||||
['principals/users/user', 'personal'],
|
||||
['principals/users/user2', 'personal'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[
|
||||
->willReturnMap([
|
||||
['principals/users/user', 'personal', [
|
||||
'id' => 1234,
|
||||
'uri' => 'personal',
|
||||
'{DAV:}displayname' => 'Personal'
|
||||
],
|
||||
null,
|
||||
);
|
||||
]],
|
||||
['principals/users/user2', 'personal', null],
|
||||
]);
|
||||
|
||||
$this->calDav->expects($this->once())->method('getShares')
|
||||
->with(1234)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2018 ownCloud GmbH
|
||||
|
|
@ -10,7 +11,6 @@ namespace OCA\DAV\Tests\Unit\Command;
|
|||
use OCA\DAV\Command\RemoveInvalidShares;
|
||||
use OCA\DAV\Connector\Sabre\Principal;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Server;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
|
@ -37,18 +37,16 @@ class RemoveInvalidSharesTest extends TestCase {
|
|||
|
||||
public function test(): void {
|
||||
$db = Server::get(IDBConnection::class);
|
||||
/** @var Principal | \PHPUnit\Framework\MockObject\MockObject $principal */
|
||||
$principal = $this->createMock(Principal::class);
|
||||
|
||||
/** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $output */
|
||||
$output = $this->createMock(IOutput::class);
|
||||
|
||||
$repair = new RemoveInvalidShares($db, $principal);
|
||||
$this->invokePrivate($repair, 'run', [$this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)]);
|
||||
|
||||
$query = $db->getQueryBuilder();
|
||||
$result = $query->select('*')->from('dav_shares')
|
||||
->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')))->execute();
|
||||
$query->select('*')
|
||||
->from('dav_shares')
|
||||
->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')));
|
||||
$result = $query->executeQuery();
|
||||
$data = $result->fetchAll();
|
||||
$result->closeCursor();
|
||||
$this->assertEquals(0, count($data));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -14,38 +15,26 @@ use OCP\Comments\MessageTooLongException;
|
|||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Sabre\DAV\PropPatch;
|
||||
|
||||
class CommentsNodeTest extends \Test\TestCase {
|
||||
|
||||
/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $commentsManager;
|
||||
|
||||
protected $comment;
|
||||
protected $node;
|
||||
protected $userManager;
|
||||
protected $logger;
|
||||
protected $userSession;
|
||||
protected ICommentsManager&MockObject $commentsManager;
|
||||
protected IComment&MockObject $comment;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
protected IUserSession&MockObject $userSession;
|
||||
protected CommentNode $node;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->commentsManager = $this->getMockBuilder(ICommentsManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->comment = $this->getMockBuilder(IComment::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userManager = $this->getMockBuilder(IUserManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
||||
$this->comment = $this->createMock(IComment::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$this->node = new CommentNode(
|
||||
$this->commentsManager,
|
||||
|
|
@ -57,10 +46,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testDelete(): void {
|
||||
$user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn('alice');
|
||||
|
|
@ -92,10 +78,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
public function testDeleteForbidden(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
||||
|
||||
$user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn('mallory');
|
||||
|
|
@ -144,10 +127,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
public function testUpdateComment(): void {
|
||||
$msg = 'Hello Earth';
|
||||
|
||||
$user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn('alice');
|
||||
|
|
@ -182,10 +162,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
|
||||
$msg = null;
|
||||
|
||||
$user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn('alice');
|
||||
|
|
@ -221,10 +198,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
|
||||
$this->expectExceptionMessage('Message exceeds allowed character limit of');
|
||||
|
||||
$user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn('alice');
|
||||
|
|
@ -261,10 +235,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
|
||||
$msg = 'HaXX0r';
|
||||
|
||||
$user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn('mallory');
|
||||
|
|
@ -296,10 +267,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
|
||||
$msg = 'HaXX0r';
|
||||
|
||||
$user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->never())
|
||||
->method('getUID');
|
||||
|
||||
|
|
@ -344,10 +312,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testPropPatch(): void {
|
||||
$propPatch = $this->getMockBuilder(PropPatch::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$propPatch = $this->createMock(PropPatch::class);
|
||||
$propPatch->expects($this->once())
|
||||
->method('handle')
|
||||
->with('{http://owncloud.org/ns}message');
|
||||
|
|
@ -396,11 +361,10 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
|
||||
$this->commentsManager->expects($this->exactly(2))
|
||||
->method('resolveDisplayName')
|
||||
->withConsecutive(
|
||||
[$this->equalTo('user'), $this->equalTo('alice')],
|
||||
[$this->equalTo('user'), $this->equalTo('bob')]
|
||||
)
|
||||
->willReturnOnConsecutiveCalls('Alice Al-Isson', 'Unknown user');
|
||||
->willReturnMap([
|
||||
['user', 'alice', 'Alice Al-Isson'],
|
||||
['user', 'bob', 'Unknown user']
|
||||
]);
|
||||
|
||||
$this->comment->expects($this->once())
|
||||
->method('getId')
|
||||
|
|
@ -491,7 +455,7 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
$this->assertTrue(empty($expected));
|
||||
}
|
||||
|
||||
public function readCommentProvider() {
|
||||
public static function readCommentProvider(): array {
|
||||
$creationDT = new \DateTime('2016-01-19 18:48:00');
|
||||
$diff = new \DateInterval('PT2H');
|
||||
$readDT1 = clone $creationDT;
|
||||
|
|
@ -507,9 +471,8 @@ class CommentsNodeTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider readCommentProvider
|
||||
* @param $expected
|
||||
*/
|
||||
public function testGetPropertiesUnreadProperty($creationDT, $readDT, $expected): void {
|
||||
public function testGetPropertiesUnreadProperty(\DateTime $creationDT, ?\DateTime $readDT, string $expected): void {
|
||||
$this->comment->expects($this->any())
|
||||
->method('getCreationDateTime')
|
||||
->willReturn($creationDT);
|
||||
|
|
|
|||
|
|
@ -14,44 +14,30 @@ use OCP\Comments\IComment;
|
|||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Sabre\DAV\INode;
|
||||
use Sabre\DAV\Tree;
|
||||
use Sabre\HTTP\RequestInterface;
|
||||
use Sabre\HTTP\ResponseInterface;
|
||||
|
||||
class CommentsPluginTest extends \Test\TestCase {
|
||||
/** @var \Sabre\DAV\Server */
|
||||
private $server;
|
||||
|
||||
/** @var Tree */
|
||||
private $tree;
|
||||
|
||||
/** @var ICommentsManager */
|
||||
private $commentsManager;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
/** @var CommentsPluginImplementation */
|
||||
private $plugin;
|
||||
private \Sabre\DAV\Server&MockObject $server;
|
||||
private Tree&MockObject $tree;
|
||||
private ICommentsManager&MockObject $commentsManager;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private CommentsPluginImplementation $plugin;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->tree = $this->getMockBuilder(Tree::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->tree = $this->createMock(Tree::class);
|
||||
|
||||
$this->server = $this->getMockBuilder('\Sabre\DAV\Server')
|
||||
$this->server = $this->getMockBuilder(\Sabre\DAV\Server::class)
|
||||
->setConstructorArgs([$this->tree])
|
||||
->setMethods(['getRequestUri'])
|
||||
->onlyMethods(['getRequestUri'])
|
||||
->getMock();
|
||||
|
||||
$this->commentsManager = $this->getMockBuilder(ICommentsManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
|
||||
$this->plugin = new CommentsPluginImplementation($this->commentsManager, $this->userSession);
|
||||
}
|
||||
|
|
@ -151,7 +137,7 @@ class CommentsPluginTest extends \Test\TestCase {
|
|||
$this->plugin->httpPost($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testCreateCommentInvalidObject(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
||||
|
||||
|
|
@ -233,7 +219,7 @@ class CommentsPluginTest extends \Test\TestCase {
|
|||
$this->plugin->httpPost($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testCreateCommentInvalidActor(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
|
||||
|
||||
|
|
@ -321,7 +307,7 @@ class CommentsPluginTest extends \Test\TestCase {
|
|||
$this->plugin->httpPost($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testCreateCommentUnsupportedMediaType(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\UnsupportedMediaType::class);
|
||||
|
||||
|
|
@ -409,7 +395,7 @@ class CommentsPluginTest extends \Test\TestCase {
|
|||
$this->plugin->httpPost($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testCreateCommentInvalidPayload(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
|
||||
|
||||
|
|
@ -503,7 +489,7 @@ class CommentsPluginTest extends \Test\TestCase {
|
|||
$this->plugin->httpPost($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testCreateCommentMessageTooLong(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
|
||||
$this->expectExceptionMessage('Message exceeds allowed character limit of');
|
||||
|
|
@ -597,7 +583,7 @@ class CommentsPluginTest extends \Test\TestCase {
|
|||
$this->plugin->httpPost($request, $response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testOnReportInvalidNode(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\ReportNotSupported::class);
|
||||
|
||||
|
|
@ -620,7 +606,7 @@ class CommentsPluginTest extends \Test\TestCase {
|
|||
$this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, [], '/' . $path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testOnReportInvalidReportName(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\ReportNotSupported::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -14,36 +15,23 @@ use OCP\Comments\ICommentsManager;
|
|||
use OCP\Comments\NotFoundException;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class EntityCollectionTest extends \Test\TestCase {
|
||||
|
||||
/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $commentsManager;
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $userManager;
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $logger;
|
||||
/** @var EntityCollection */
|
||||
protected $collection;
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $userSession;
|
||||
protected ICommentsManager&MockObject $commentsManager;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
protected IUserSession&MockObject $userSession;
|
||||
protected EntityCollection $collection;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->commentsManager = $this->getMockBuilder(ICommentsManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userManager = $this->getMockBuilder(IUserManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$this->collection = new EntityCollection(
|
||||
'19',
|
||||
|
|
@ -70,7 +58,7 @@ class EntityCollectionTest extends \Test\TestCase {
|
|||
);
|
||||
|
||||
$node = $this->collection->getChild('55');
|
||||
$this->assertTrue($node instanceof CommentNode);
|
||||
$this->assertInstanceOf(CommentNode::class, $node);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -97,8 +85,8 @@ class EntityCollectionTest extends \Test\TestCase {
|
|||
|
||||
$result = $this->collection->getChildren();
|
||||
|
||||
$this->assertSame(count($result), 1);
|
||||
$this->assertTrue($result[0] instanceof CommentNode);
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertInstanceOf(CommentNode::class, $result[0]);
|
||||
}
|
||||
|
||||
public function testFindChildren(): void {
|
||||
|
|
@ -114,8 +102,8 @@ class EntityCollectionTest extends \Test\TestCase {
|
|||
|
||||
$result = $this->collection->findChildren(5, 15, $dt);
|
||||
|
||||
$this->assertSame(count($result), 1);
|
||||
$this->assertTrue($result[0] instanceof CommentNode);
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertInstanceOf(CommentNode::class, $result[0]);
|
||||
}
|
||||
|
||||
public function testChildExistsTrue(): void {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -12,40 +13,25 @@ use OCA\DAV\Comments\EntityTypeCollection;
|
|||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class EntityTypeCollectionTest extends \Test\TestCase {
|
||||
|
||||
/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $commentsManager;
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $userManager;
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $logger;
|
||||
/** @var EntityTypeCollection */
|
||||
protected $collection;
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $userSession;
|
||||
protected ICommentsManager&MockObject $commentsManager;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
protected IUserSession&MockObject $userSession;
|
||||
protected EntityTypeCollection $collection;
|
||||
|
||||
protected $childMap = [];
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->commentsManager = $this->getMockBuilder(ICommentsManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userManager = $this->getMockBuilder(IUserManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$instance = $this;
|
||||
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$this->collection = new EntityTypeCollection(
|
||||
'files',
|
||||
|
|
@ -53,8 +39,8 @@ class EntityTypeCollectionTest extends \Test\TestCase {
|
|||
$this->userManager,
|
||||
$this->userSession,
|
||||
$this->logger,
|
||||
function ($child) use ($instance) {
|
||||
return !empty($instance->childMap[$child]);
|
||||
function ($child) {
|
||||
return !empty($this->childMap[$child]);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -72,7 +58,7 @@ class EntityTypeCollectionTest extends \Test\TestCase {
|
|||
$this->childMap[17] = true;
|
||||
|
||||
$ec = $this->collection->getChild('17');
|
||||
$this->assertTrue($ec instanceof EntityCollectionImplemantation);
|
||||
$this->assertInstanceOf(EntityCollectionImplemantation::class, $ec);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -16,44 +17,27 @@ use OCP\EventDispatcher\IEventDispatcher;
|
|||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class RootCollectionTest extends \Test\TestCase {
|
||||
|
||||
/** @var ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $commentsManager;
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $userManager;
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $logger;
|
||||
/** @var RootCollection */
|
||||
protected $collection;
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $userSession;
|
||||
/** @var IEventDispatcher */
|
||||
protected $dispatcher;
|
||||
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $user;
|
||||
protected ICommentsManager&MockObject $commentsManager;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
protected IUserSession&MockObject $userSession;
|
||||
protected IEventDispatcher $dispatcher;
|
||||
protected IUser&MockObject $user;
|
||||
protected RootCollection $collection;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->user = $this->createMock(IUser::class);
|
||||
|
||||
$this->commentsManager = $this->getMockBuilder(ICommentsManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userManager = $this->getMockBuilder(IUserManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->dispatcher = new EventDispatcher(
|
||||
new \Symfony\Component\EventDispatcher\EventDispatcher(),
|
||||
\OC::$server,
|
||||
|
|
@ -69,7 +53,7 @@ class RootCollectionTest extends \Test\TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
protected function prepareForInitCollections() {
|
||||
protected function prepareForInitCollections(): void {
|
||||
$this->user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('alice');
|
||||
|
|
@ -102,7 +86,7 @@ class RootCollectionTest extends \Test\TestCase {
|
|||
public function testGetChild(): void {
|
||||
$this->prepareForInitCollections();
|
||||
$etc = $this->collection->getChild('files');
|
||||
$this->assertTrue($etc instanceof EntityTypeCollectionImplementation);
|
||||
$this->assertInstanceOf(EntityTypeCollectionImplementation::class, $etc);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -125,7 +109,7 @@ class RootCollectionTest extends \Test\TestCase {
|
|||
$children = $this->collection->getChildren();
|
||||
$this->assertFalse(empty($children));
|
||||
foreach ($children as $child) {
|
||||
$this->assertTrue($child instanceof EntityTypeCollectionImplementation);
|
||||
$this->assertInstanceOf(EntityTypeCollectionImplementation::class, $child);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue