mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
Merge pull request #53122 from nextcloud/tests/noid/dav-systemtag
test: Migrate DAV Systemtags tests to PHPUnit 10
This commit is contained in:
commit
5bade98f69
11 changed files with 250 additions and 386 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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -22,7 +23,7 @@ class ServerTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider providesUris
|
||||
*/
|
||||
public function test($uri, array $plugins): void {
|
||||
public function test(string $uri, array $plugins): void {
|
||||
/** @var IRequest | \PHPUnit\Framework\MockObject\MockObject $r */
|
||||
$r = $this->createMock(IRequest::class);
|
||||
$r->expects($this->any())->method('getRequestUri')->willReturn($uri);
|
||||
|
|
@ -33,7 +34,7 @@ class ServerTest extends \Test\TestCase {
|
|||
$this->assertNotNull($s->server->getPlugin($plugin));
|
||||
}
|
||||
}
|
||||
public function providesUris() {
|
||||
public static function providesUris(): array {
|
||||
return [
|
||||
'principals' => ['principals/users/admin', ['caldav', 'oc-resource-sharing', 'carddav']],
|
||||
'calendars' => ['calendars/admin', ['caldav', 'oc-resource-sharing']],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -15,19 +17,10 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class CalDAVSettingsTest extends TestCase {
|
||||
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var IInitialState|MockObject */
|
||||
private $initialState;
|
||||
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var IAppManager|MockObject */
|
||||
private $appManager;
|
||||
|
||||
private IConfig&MockObject $config;
|
||||
private IInitialState&MockObject $initialState;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private IAppManager&MockObject $appManager;
|
||||
private CalDAVSettings $settings;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
@ -42,28 +35,32 @@ class CalDAVSettingsTest extends TestCase {
|
|||
|
||||
public function testGetForm(): void {
|
||||
$this->config->method('getAppValue')
|
||||
->withConsecutive(
|
||||
['dav', 'sendInvitations', 'yes'],
|
||||
['dav', 'generateBirthdayCalendar', 'yes'],
|
||||
['dav', 'sendEventReminders', 'yes'],
|
||||
['dav', 'sendEventRemindersToSharedUsers', 'yes'],
|
||||
['dav', 'sendEventRemindersPush', 'yes'],
|
||||
)
|
||||
->will($this->onConsecutiveCalls('yes', 'no', 'yes', 'yes', 'yes'));
|
||||
->willReturnMap([
|
||||
['dav', 'sendInvitations', 'yes', 'yes'],
|
||||
['dav', 'generateBirthdayCalendar', 'yes', 'no'],
|
||||
['dav', 'sendEventReminders', 'yes', 'yes'],
|
||||
['dav', 'sendEventRemindersToSharedUsers', 'yes', 'yes'],
|
||||
['dav', 'sendEventRemindersPush', 'yes', 'yes'],
|
||||
]);
|
||||
$this->urlGenerator
|
||||
->expects($this->once())
|
||||
->method('linkToDocs')
|
||||
->with('user-sync-calendars')
|
||||
->willReturn('Some docs URL');
|
||||
|
||||
$calls = [
|
||||
['userSyncCalendarsDocUrl', 'Some docs URL'],
|
||||
['sendInvitations', true],
|
||||
['generateBirthdayCalendar', false],
|
||||
['sendEventReminders', true],
|
||||
['sendEventRemindersToSharedUsers', true],
|
||||
['sendEventRemindersPush', true],
|
||||
];
|
||||
$this->initialState->method('provideInitialState')
|
||||
->withConsecutive(
|
||||
['userSyncCalendarsDocUrl', 'Some docs URL'],
|
||||
['sendInvitations', true],
|
||||
['generateBirthdayCalendar', false],
|
||||
['sendEventReminders', true],
|
||||
['sendEventRemindersToSharedUsers', true],
|
||||
['sendEventRemindersPush', true],
|
||||
);
|
||||
->willReturnCallback(function () use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
});
|
||||
$result = $this->settings->getForm();
|
||||
|
||||
$this->assertInstanceOf(TemplateResponse::class, $result);
|
||||
|
|
@ -88,5 +85,4 @@ class CalDAVSettingsTest extends TestCase {
|
|||
public function testGetPriority(): void {
|
||||
$this->assertEquals(10, $this->settings->getPriority());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -14,30 +15,28 @@ use OCP\SystemTag\ISystemTag;
|
|||
use OCP\SystemTag\ISystemTagManager;
|
||||
use OCP\SystemTag\ISystemTagObjectMapper;
|
||||
use OCP\SystemTag\TagNotFoundException;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class SystemTagMappingNodeTest extends \Test\TestCase {
|
||||
private ISystemTagManager $tagManager;
|
||||
private ISystemTagObjectMapper $tagMapper;
|
||||
private IUser $user;
|
||||
private ISystemTagManager&MockObject $tagManager;
|
||||
private ISystemTagObjectMapper&MockObject $tagMapper;
|
||||
private IUser&MockObject $user;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->tagManager = $this->getMockBuilder(ISystemTagManager::class)
|
||||
->getMock();
|
||||
$this->tagMapper = $this->getMockBuilder(ISystemTagObjectMapper::class)
|
||||
->getMock();
|
||||
$this->user = $this->getMockBuilder(IUser::class)
|
||||
->getMock();
|
||||
$this->tagManager = $this->createMock(ISystemTagManager::class);
|
||||
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
|
||||
$this->user = $this->createMock(IUser::class);
|
||||
}
|
||||
|
||||
public function getMappingNode($tag = null, array $writableNodeIds = []) {
|
||||
if ($tag === null) {
|
||||
$tag = new SystemTag(1, 'Test', true, true);
|
||||
$tag = new SystemTag('1', 'Test', true, true);
|
||||
}
|
||||
return new SystemTagMappingNode(
|
||||
$tag,
|
||||
123,
|
||||
'123',
|
||||
'files',
|
||||
$this->user,
|
||||
$this->tagManager,
|
||||
|
|
@ -47,7 +46,7 @@ class SystemTagMappingNodeTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetters(): void {
|
||||
$tag = new SystemTag(1, 'Test', true, false);
|
||||
$tag = new SystemTag('1', 'Test', true, false);
|
||||
$node = $this->getMappingNode($tag);
|
||||
$this->assertEquals('1', $node->getName());
|
||||
$this->assertEquals($tag, $node->getSystemTag());
|
||||
|
|
@ -93,16 +92,16 @@ class SystemTagMappingNodeTest extends \Test\TestCase {
|
|||
$node->delete();
|
||||
}
|
||||
|
||||
public function tagNodeDeleteProviderPermissionException() {
|
||||
public static function tagNodeDeleteProviderPermissionException(): array {
|
||||
return [
|
||||
[
|
||||
// cannot unassign invisible tag
|
||||
new SystemTag(1, 'Original', false, true),
|
||||
new SystemTag('1', 'Original', false, true),
|
||||
'Sabre\DAV\Exception\NotFound',
|
||||
],
|
||||
[
|
||||
// cannot unassign non-assignable tag
|
||||
new SystemTag(1, 'Original', true, false),
|
||||
new SystemTag('1', 'Original', true, false),
|
||||
'Sabre\DAV\Exception\Forbidden',
|
||||
],
|
||||
];
|
||||
|
|
@ -141,7 +140,7 @@ class SystemTagMappingNodeTest extends \Test\TestCase {
|
|||
|
||||
// assuming the tag existed at the time the node was created,
|
||||
// but got deleted concurrently in the database
|
||||
$tag = new SystemTag(1, 'Test', true, true);
|
||||
$tag = new SystemTag('1', 'Test', true, true);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -15,39 +16,25 @@ use OCP\SystemTag\ISystemTagManager;
|
|||
use OCP\SystemTag\ISystemTagObjectMapper;
|
||||
use OCP\SystemTag\TagAlreadyExistsException;
|
||||
use OCP\SystemTag\TagNotFoundException;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Sabre\DAV\Exception\Forbidden;
|
||||
|
||||
class SystemTagNodeTest extends \Test\TestCase {
|
||||
|
||||
/**
|
||||
* @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $tagManager;
|
||||
|
||||
/**
|
||||
* @var ISystemTagObjectMapper|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $tagMapper;
|
||||
|
||||
/**
|
||||
* @var IUser
|
||||
*/
|
||||
private $user;
|
||||
private ISystemTagManager&MockObject $tagManager;
|
||||
private ISystemTagObjectMapper&MockObject $tagMapper;
|
||||
private IUser&MockObject $user;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->tagManager = $this->getMockBuilder(ISystemTagManager::class)
|
||||
->getMock();
|
||||
$this->tagMapper = $this->getMockBuilder(ISystemTagObjectMapper::class)
|
||||
->getMock();
|
||||
$this->user = $this->getMockBuilder(IUser::class)
|
||||
->getMock();
|
||||
$this->tagManager = $this->createMock(ISystemTagManager::class);
|
||||
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
|
||||
$this->user = $this->createMock(IUser::class);
|
||||
}
|
||||
|
||||
protected function getTagNode($isAdmin = true, $tag = null) {
|
||||
if ($tag === null) {
|
||||
$tag = new SystemTag(1, 'Test', true, true);
|
||||
$tag = new SystemTag('1', 'Test', true, true);
|
||||
}
|
||||
return new SystemTagNode(
|
||||
$tag,
|
||||
|
|
@ -58,14 +45,14 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function adminFlagProvider() {
|
||||
public static function adminFlagProvider(): array {
|
||||
return [[true], [false]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider adminFlagProvider
|
||||
*/
|
||||
public function testGetters($isAdmin): void {
|
||||
public function testGetters(bool $isAdmin): void {
|
||||
$tag = new SystemTag('1', 'Test', true, true);
|
||||
$node = $this->getTagNode($isAdmin, $tag);
|
||||
$this->assertEquals('1', $node->getName());
|
||||
|
|
@ -79,24 +66,24 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
$this->getTagNode()->setName('2');
|
||||
}
|
||||
|
||||
public function tagNodeProvider() {
|
||||
public static function tagNodeProvider(): array {
|
||||
return [
|
||||
// admin
|
||||
[
|
||||
true,
|
||||
new SystemTag(1, 'Original', true, true),
|
||||
new SystemTag('1', 'Original', true, true),
|
||||
['Renamed', true, true, null]
|
||||
],
|
||||
[
|
||||
true,
|
||||
new SystemTag(1, 'Original', true, true),
|
||||
new SystemTag('1', 'Original', true, true),
|
||||
['Original', false, false, null]
|
||||
],
|
||||
// non-admin
|
||||
[
|
||||
// renaming allowed
|
||||
false,
|
||||
new SystemTag(1, 'Original', true, true),
|
||||
new SystemTag('1', 'Original', true, true),
|
||||
['Rename', true, true, '0082c9']
|
||||
],
|
||||
];
|
||||
|
|
@ -105,7 +92,7 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider tagNodeProvider
|
||||
*/
|
||||
public function testUpdateTag($isAdmin, ISystemTag $originalTag, $changedArgs): void {
|
||||
public function testUpdateTag(bool $isAdmin, ISystemTag $originalTag, array $changedArgs): void {
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('canUserSeeTag')
|
||||
->with($originalTag)
|
||||
|
|
@ -121,41 +108,41 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
->update($changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]);
|
||||
}
|
||||
|
||||
public function tagNodeProviderPermissionException() {
|
||||
public static function tagNodeProviderPermissionException(): array {
|
||||
return [
|
||||
[
|
||||
// changing permissions not allowed
|
||||
new SystemTag(1, 'Original', true, true),
|
||||
new SystemTag('1', 'Original', true, true),
|
||||
['Original', false, true, ''],
|
||||
'Sabre\DAV\Exception\Forbidden',
|
||||
],
|
||||
[
|
||||
// changing permissions not allowed
|
||||
new SystemTag(1, 'Original', true, true),
|
||||
new SystemTag('1', 'Original', true, true),
|
||||
['Original', true, false, ''],
|
||||
'Sabre\DAV\Exception\Forbidden',
|
||||
],
|
||||
[
|
||||
// changing permissions not allowed
|
||||
new SystemTag(1, 'Original', true, true),
|
||||
new SystemTag('1', 'Original', true, true),
|
||||
['Original', false, false, ''],
|
||||
'Sabre\DAV\Exception\Forbidden',
|
||||
],
|
||||
[
|
||||
// changing non-assignable not allowed
|
||||
new SystemTag(1, 'Original', true, false),
|
||||
new SystemTag('1', 'Original', true, false),
|
||||
['Rename', true, false, ''],
|
||||
'Sabre\DAV\Exception\Forbidden',
|
||||
],
|
||||
[
|
||||
// changing non-assignable not allowed
|
||||
new SystemTag(1, 'Original', true, false),
|
||||
new SystemTag('1', 'Original', true, false),
|
||||
['Original', true, true, ''],
|
||||
'Sabre\DAV\Exception\Forbidden',
|
||||
],
|
||||
[
|
||||
// invisible tag does not exist
|
||||
new SystemTag(1, 'Original', false, false),
|
||||
new SystemTag('1', 'Original', false, false),
|
||||
['Rename', false, false, ''],
|
||||
'Sabre\DAV\Exception\NotFound',
|
||||
],
|
||||
|
|
@ -165,7 +152,7 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider tagNodeProviderPermissionException
|
||||
*/
|
||||
public function testUpdateTagPermissionException(ISystemTag $originalTag, $changedArgs, $expectedException = null): void {
|
||||
public function testUpdateTagPermissionException(ISystemTag $originalTag, array $changedArgs, string $expectedException): void {
|
||||
$this->tagManager->expects($this->any())
|
||||
->method('canUserSeeTag')
|
||||
->with($originalTag)
|
||||
|
|
@ -193,7 +180,7 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
public function testUpdateTagAlreadyExists(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Conflict::class);
|
||||
|
||||
$tag = new SystemTag(1, 'tag1', true, true);
|
||||
$tag = new SystemTag('1', 'tag1', true, true);
|
||||
$this->tagManager->expects($this->any())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
@ -213,7 +200,7 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
public function testUpdateTagNotFound(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
||||
|
||||
$tag = new SystemTag(1, 'tag1', true, true);
|
||||
$tag = new SystemTag('1', 'tag1', true, true);
|
||||
$this->tagManager->expects($this->any())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
@ -232,8 +219,8 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider adminFlagProvider
|
||||
*/
|
||||
public function testDeleteTag($isAdmin): void {
|
||||
$tag = new SystemTag(1, 'tag1', true, true);
|
||||
public function testDeleteTag(bool $isAdmin): void {
|
||||
$tag = new SystemTag('1', 'tag1', true, true);
|
||||
$this->tagManager->expects($isAdmin ? $this->once() : $this->never())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
@ -247,16 +234,16 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
$this->getTagNode($isAdmin, $tag)->delete();
|
||||
}
|
||||
|
||||
public function tagNodeDeleteProviderPermissionException() {
|
||||
public static function tagNodeDeleteProviderPermissionException(): array {
|
||||
return [
|
||||
[
|
||||
// cannot delete invisible tag
|
||||
new SystemTag(1, 'Original', false, true),
|
||||
new SystemTag('1', 'Original', false, true),
|
||||
'Sabre\DAV\Exception\Forbidden',
|
||||
],
|
||||
[
|
||||
// cannot delete non-assignable tag
|
||||
new SystemTag(1, 'Original', true, false),
|
||||
new SystemTag('1', 'Original', true, false),
|
||||
'Sabre\DAV\Exception\Forbidden',
|
||||
],
|
||||
];
|
||||
|
|
@ -265,7 +252,7 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider tagNodeDeleteProviderPermissionException
|
||||
*/
|
||||
public function testDeleteTagPermissionException(ISystemTag $tag, $expectedException): void {
|
||||
public function testDeleteTagPermissionException(ISystemTag $tag, string $expectedException): void {
|
||||
$this->tagManager->expects($this->any())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
@ -281,7 +268,7 @@ class SystemTagNodeTest extends \Test\TestCase {
|
|||
public function testDeleteTagNotFound(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
||||
|
||||
$tag = new SystemTag(1, 'tag1', true, true);
|
||||
$tag = new SystemTag('1', 'tag1', true, true);
|
||||
$this->tagManager->expects($this->any())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -20,6 +21,7 @@ use OCP\SystemTag\ISystemTag;
|
|||
use OCP\SystemTag\ISystemTagManager;
|
||||
use OCP\SystemTag\ISystemTagObjectMapper;
|
||||
use OCP\SystemTag\TagAlreadyExistsException;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Sabre\DAV\Tree;
|
||||
use Sabre\HTTP\RequestInterface;
|
||||
use Sabre\HTTP\ResponseInterface;
|
||||
|
|
@ -32,67 +34,26 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
public const CANASSIGN_PROPERTYNAME = SystemTagPlugin::CANASSIGN_PROPERTYNAME;
|
||||
public const GROUPS_PROPERTYNAME = SystemTagPlugin::GROUPS_PROPERTYNAME;
|
||||
|
||||
/**
|
||||
* @var \Sabre\DAV\Server
|
||||
*/
|
||||
private $server;
|
||||
|
||||
/**
|
||||
* @var \Sabre\DAV\Tree
|
||||
*/
|
||||
private $tree;
|
||||
|
||||
/**
|
||||
* @var ISystemTagManager
|
||||
*/
|
||||
private $tagManager;
|
||||
|
||||
/**
|
||||
* @var IGroupManager
|
||||
*/
|
||||
private $groupManager;
|
||||
|
||||
/**
|
||||
* @var IUserSession
|
||||
*/
|
||||
private $userSession;
|
||||
|
||||
/**
|
||||
* @var IRootFolder
|
||||
*/
|
||||
private $rootFolder;
|
||||
|
||||
/**
|
||||
* @var IUser
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var SystemTagPlugin
|
||||
*/
|
||||
private $plugin;
|
||||
|
||||
/**
|
||||
* @var ISystemTagObjectMapper
|
||||
*/
|
||||
private $tagMapper;
|
||||
private \Sabre\DAV\Server $server;
|
||||
private \Sabre\DAV\Tree&MockObject $tree;
|
||||
private ISystemTagManager&MockObject $tagManager;
|
||||
private IGroupManager&MockObject $groupManager;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IRootFolder&MockObject $rootFolder;
|
||||
private IUser&MockObject $user;
|
||||
private ISystemTagObjectMapper&MockObject $tagMapper;
|
||||
private SystemTagPlugin $plugin;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->tree = $this->getMockBuilder(Tree::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->tree = $this->createMock(Tree::class);
|
||||
|
||||
$this->server = new \Sabre\DAV\Server($this->tree);
|
||||
|
||||
$this->tagManager = $this->getMockBuilder(ISystemTagManager::class)
|
||||
->getMock();
|
||||
$this->groupManager = $this->getMockBuilder(IGroupManager::class)
|
||||
->getMock();
|
||||
$this->user = $this->getMockBuilder(IUser::class)
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->getMock();
|
||||
$this->tagManager = $this->createMock(ISystemTagManager::class);
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->user = $this->createMock(IUser::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$this->userSession
|
||||
->expects($this->any())
|
||||
->method('getUser')
|
||||
|
|
@ -102,10 +63,8 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
->method('isLoggedIn')
|
||||
->willReturn(true);
|
||||
|
||||
$this->tagMapper = $this->getMockBuilder(ISystemTagObjectMapper::class)
|
||||
->getMock();
|
||||
$this->rootFolder = $this->getMockBuilder(IRootFolder::class)
|
||||
->getMock();
|
||||
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
|
||||
$this->rootFolder = $this->createMock(IRootFolder::class);
|
||||
|
||||
$this->plugin = new SystemTagPlugin(
|
||||
$this->tagManager,
|
||||
|
|
@ -117,10 +76,10 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
$this->plugin->initialize($this->server);
|
||||
}
|
||||
|
||||
public function getPropertiesDataProvider() {
|
||||
public static function getPropertiesDataProvider(): array {
|
||||
return [
|
||||
[
|
||||
new SystemTag(1, 'Test', true, true),
|
||||
new SystemTag('1', 'Test', true, true),
|
||||
[],
|
||||
[
|
||||
self::ID_PROPERTYNAME,
|
||||
|
|
@ -138,7 +97,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
new SystemTag(1, 'Test', true, false),
|
||||
new SystemTag('1', 'Test', true, false),
|
||||
[],
|
||||
[
|
||||
self::ID_PROPERTYNAME,
|
||||
|
|
@ -156,7 +115,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
new SystemTag(1, 'Test', true, false),
|
||||
new SystemTag('1', 'Test', true, false),
|
||||
['group1', 'group2'],
|
||||
[
|
||||
self::ID_PROPERTYNAME,
|
||||
|
|
@ -168,7 +127,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
]
|
||||
],
|
||||
[
|
||||
new SystemTag(1, 'Test', true, true),
|
||||
new SystemTag('1', 'Test', true, true),
|
||||
['group1', 'group2'],
|
||||
[
|
||||
self::ID_PROPERTYNAME,
|
||||
|
|
@ -186,7 +145,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider getPropertiesDataProvider
|
||||
*/
|
||||
public function testGetProperties(ISystemTag $systemTag, $groups, $requestedProperties, $expectedProperties): void {
|
||||
public function testGetProperties(ISystemTag $systemTag, array $groups, array $requestedProperties, array $expectedProperties): void {
|
||||
$this->user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
|
|
@ -237,7 +196,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
public function testGetPropertiesForbidden(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
||||
|
||||
$systemTag = new SystemTag(1, 'Test', true, false);
|
||||
$systemTag = new SystemTag('1', 'Test', true, false);
|
||||
$requestedProperties = [
|
||||
self::ID_PROPERTYNAME,
|
||||
self::GROUPS_PROPERTYNAME,
|
||||
|
|
@ -276,7 +235,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testUpdatePropertiesAdmin(): void {
|
||||
$systemTag = new SystemTag(1, 'Test', true, false);
|
||||
$systemTag = new SystemTag('1', 'Test', true, false);
|
||||
$this->user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
|
|
@ -334,7 +293,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
public function testUpdatePropertiesForbidden(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
||||
|
||||
$systemTag = new SystemTag(1, 'Test', true, false);
|
||||
$systemTag = new SystemTag('1', 'Test', true, false);
|
||||
$this->user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
|
|
@ -375,7 +334,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
$propPatch->commit();
|
||||
}
|
||||
|
||||
public function createTagInsufficientPermissionsProvider() {
|
||||
public static function createTagInsufficientPermissionsProvider(): array {
|
||||
return [
|
||||
[true, false, ''],
|
||||
[false, true, ''],
|
||||
|
|
@ -385,7 +344,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider createTagInsufficientPermissionsProvider
|
||||
*/
|
||||
public function testCreateNotAssignableTagAsRegularUser($userVisible, $userAssignable, $groups): void {
|
||||
public function testCreateNotAssignableTagAsRegularUser(bool $userVisible, bool $userAssignable, string $groups): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
|
||||
$this->expectExceptionMessage('Not sufficient permissions');
|
||||
|
||||
|
|
@ -408,9 +367,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
}
|
||||
$requestData = json_encode($requestData);
|
||||
|
||||
$node = $this->getMockBuilder(SystemTagsByIdCollection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$node = $this->createMock(SystemTagsByIdCollection::class);
|
||||
$this->tagManager->expects($this->never())
|
||||
->method('createTag');
|
||||
$this->tagManager->expects($this->never())
|
||||
|
|
@ -421,12 +378,8 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
->with('/systemtags')
|
||||
->willReturn($node);
|
||||
|
||||
$request = $this->getMockBuilder(RequestInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$response = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$request = $this->createMock(RequestInterface::class);
|
||||
$response = $this->createMock(ResponseInterface::class);
|
||||
|
||||
$request->expects($this->once())
|
||||
->method('getPath')
|
||||
|
|
@ -445,7 +398,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testCreateTagInByIdCollectionAsRegularUser(): void {
|
||||
$systemTag = new SystemTag(1, 'Test', true, false);
|
||||
$systemTag = new SystemTag('1', 'Test', true, false);
|
||||
|
||||
$requestData = json_encode([
|
||||
'name' => 'Test',
|
||||
|
|
@ -453,9 +406,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
'userAssignable' => true,
|
||||
]);
|
||||
|
||||
$node = $this->getMockBuilder(SystemTagsByIdCollection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$node = $this->createMock(SystemTagsByIdCollection::class);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('createTag')
|
||||
->with('Test', true, true)
|
||||
|
|
@ -466,12 +417,8 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
->with('/systemtags')
|
||||
->willReturn($node);
|
||||
|
||||
$request = $this->getMockBuilder(RequestInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$response = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$request = $this->createMock(RequestInterface::class);
|
||||
$response = $this->createMock(ResponseInterface::class);
|
||||
|
||||
$request->expects($this->once())
|
||||
->method('getPath')
|
||||
|
|
@ -497,7 +444,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
$this->plugin->httpPost($request, $response);
|
||||
}
|
||||
|
||||
public function createTagProvider() {
|
||||
public static function createTagProvider(): array {
|
||||
return [
|
||||
[true, false, ''],
|
||||
[false, false, ''],
|
||||
|
|
@ -508,7 +455,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider createTagProvider
|
||||
*/
|
||||
public function testCreateTagInByIdCollection($userVisible, $userAssignable, $groups): void {
|
||||
public function testCreateTagInByIdCollection(bool $userVisible, bool $userAssignable, string $groups): void {
|
||||
$this->user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn('admin');
|
||||
|
|
@ -518,7 +465,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
->with('admin')
|
||||
->willReturn(true);
|
||||
|
||||
$systemTag = new SystemTag(1, 'Test', true, false);
|
||||
$systemTag = new SystemTag('1', 'Test', true, false);
|
||||
|
||||
$requestData = [
|
||||
'name' => 'Test',
|
||||
|
|
@ -530,9 +477,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
}
|
||||
$requestData = json_encode($requestData);
|
||||
|
||||
$node = $this->getMockBuilder(SystemTagsByIdCollection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$node = $this->createMock(SystemTagsByIdCollection::class);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('createTag')
|
||||
->with('Test', $userVisible, $userAssignable)
|
||||
|
|
@ -553,12 +498,8 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
->with('/systemtags')
|
||||
->willReturn($node);
|
||||
|
||||
$request = $this->getMockBuilder(RequestInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$response = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$request = $this->createMock(RequestInterface::class);
|
||||
$response = $this->createMock(ResponseInterface::class);
|
||||
|
||||
$request->expects($this->once())
|
||||
->method('getPath')
|
||||
|
|
@ -584,7 +525,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
$this->plugin->httpPost($request, $response);
|
||||
}
|
||||
|
||||
public function nodeClassProvider() {
|
||||
public static function nodeClassProvider(): array {
|
||||
return [
|
||||
['\OCA\DAV\SystemTag\SystemTagsByIdCollection'],
|
||||
['\OCA\DAV\SystemTag\SystemTagsObjectMappingCollection'],
|
||||
|
|
@ -601,7 +542,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
->with('admin')
|
||||
->willReturn(true);
|
||||
|
||||
$systemTag = new SystemTag(1, 'Test', true, false);
|
||||
$systemTag = new SystemTag('1', 'Test', true, false);
|
||||
|
||||
$requestData = json_encode([
|
||||
'name' => 'Test',
|
||||
|
|
@ -609,9 +550,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
'userAssignable' => false,
|
||||
]);
|
||||
|
||||
$node = $this->getMockBuilder(SystemTagsObjectMappingCollection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$node = $this->createMock(SystemTagsObjectMappingCollection::class);
|
||||
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('createTag')
|
||||
|
|
@ -627,12 +566,8 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
->method('createFile')
|
||||
->with(1);
|
||||
|
||||
$request = $this->getMockBuilder(RequestInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$response = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$request = $this->createMock(RequestInterface::class);
|
||||
$response = $this->createMock(ResponseInterface::class);
|
||||
|
||||
$request->expects($this->once())
|
||||
->method('getPath')
|
||||
|
|
@ -662,9 +597,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
public function testCreateTagToUnknownNode(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
||||
|
||||
$node = $this->getMockBuilder(SystemTagsObjectMappingCollection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$node = $this->createMock(SystemTagsObjectMappingCollection::class);
|
||||
|
||||
$this->tree->expects($this->any())
|
||||
->method('getNodeForPath')
|
||||
|
|
@ -676,12 +609,8 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
$node->expects($this->never())
|
||||
->method('createFile');
|
||||
|
||||
$request = $this->getMockBuilder(RequestInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$response = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$request = $this->createMock(RequestInterface::class);
|
||||
$response = $this->createMock(ResponseInterface::class);
|
||||
|
||||
$request->expects($this->once())
|
||||
->method('getPath')
|
||||
|
|
@ -693,7 +622,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider nodeClassProvider
|
||||
*/
|
||||
public function testCreateTagConflict($nodeClass): void {
|
||||
public function testCreateTagConflict(string $nodeClass): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Conflict::class);
|
||||
|
||||
$this->user->expects($this->once())
|
||||
|
|
@ -711,9 +640,7 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
'userAssignable' => false,
|
||||
]);
|
||||
|
||||
$node = $this->getMockBuilder($nodeClass)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$node = $this->createMock($nodeClass);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('createTag')
|
||||
->with('Test', true, false)
|
||||
|
|
@ -724,12 +651,8 @@ class SystemTagPluginTest extends \Test\TestCase {
|
|||
->with('/systemtags')
|
||||
->willReturn($node);
|
||||
|
||||
$request = $this->getMockBuilder(RequestInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$response = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$request = $this->createMock(RequestInterface::class);
|
||||
$response = $this->createMock(ResponseInterface::class);
|
||||
|
||||
$request->expects($this->once())
|
||||
->method('getPath')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -18,50 +19,36 @@ use OCP\SystemTag\TagNotFoundException;
|
|||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
||||
|
||||
/**
|
||||
* @var ISystemTagManager
|
||||
*/
|
||||
private $tagManager;
|
||||
|
||||
/**
|
||||
* @var IUser
|
||||
*/
|
||||
private $user;
|
||||
private ISystemTagManager&MockObject $tagManager;
|
||||
private IUser&MockObject $user;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->tagManager = $this->getMockBuilder(ISystemTagManager::class)
|
||||
->getMock();
|
||||
$this->tagManager = $this->createMock(ISystemTagManager::class);
|
||||
}
|
||||
|
||||
public function getNode($isAdmin = true) {
|
||||
$this->user = $this->getMockBuilder(IUser::class)
|
||||
->getMock();
|
||||
public function getNode(bool $isAdmin = true) {
|
||||
$this->user = $this->createMock(IUser::class);
|
||||
$this->user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('testuser');
|
||||
|
||||
/** @var IUserSession|MockObject */
|
||||
$userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->getMock();
|
||||
/** @var IUserSession&MockObject */
|
||||
$userSession = $this->createMock(IUserSession::class);
|
||||
$userSession->expects($this->any())
|
||||
->method('getUser')
|
||||
->willReturn($this->user);
|
||||
|
||||
/** @var IGroupManager|MockObject */
|
||||
$groupManager = $this->getMockBuilder(IGroupManager::class)
|
||||
->getMock();
|
||||
/** @var IGroupManager&MockObject */
|
||||
$groupManager = $this->createMock(IGroupManager::class);
|
||||
$groupManager->expects($this->any())
|
||||
->method('isAdmin')
|
||||
->with('testuser')
|
||||
->willReturn($isAdmin);
|
||||
|
||||
/** @var ISystemTagObjectMapper|MockObject */
|
||||
$tagMapper = $this->getMockBuilder(ISystemTagObjectMapper::class)
|
||||
->getMock();
|
||||
|
||||
/** @var ISystemTagObjectMapper&MockObject */
|
||||
$tagMapper = $this->createMock(ISystemTagObjectMapper::class);
|
||||
return new SystemTagsByIdCollection(
|
||||
$this->tagManager,
|
||||
$userSession,
|
||||
|
|
@ -70,18 +57,18 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function adminFlagProvider() {
|
||||
public static function adminFlagProvider(): array {
|
||||
return [[true], [false]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testForbiddenCreateFile(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
||||
|
||||
$this->getNode()->createFile('555');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testForbiddenCreateDirectory(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
||||
|
||||
|
|
@ -89,7 +76,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetChild(): void {
|
||||
$tag = new SystemTag(123, 'Test', true, false);
|
||||
$tag = new SystemTag('123', 'Test', true, false);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
@ -107,7 +94,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
$this->assertEquals($tag, $childNode->getSystemTag());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testGetChildInvalidName(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
|
||||
|
||||
|
|
@ -119,7 +106,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
$this->getNode()->getChild('invalid');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testGetChildNotFound(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
||||
|
||||
|
|
@ -131,11 +118,11 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
$this->getNode()->getChild('444');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testGetChildUserNotVisible(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
||||
|
||||
$tag = new SystemTag(123, 'Test', false, false);
|
||||
$tag = new SystemTag('123', 'Test', false, false);
|
||||
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('getTagsByIds')
|
||||
|
|
@ -146,8 +133,8 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetChildrenAdmin(): void {
|
||||
$tag1 = new SystemTag(123, 'One', true, false);
|
||||
$tag2 = new SystemTag(456, 'Two', true, true);
|
||||
$tag1 = new SystemTag('123', 'One', true, false);
|
||||
$tag2 = new SystemTag('456', 'Two', true, true);
|
||||
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('getAllTags')
|
||||
|
|
@ -165,8 +152,8 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetChildrenNonAdmin(): void {
|
||||
$tag1 = new SystemTag(123, 'One', true, false);
|
||||
$tag2 = new SystemTag(456, 'Two', true, true);
|
||||
$tag1 = new SystemTag('123', 'One', true, false);
|
||||
$tag2 = new SystemTag('456', 'Two', true, true);
|
||||
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('getAllTags')
|
||||
|
|
@ -191,7 +178,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
$this->assertCount(0, $this->getNode()->getChildren());
|
||||
}
|
||||
|
||||
public function childExistsProvider() {
|
||||
public static function childExistsProvider(): array {
|
||||
return [
|
||||
[true, true],
|
||||
[false, false],
|
||||
|
|
@ -201,8 +188,8 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider childExistsProvider
|
||||
*/
|
||||
public function testChildExists($userVisible, $expectedResult): void {
|
||||
$tag = new SystemTag(123, 'One', $userVisible, false);
|
||||
public function testChildExists(bool $userVisible, bool $expectedResult): void {
|
||||
$tag = new SystemTag('123', 'One', $userVisible, false);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
@ -225,7 +212,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase {
|
|||
$this->assertFalse($this->getNode()->childExists('123'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testChildExistsBadRequest(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -13,27 +14,24 @@ use OCP\IUser;
|
|||
use OCP\SystemTag\ISystemTagManager;
|
||||
use OCP\SystemTag\ISystemTagObjectMapper;
|
||||
use OCP\SystemTag\TagNotFoundException;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
|
||||
private ISystemTagManager $tagManager;
|
||||
private ISystemTagObjectMapper $tagMapper;
|
||||
private IUser $user;
|
||||
private ISystemTagManager&MockObject $tagManager;
|
||||
private ISystemTagObjectMapper&MockObject $tagMapper;
|
||||
private IUser&MockObject $user;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->tagManager = $this->getMockBuilder(ISystemTagManager::class)
|
||||
->getMock();
|
||||
$this->tagMapper = $this->getMockBuilder(ISystemTagObjectMapper::class)
|
||||
->getMock();
|
||||
|
||||
$this->user = $this->getMockBuilder(IUser::class)
|
||||
->getMock();
|
||||
$this->tagManager = $this->createMock(ISystemTagManager::class);
|
||||
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
|
||||
$this->user = $this->createMock(IUser::class);
|
||||
}
|
||||
|
||||
public function getNode(array $writableNodeIds = []) {
|
||||
public function getNode(array $writableNodeIds = []): SystemTagsObjectMappingCollection {
|
||||
return new SystemTagsObjectMappingCollection(
|
||||
111,
|
||||
'111',
|
||||
'files',
|
||||
$this->user,
|
||||
$this->tagManager,
|
||||
|
|
@ -86,7 +84,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
|
|||
$this->getNode()->createFile('555');
|
||||
}
|
||||
|
||||
public function permissionsProvider() {
|
||||
public static function permissionsProvider(): array {
|
||||
return [
|
||||
// invisible, tag does not exist for user
|
||||
[false, true, '\Sabre\DAV\Exception\PreconditionFailed'],
|
||||
|
|
@ -98,7 +96,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider permissionsProvider
|
||||
*/
|
||||
public function testAssignTagNoPermission($userVisible, $userAssignable, $expectedException): void {
|
||||
public function testAssignTagNoPermission(bool $userVisible, bool $userAssignable, string $expectedException): void {
|
||||
$tag = new SystemTag('1', 'Test', $userVisible, $userAssignable);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('canUserSeeTag')
|
||||
|
|
@ -146,7 +144,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetChild(): void {
|
||||
$tag = new SystemTag(555, 'TheTag', true, false);
|
||||
$tag = new SystemTag('555', 'TheTag', true, false);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
@ -172,7 +170,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
|
|||
public function testGetChildNonVisible(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
|
||||
|
||||
$tag = new SystemTag(555, 'TheTag', false, false);
|
||||
$tag = new SystemTag('555', 'TheTag', false, false);
|
||||
$this->tagManager->expects($this->once())
|
||||
->method('canUserSeeTag')
|
||||
->with($tag)
|
||||
|
|
@ -228,9 +226,9 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetChildren(): void {
|
||||
$tag1 = new SystemTag(555, 'TagOne', true, false);
|
||||
$tag2 = new SystemTag(556, 'TagTwo', true, true);
|
||||
$tag3 = new SystemTag(557, 'InvisibleTag', false, true);
|
||||
$tag1 = new SystemTag('555', 'TagOne', true, false);
|
||||
$tag2 = new SystemTag('556', 'TagTwo', true, true);
|
||||
$tag3 = new SystemTag('557', 'InvisibleTag', false, true);
|
||||
|
||||
$this->tagMapper->expects($this->once())
|
||||
->method('getTagIdsForObjects')
|
||||
|
|
@ -265,7 +263,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testChildExistsWithVisibleTag(): void {
|
||||
$tag = new SystemTag(555, 'TagOne', true, false);
|
||||
$tag = new SystemTag('555', 'TagOne', true, false);
|
||||
|
||||
$this->tagMapper->expects($this->once())
|
||||
->method('haveTag')
|
||||
|
|
@ -286,7 +284,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testChildExistsWithInvisibleTag(): void {
|
||||
$tag = new SystemTag(555, 'TagOne', false, false);
|
||||
$tag = new SystemTag('555', 'TagOne', false, false);
|
||||
|
||||
$this->tagMapper->expects($this->once())
|
||||
->method('haveTag')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -15,60 +16,39 @@ use OCP\IUser;
|
|||
use OCP\IUserSession;
|
||||
use OCP\SystemTag\ISystemTagManager;
|
||||
use OCP\SystemTag\ISystemTagObjectMapper;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class SystemTagsObjectTypeCollectionTest extends \Test\TestCase {
|
||||
|
||||
/**
|
||||
* @var SystemTagsObjectTypeCollection
|
||||
*/
|
||||
private $node;
|
||||
|
||||
/**
|
||||
* @var ISystemTagManager
|
||||
*/
|
||||
private $tagManager;
|
||||
|
||||
/**
|
||||
* @var ISystemTagObjectMapper
|
||||
*/
|
||||
private $tagMapper;
|
||||
|
||||
/**
|
||||
* @var Folder
|
||||
*/
|
||||
private $userFolder;
|
||||
private ISystemTagManager&MockObject $tagManager;
|
||||
private ISystemTagObjectMapper&MockObject $tagMapper;
|
||||
private Folder&MockObject $userFolder;
|
||||
private SystemTagsObjectTypeCollection $node;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->tagManager = $this->getMockBuilder(ISystemTagManager::class)
|
||||
->getMock();
|
||||
$this->tagMapper = $this->getMockBuilder(ISystemTagObjectMapper::class)
|
||||
->getMock();
|
||||
$this->tagManager = $this->createMock(ISystemTagManager::class);
|
||||
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
|
||||
|
||||
$user = $this->getMockBuilder(IUser::class)
|
||||
->getMock();
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('testuser');
|
||||
$userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->getMock();
|
||||
$userSession = $this->createMock(IUserSession::class);
|
||||
$userSession->expects($this->any())
|
||||
->method('getUser')
|
||||
->willReturn($user);
|
||||
$groupManager = $this->getMockBuilder(IGroupManager::class)
|
||||
->getMock();
|
||||
$groupManager = $this->createMock(IGroupManager::class);
|
||||
$groupManager->expects($this->any())
|
||||
->method('isAdmin')
|
||||
->with('testuser')
|
||||
->willReturn(true);
|
||||
|
||||
$this->userFolder = $this->getMockBuilder(Folder::class)
|
||||
->getMock();
|
||||
$this->userFolder = $this->createMock(Folder::class);
|
||||
$userFolder = $this->userFolder;
|
||||
|
||||
$closure = function ($name) use ($userFolder) {
|
||||
$node = $userFolder->getFirstNodeById(intval($name));
|
||||
$node = $userFolder->getFirstNodeById((int)$name);
|
||||
return $node !== null;
|
||||
};
|
||||
$writeAccessClosure = function ($name) use ($userFolder) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
|
||||
|
|
@ -10,40 +11,24 @@ namespace OCA\DAV\Tests\unit\Upload;
|
|||
use OCA\DAV\Connector\Sabre\Directory;
|
||||
use OCA\DAV\Upload\ChunkingPlugin;
|
||||
use OCA\DAV\Upload\FutureFile;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Sabre\DAV\Exception\NotFound;
|
||||
use Sabre\HTTP\RequestInterface;
|
||||
use Sabre\HTTP\ResponseInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class ChunkingPluginTest extends TestCase {
|
||||
/**
|
||||
* @var \Sabre\DAV\Server | \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $server;
|
||||
|
||||
/**
|
||||
* @var \Sabre\DAV\Tree | \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $tree;
|
||||
|
||||
/**
|
||||
* @var ChunkingPlugin
|
||||
*/
|
||||
private $plugin;
|
||||
/** @var RequestInterface | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $request;
|
||||
/** @var ResponseInterface | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $response;
|
||||
private \Sabre\DAV\Server&MockObject $server;
|
||||
private \Sabre\DAV\Tree&MockObject $tree;
|
||||
private ChunkingPlugin $plugin;
|
||||
private RequestInterface&MockObject $request;
|
||||
private ResponseInterface&MockObject $response;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->server = $this->getMockBuilder('\Sabre\DAV\Server')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->server = $this->createMock('\Sabre\DAV\Server');
|
||||
$this->tree = $this->createMock('\Sabre\DAV\Tree');
|
||||
|
||||
$this->server->tree = $this->tree;
|
||||
$this->plugin = new ChunkingPlugin();
|
||||
|
|
@ -78,14 +63,10 @@ class ChunkingPluginTest extends TestCase {
|
|||
|
||||
$this->tree->expects($this->exactly(2))
|
||||
->method('getNodeForPath')
|
||||
->withConsecutive(
|
||||
['source'],
|
||||
['target'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$sourceNode,
|
||||
$targetNode,
|
||||
);
|
||||
->willReturnMap([
|
||||
['source', $sourceNode],
|
||||
['target', $targetNode],
|
||||
]);
|
||||
$this->response->expects($this->never())
|
||||
->method('setStatus');
|
||||
|
||||
|
|
@ -98,16 +79,20 @@ class ChunkingPluginTest extends TestCase {
|
|||
->method('getSize')
|
||||
->willReturn(4);
|
||||
|
||||
$calls = [
|
||||
['source', $sourceNode],
|
||||
['target', new NotFound()],
|
||||
];
|
||||
$this->tree->expects($this->exactly(2))
|
||||
->method('getNodeForPath')
|
||||
->withConsecutive(
|
||||
['source'],
|
||||
['target'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$sourceNode,
|
||||
$this->throwException(new NotFound()),
|
||||
);
|
||||
->willReturnCallback(function (string $path) use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertSame($expected[0], $path);
|
||||
if ($expected[1] instanceof \Throwable) {
|
||||
throw $expected[1];
|
||||
}
|
||||
return $expected[1];
|
||||
});
|
||||
$this->tree->expects($this->any())
|
||||
->method('nodeExists')
|
||||
->with('target')
|
||||
|
|
@ -132,17 +117,21 @@ class ChunkingPluginTest extends TestCase {
|
|||
->method('getSize')
|
||||
->willReturn(4);
|
||||
|
||||
|
||||
$calls = [
|
||||
['source', $sourceNode],
|
||||
['target', new NotFound()],
|
||||
];
|
||||
$this->tree->expects($this->exactly(2))
|
||||
->method('getNodeForPath')
|
||||
->withConsecutive(
|
||||
['source'],
|
||||
['target'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$sourceNode,
|
||||
$this->throwException(new NotFound()),
|
||||
);
|
||||
->willReturnCallback(function (string $path) use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertSame($expected[0], $path);
|
||||
if ($expected[1] instanceof \Throwable) {
|
||||
throw $expected[1];
|
||||
}
|
||||
return $expected[1];
|
||||
});
|
||||
|
||||
$this->tree->expects($this->any())
|
||||
->method('nodeExists')
|
||||
->with('target')
|
||||
|
|
@ -175,17 +164,21 @@ class ChunkingPluginTest extends TestCase {
|
|||
->method('getSize')
|
||||
->willReturn(3);
|
||||
|
||||
|
||||
$calls = [
|
||||
['source', $sourceNode],
|
||||
['target', new NotFound()],
|
||||
];
|
||||
$this->tree->expects($this->exactly(2))
|
||||
->method('getNodeForPath')
|
||||
->withConsecutive(
|
||||
['source'],
|
||||
['target'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$sourceNode,
|
||||
$this->throwException(new NotFound()),
|
||||
);
|
||||
->willReturnCallback(function (string $path) use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertSame($expected[0], $path);
|
||||
if ($expected[1] instanceof \Throwable) {
|
||||
throw $expected[1];
|
||||
}
|
||||
return $expected[1];
|
||||
});
|
||||
|
||||
$this->request->expects($this->once())
|
||||
->method('getHeader')
|
||||
->with('OC-Total-Length')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -45,7 +46,7 @@ class FutureFileTest extends \Test\TestCase {
|
|||
public function testDelete(): void {
|
||||
$d = $this->getMockBuilder(Directory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['delete'])
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
|
||||
$d->expects($this->once())
|
||||
|
|
@ -55,7 +56,7 @@ class FutureFileTest extends \Test\TestCase {
|
|||
$f->delete();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testPut(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
||||
|
||||
|
|
@ -63,7 +64,7 @@ class FutureFileTest extends \Test\TestCase {
|
|||
$f->put('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testSetName(): void {
|
||||
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
||||
|
||||
|
|
@ -71,13 +72,10 @@ class FutureFileTest extends \Test\TestCase {
|
|||
$f->setName('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FutureFile
|
||||
*/
|
||||
private function mockFutureFile() {
|
||||
private function mockFutureFile(): FutureFile {
|
||||
$d = $this->getMockBuilder(Directory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getETag', 'getLastModified', 'getChildren'])
|
||||
->onlyMethods(['getETag', 'getLastModified', 'getChildren'])
|
||||
->getMock();
|
||||
|
||||
$d->expects($this->any())
|
||||
|
|
|
|||
Loading…
Reference in a new issue