mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #53235 from nextcloud/test/fix-files-sharing
This commit is contained in:
commit
1eab80f901
5 changed files with 95 additions and 135 deletions
|
|
@ -11,6 +11,7 @@ use OCP\Federation\ICloudId;
|
|||
use OCP\Federation\ICloudIdManager;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Test\TestCase;
|
||||
|
|
@ -24,20 +25,9 @@ use Test\TestCase;
|
|||
*/
|
||||
class CleanupRemoteStoragesTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var CleanupRemoteStorages
|
||||
*/
|
||||
private $command;
|
||||
|
||||
/**
|
||||
* @var IDBConnection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $cloudIdManager;
|
||||
protected IDBConnection $connection;
|
||||
protected CleanupRemoteStorages $command;
|
||||
private ICloudIdManager&MockObject $cloudIdManager;
|
||||
|
||||
private $storages = [
|
||||
['id' => 'shared::7b4a322b22f9d0047c38d77d471ce3cf', 'share_token' => 'f2c69dad1dc0649f26976fd210fc62e1', 'remote' => 'https://hostname.tld/owncloud1', 'user' => 'user1'],
|
||||
|
|
@ -77,7 +67,7 @@ class CleanupRemoteStoragesTest extends TestCase {
|
|||
foreach ($this->storages as &$storage) {
|
||||
if (isset($storage['id'])) {
|
||||
$storageQuery->setParameter('id', $storage['id']);
|
||||
$storageQuery->execute();
|
||||
$storageQuery->executeStatement();
|
||||
$storage['numeric_id'] = $storageQuery->getLastInsertId();
|
||||
}
|
||||
|
||||
|
|
@ -121,13 +111,13 @@ class CleanupRemoteStoragesTest extends TestCase {
|
|||
foreach ($this->storages as $storage) {
|
||||
if (isset($storage['id'])) {
|
||||
$storageQuery->setParameter('id', $storage['id']);
|
||||
$storageQuery->execute();
|
||||
$storageQuery->executeStatement();
|
||||
}
|
||||
|
||||
if (isset($storage['share_token'])) {
|
||||
$shareExternalQuery->setParameter('share_token', $storage['share_token']);
|
||||
$shareExternalQuery->setParameter('remote', $storage['remote']);
|
||||
$shareExternalQuery->execute();
|
||||
$shareExternalQuery->executeStatement();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -174,14 +164,13 @@ class CleanupRemoteStoragesTest extends TestCase {
|
|||
->getMock();
|
||||
|
||||
// parent folder, `files`, ´test` and `welcome.txt` => 4 elements
|
||||
|
||||
$outputCalls = [];
|
||||
$output
|
||||
->expects($this->any())
|
||||
->method('writeln')
|
||||
->withConsecutive(
|
||||
['5 remote storage(s) need(s) to be checked'],
|
||||
['5 remote share(s) exist'],
|
||||
);
|
||||
->willReturnCallback(function (string $text) use (&$outputCalls) {
|
||||
$outputCalls[] = $text;
|
||||
});
|
||||
|
||||
$this->cloudIdManager
|
||||
->expects($this->any())
|
||||
|
|
@ -206,5 +195,10 @@ class CleanupRemoteStoragesTest extends TestCase {
|
|||
$this->assertFalse($this->doesStorageExist($this->storages[3]['numeric_id']));
|
||||
$this->assertTrue($this->doesStorageExist($this->storages[4]['numeric_id']));
|
||||
$this->assertFalse($this->doesStorageExist($this->storages[5]['numeric_id']));
|
||||
|
||||
$this->assertEquals([
|
||||
'5 remote storage(s) need(s) to be checked',
|
||||
'5 remote share(s) exist',
|
||||
], array_slice($outputCalls, 0, 2));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1675,8 +1675,11 @@ class ShareAPIControllerTest extends TestCase {
|
|||
->with('spreed')
|
||||
->willReturn(true);
|
||||
|
||||
$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
|
||||
->setMethods(['canAccessShare'])
|
||||
// This is not possible anymore with PHPUnit 10+
|
||||
// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
|
||||
// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
|
||||
$helper = $this->getMockBuilder(\stdClass::class)
|
||||
->addMethods(['canAccessShare'])
|
||||
->getMock();
|
||||
$helper->method('canAccessShare')
|
||||
->with($share, $this->currentUser)
|
||||
|
|
@ -2492,8 +2495,11 @@ class ShareAPIControllerTest extends TestCase {
|
|||
->with('spreed')
|
||||
->willReturn(true);
|
||||
|
||||
$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
|
||||
->setMethods(['createShare'])
|
||||
// This is not possible anymore with PHPUnit 10+
|
||||
// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
|
||||
// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
|
||||
$helper = $this->getMockBuilder(\stdClass::class)
|
||||
->addMethods(['createShare'])
|
||||
->getMock();
|
||||
$helper->method('createShare')
|
||||
->with(
|
||||
|
|
@ -2598,7 +2604,10 @@ class ShareAPIControllerTest extends TestCase {
|
|||
->with('spreed')
|
||||
->willReturn(true);
|
||||
|
||||
$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
|
||||
// This is not possible anymore with PHPUnit 10+
|
||||
// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
|
||||
// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
|
||||
$helper = $this->getMockBuilder(\stdClass::class)
|
||||
->addMethods(['createShare'])
|
||||
->getMock();
|
||||
$helper->method('createShare')
|
||||
|
|
@ -5093,8 +5102,11 @@ class ShareAPIControllerTest extends TestCase {
|
|||
->with('spreed')
|
||||
->willReturn(true);
|
||||
|
||||
$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
|
||||
->setMethods(['formatShare', 'canAccessShare'])
|
||||
// This is not possible anymore with PHPUnit 10+
|
||||
// as `setMethods` was removed and now real reflection is used, thus the class needs to exist.
|
||||
// $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
|
||||
$helper = $this->getMockBuilder(\stdClass::class)
|
||||
->addMethods(['formatShare', 'canAccessShare'])
|
||||
->getMock();
|
||||
$helper->method('formatShare')
|
||||
->with($share)
|
||||
|
|
|
|||
|
|
@ -15,15 +15,13 @@ use OCP\IRequest;
|
|||
use OCP\Share\Exceptions\ShareNotFound;
|
||||
use OCP\Share\IManager as ShareManager;
|
||||
use OCP\Share\IShare;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ShareInfoControllerTest extends TestCase {
|
||||
|
||||
/** @var ShareInfoController */
|
||||
private $controller;
|
||||
|
||||
/** @var ShareManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $shareManager;
|
||||
protected ShareInfoController $controller;
|
||||
protected ShareManager&MockObject $shareManager;
|
||||
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
@ -31,14 +29,11 @@ class ShareInfoControllerTest extends TestCase {
|
|||
|
||||
$this->shareManager = $this->createMock(ShareManager::class);
|
||||
|
||||
$this->controller = $this->getMockBuilder(ShareInfoController::class)
|
||||
->setConstructorArgs([
|
||||
'files_sharing',
|
||||
$this->createMock(IRequest::class),
|
||||
$this->shareManager
|
||||
])
|
||||
->setMethods(['addROWrapper'])
|
||||
->getMock();
|
||||
$this->controller = new ShareInfoController(
|
||||
'files_sharing',
|
||||
$this->createMock(IRequest::class),
|
||||
$this->shareManager
|
||||
);
|
||||
}
|
||||
|
||||
public function testNoShare(): void {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use OCP\IUserSession;
|
|||
use OCP\OCS\IDiscoveryService;
|
||||
use OCP\Server;
|
||||
use OCP\Share\IShare;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\Traits\UserTrait;
|
||||
|
||||
|
|
@ -46,42 +47,19 @@ use Test\Traits\UserTrait;
|
|||
class ManagerTest extends TestCase {
|
||||
use UserTrait;
|
||||
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $contactsManager;
|
||||
|
||||
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject * */
|
||||
private $manager;
|
||||
|
||||
/** @var \OC\Files\Mount\Manager */
|
||||
private $mountManager;
|
||||
|
||||
/** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $clientService;
|
||||
|
||||
/** @var ICloudFederationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cloudFederationProviderManager;
|
||||
|
||||
/** @var ICloudFederationFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cloudFederationFactory;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
private $uid;
|
||||
|
||||
/**
|
||||
* @var IUser
|
||||
*/
|
||||
private $user;
|
||||
private $testMountProvider;
|
||||
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $eventDispatcher;
|
||||
protected string $uid;
|
||||
protected IUser $user;
|
||||
protected MountProvider $testMountProvider;
|
||||
protected IEventDispatcher&MockObject $eventDispatcher;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
protected \OC\Files\Mount\Manager $mountManager;
|
||||
protected IManager&MockObject $contactsManager;
|
||||
protected Manager&MockObject $manager;
|
||||
protected IClientService&MockObject $clientService;
|
||||
protected ICloudFederationProviderManager&MockObject $cloudFederationProviderManager;
|
||||
protected ICloudFederationFactory&MockObject $cloudFederationFactory;
|
||||
protected IGroupManager&MockObject $groupManager;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -169,7 +147,7 @@ class ManagerTest extends TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->logger,
|
||||
]
|
||||
)->setMethods(['tryOCMEndPoint'])->getMock();
|
||||
)->onlyMethods(['tryOCMEndPoint'])->getMock();
|
||||
}
|
||||
|
||||
private function setupMounts() {
|
||||
|
|
@ -222,14 +200,12 @@ class ManagerTest extends TestCase {
|
|||
if ($isGroup) {
|
||||
$this->manager->expects($this->never())->method('tryOCMEndPoint');
|
||||
} else {
|
||||
$this->manager->method('tryOCMEndPoint')
|
||||
->withConsecutive(
|
||||
['http://localhost', 'token1', '2342', 'accept'],
|
||||
['http://localhost', 'token3', '2342', 'decline'],
|
||||
)->willReturnOnConsecutiveCalls(
|
||||
false,
|
||||
false,
|
||||
);
|
||||
$this->manager->expects(self::atLeast(2))
|
||||
->method('tryOCMEndPoint')
|
||||
->willReturnMap([
|
||||
['http://localhost', 'token1', '2342', 'accept', false],
|
||||
['http://localhost', 'token3', '2342', 'decline', false],
|
||||
]);
|
||||
}
|
||||
|
||||
// Add a share for "user"
|
||||
|
|
|
|||
|
|
@ -20,29 +20,21 @@ use OCP\IUserManager;
|
|||
use OCP\Share\IAttributes as IShareAttributes;
|
||||
use OCP\Share\IManager;
|
||||
use OCP\Share\IShare;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
*/
|
||||
class MountProviderTest extends \Test\TestCase {
|
||||
/** @var MountProvider */
|
||||
private $provider;
|
||||
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
protected MountProvider $provider;
|
||||
|
||||
/** @var IUser|MockObject */
|
||||
private $user;
|
||||
|
||||
/** @var IStorageFactory|MockObject */
|
||||
private $loader;
|
||||
|
||||
/** @var IManager|MockObject */
|
||||
private $shareManager;
|
||||
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
protected IUser&MockObject $user;
|
||||
protected IConfig&MockObject $config;
|
||||
protected IManager&MockObject $shareManager;
|
||||
protected IStorageFactory&MockObject $loader;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -144,38 +136,34 @@ class MountProviderTest extends \Test\TestCase {
|
|||
];
|
||||
// tests regarding circles and sciencemesh are made in the apps themselves.
|
||||
$circleShares = [];
|
||||
$sciencemeshShares = [];
|
||||
$scienceMeshShares = [];
|
||||
$this->user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('user1');
|
||||
$this->shareManager->expects($this->exactly(6))
|
||||
->method('getSharedWith')
|
||||
->withConsecutive(
|
||||
['user1', IShare::TYPE_USER],
|
||||
['user1', IShare::TYPE_GROUP, null, -1],
|
||||
['user1', IShare::TYPE_CIRCLE, null, -1],
|
||||
['user1', IShare::TYPE_ROOM, null, -1],
|
||||
['user1', IShare::TYPE_DECK, null, -1],
|
||||
['user1', IShare::TYPE_SCIENCEMESH, null, -1],
|
||||
)->willReturnOnConsecutiveCalls(
|
||||
$userShares,
|
||||
$groupShares,
|
||||
$circleShares,
|
||||
$roomShares,
|
||||
$deckShares,
|
||||
$sciencemeshShares
|
||||
);
|
||||
->willReturnMap([
|
||||
['user1', IShare::TYPE_USER, null, -1, 0, $userShares],
|
||||
['user1', IShare::TYPE_GROUP, null, -1, 0, $groupShares],
|
||||
['user1', IShare::TYPE_CIRCLE, null, -1, 0, $circleShares],
|
||||
['user1', IShare::TYPE_ROOM, null, -1, 0, $roomShares],
|
||||
['user1', IShare::TYPE_DECK, null, -1, 0, $deckShares],
|
||||
['user1', IShare::TYPE_SCIENCEMESH, null, -1, 0, $scienceMeshShares],
|
||||
]);
|
||||
|
||||
$this->shareManager->expects($this->any())
|
||||
->method('newShare')
|
||||
->willReturnCallback(function () use ($rootFolder, $userManager) {
|
||||
return new Share($rootFolder, $userManager);
|
||||
});
|
||||
|
||||
$mounts = $this->provider->getMountsForUser($this->user, $this->loader);
|
||||
$this->assertCount(4, $mounts);
|
||||
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[0]);
|
||||
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[1]);
|
||||
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[2]);
|
||||
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[3]);
|
||||
/** @var OCA\Files_Sharing\SharedMount[] $mounts */
|
||||
$mountedShare1 = $mounts[0]->getShare();
|
||||
$this->assertEquals('2', $mountedShare1->getId());
|
||||
$this->assertEquals('user2', $mountedShare1->getShareOwner());
|
||||
|
|
@ -204,7 +192,7 @@ class MountProviderTest extends \Test\TestCase {
|
|||
$this->assertEquals(31, $mountedShare4->getPermissions());
|
||||
}
|
||||
|
||||
public function mergeSharesDataProvider() {
|
||||
public static function mergeSharesDataProvider(): array {
|
||||
// note: the user in the specs here is the shareOwner not recipient
|
||||
// the recipient is always "user1"
|
||||
return [
|
||||
|
|
@ -368,24 +356,18 @@ class MountProviderTest extends \Test\TestCase {
|
|||
$circleShares = [];
|
||||
$roomShares = [];
|
||||
$deckShares = [];
|
||||
$sciencemeshShares = [];
|
||||
$scienceMeshShares = [];
|
||||
$this->shareManager->expects($this->exactly(6))
|
||||
->method('getSharedWith')
|
||||
->withConsecutive(
|
||||
['user1', IShare::TYPE_USER],
|
||||
['user1', IShare::TYPE_GROUP, null, -1],
|
||||
['user1', IShare::TYPE_CIRCLE, null, -1],
|
||||
['user1', IShare::TYPE_ROOM, null, -1],
|
||||
['user1', IShare::TYPE_DECK, null, -1],
|
||||
['user1', IShare::TYPE_SCIENCEMESH, null, -1],
|
||||
)->willReturnOnConsecutiveCalls(
|
||||
$userShares,
|
||||
$groupShares,
|
||||
$circleShares,
|
||||
$roomShares,
|
||||
$deckShares,
|
||||
$sciencemeshShares
|
||||
);
|
||||
->willReturnMap([
|
||||
['user1', IShare::TYPE_USER, null, -1, 0, $userShares],
|
||||
['user1', IShare::TYPE_GROUP, null, -1, 0, $groupShares],
|
||||
['user1', IShare::TYPE_CIRCLE, null, -1, 0, $circleShares],
|
||||
['user1', IShare::TYPE_ROOM, null, -1, 0, $roomShares],
|
||||
['user1', IShare::TYPE_DECK, null, -1, 0, $deckShares],
|
||||
['user1', IShare::TYPE_SCIENCEMESH, null, -1, 0, $scienceMeshShares],
|
||||
]);
|
||||
|
||||
$this->shareManager->expects($this->any())
|
||||
->method('newShare')
|
||||
->willReturnCallback(function () use ($rootFolder, $userManager) {
|
||||
|
|
@ -407,6 +389,7 @@ class MountProviderTest extends \Test\TestCase {
|
|||
$this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mount);
|
||||
|
||||
// supershare
|
||||
/** @var OCA\Files_Sharing\SharedMount $mount */
|
||||
$share = $mount->getShare();
|
||||
|
||||
$this->assertEquals($expectedShare[0], $share->getId());
|
||||
|
|
|
|||
Loading…
Reference in a new issue