mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #54905 from nextcloud/fix/show-phpunit-warnings
This commit is contained in:
commit
ef336fe809
30 changed files with 1430 additions and 1323 deletions
|
|
@ -63,6 +63,13 @@ class CalendarFederationProvider implements ICloudFederationProvider {
|
|||
}
|
||||
|
||||
$rawProtocol = $share->getProtocol();
|
||||
if (!isset($rawProtocol[ICalendarFederationProtocol::PROP_VERSION])) {
|
||||
throw new ProviderCouldNotAddShareException(
|
||||
'No protocol version',
|
||||
'',
|
||||
Http::STATUS_BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
switch ($rawProtocol[ICalendarFederationProtocol::PROP_VERSION]) {
|
||||
case CalendarFederationProtocolV1::VERSION:
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ class FederationSharingService {
|
|||
*/
|
||||
private function decodeRemoteUserPrincipal(string $principal): ?string {
|
||||
// Expected format: principals/remote-users/abcdef123
|
||||
[$prefix, $collection, $encodedId] = explode('/', $principal);
|
||||
if ($prefix !== 'principals' || $collection !== 'remote-users') {
|
||||
if (!str_starts_with($principal, 'principals/remote-users/')) {
|
||||
return null;
|
||||
}
|
||||
$encodedId = substr($principal, strlen('principals/remote-users/'));
|
||||
|
||||
$decodedId = base64_decode($encodedId);
|
||||
if (!is_string($decodedId)) {
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ class CalendarFederationProviderTest extends TestCase {
|
|||
->method('add');
|
||||
|
||||
$this->expectException(ProviderCouldNotAddShareException::class);
|
||||
$this->expectExceptionMessage('Unknown protocol version');
|
||||
$this->expectExceptionMessage('No protocol version');
|
||||
$this->expectExceptionCode(400);
|
||||
$this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class UserEventsListenerTest extends TestCase {
|
|||
private ExampleContactService&MockObject $exampleContactService;
|
||||
private ExampleEventService&MockObject $exampleEventService;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private IJobList&MockObject $jobList;
|
||||
|
||||
private UserEventsListener $userEventsListener;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,11 +20,29 @@ use Sabre\HTTP\ResponseInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class UploadAutoMkcolPluginTest extends TestCase {
|
||||
|
||||
private Tree&MockObject $tree;
|
||||
private RequestInterface&MockObject $request;
|
||||
private ResponseInterface&MockObject $response;
|
||||
|
||||
private UploadAutoMkcolPlugin $plugin;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$server = $this->createMock(Server::class);
|
||||
$this->tree = $this->createMock(Tree::class);
|
||||
|
||||
$server->tree = $this->tree;
|
||||
$this->plugin = new UploadAutoMkcolPlugin();
|
||||
|
||||
$this->request = $this->createMock(RequestInterface::class);
|
||||
$this->response = $this->createMock(ResponseInterface::class);
|
||||
$server->httpRequest = $this->request;
|
||||
$server->httpResponse = $this->response;
|
||||
|
||||
$this->plugin->initialize($server);
|
||||
}
|
||||
|
||||
public static function dataMissingHeaderShouldReturnTrue(): Generator {
|
||||
yield 'missing X-NC-WebDAV-Auto-Mkcol header' => [null];
|
||||
yield 'empty X-NC-WebDAV-Auto-Mkcol header' => [''];
|
||||
|
|
@ -113,21 +131,4 @@ class UploadAutoMkcolPluginTest extends TestCase {
|
|||
$return = $this->plugin->beforeMethod($this->request, $this->response);
|
||||
self::assertTrue($return);
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$server = $this->createMock(Server::class);
|
||||
$this->tree = $this->createMock(Tree::class);
|
||||
|
||||
$server->tree = $this->tree;
|
||||
$this->plugin = new UploadAutoMkcolPlugin();
|
||||
|
||||
$this->request = $this->createMock(RequestInterface::class);
|
||||
$this->response = $this->createMock(ResponseInterface::class);
|
||||
$server->httpRequest = $this->request;
|
||||
$server->httpResponse = $this->response;
|
||||
|
||||
$this->plugin->initialize($server);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,6 +308,12 @@ class ViewControllerTest extends TestCase {
|
|||
}
|
||||
});
|
||||
|
||||
$this->config
|
||||
->method('getUserValue')
|
||||
->willReturnMap([
|
||||
[$this->user->getUID(), 'files', 'files_sorting_configs', '{}', '{}'],
|
||||
]);
|
||||
|
||||
$this->viewController->index('', '', null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,17 +18,15 @@ use OCA\Files_External\Lib\Storage\AmazonS3;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class Amazons3MultiPartTest extends \Test\Files\Storage\Storage {
|
||||
private $config;
|
||||
use ConfigurableStorageTrait;
|
||||
/** @var AmazonS3 */
|
||||
protected $instance;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->config = include('files_external/tests/config.amazons3.php');
|
||||
if (!is_array($this->config) || !$this->config['run']) {
|
||||
$this->markTestSkipped('AmazonS3 backend not configured');
|
||||
}
|
||||
$this->loadConfig('files_external/tests/config.amazons3.php');
|
||||
|
||||
$this->instance = new AmazonS3($this->config + [
|
||||
'putSizeLimit' => 1,
|
||||
'copySizeLimit' => 1,
|
||||
|
|
|
|||
|
|
@ -19,17 +19,14 @@ use OCA\Files_External\Lib\Storage\AmazonS3;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class Amazons3Test extends \Test\Files\Storage\Storage {
|
||||
protected $config;
|
||||
use ConfigurableStorageTrait;
|
||||
/** @var AmazonS3 */
|
||||
protected $instance;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->config = include('files_external/tests/config.amazons3.php');
|
||||
if (!is_array($this->config) || !$this->config['run']) {
|
||||
$this->markTestSkipped('AmazonS3 backend not configured');
|
||||
}
|
||||
$this->loadConfig('files_external/tests/config.amazons3.php');
|
||||
$this->instance = new AmazonS3($this->config);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Tests\Storage;
|
||||
|
||||
trait ConfigurableStorageTrait {
|
||||
protected ?array $config = null;
|
||||
|
||||
protected function loadConfig(string $path): bool {
|
||||
$this->config = null;
|
||||
if (file_exists($path)) {
|
||||
$this->config = include($path);
|
||||
}
|
||||
if (!$this->shouldRunConfig($this->config)) {
|
||||
$this->markTestSkipped(__CLASS__ . ' Backend not configured');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function shouldRunConfig(mixed $config): bool {
|
||||
return is_array($config) && ($config['run'] ?? false);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,16 +18,14 @@ use OCA\Files_External\Lib\Storage\FTP;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class FtpTest extends \Test\Files\Storage\Storage {
|
||||
private $config;
|
||||
use ConfigurableStorageTrait;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$id = $this->getUniqueID();
|
||||
$this->config = include('files_external/tests/config.ftp.php');
|
||||
if (! is_array($this->config) or ! $this->config['run']) {
|
||||
$this->markTestSkipped('FTP backend not configured');
|
||||
}
|
||||
$this->loadConfig('files_external/tests/config.ftp.php');
|
||||
|
||||
$rootInstance = new FTP($this->config);
|
||||
$rootInstance->mkdir($id);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,21 +18,22 @@ use OCA\Files_External\Lib\Storage\OwnCloud;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class OwncloudTest extends \Test\Files\Storage\Storage {
|
||||
private $config;
|
||||
use ConfigurableStorageTrait;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$id = $this->getUniqueID();
|
||||
$this->config = include('files_external/tests/config.php');
|
||||
if (! is_array($this->config) or ! isset($this->config['owncloud']) or ! $this->config['owncloud']['run']) {
|
||||
$this->markTestSkipped('Nextcloud backend not configured');
|
||||
}
|
||||
$this->loadConfig('files_external/tests/config.php');
|
||||
$this->config['owncloud']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
|
||||
$this->instance = new OwnCloud($this->config['owncloud']);
|
||||
$this->instance->mkdir('/');
|
||||
}
|
||||
|
||||
protected function shouldRunConfig(mixed $config): bool {
|
||||
return is_array($config) && ($config['owncloud']['run'] ?? false);
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
if ($this->instance) {
|
||||
$this->instance->rmdir('/');
|
||||
|
|
|
|||
|
|
@ -18,22 +18,23 @@ use OCA\Files_External\Lib\Storage\SFTP_Key;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class SFTP_KeyTest extends \Test\Files\Storage\Storage {
|
||||
private $config;
|
||||
use ConfigurableStorageTrait;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$id = $this->getUniqueID();
|
||||
$this->config = include('files_external/tests/config.php');
|
||||
if (! is_array($this->config) or ! isset($this->config['sftp_key']) or ! $this->config['sftp_key']['run']) {
|
||||
$this->markTestSkipped('SFTP with key backend not configured');
|
||||
}
|
||||
$this->loadConfig('files_external/tests/config.php');
|
||||
// Make sure we have an new empty folder to work in
|
||||
$this->config['sftp_key']['root'] .= '/' . $id;
|
||||
$this->instance = new SFTP_Key($this->config['sftp_key']);
|
||||
$this->instance->mkdir('/');
|
||||
}
|
||||
|
||||
protected function shouldRunConfig(mixed $config): bool {
|
||||
return is_array($config) && ($config['sftp_key']['run'] ?? false);
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
if ($this->instance) {
|
||||
$this->instance->rmdir('/');
|
||||
|
|
|
|||
|
|
@ -18,21 +18,17 @@ use OCA\Files_External\Lib\Storage\SFTP;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class SftpTest extends \Test\Files\Storage\Storage {
|
||||
use ConfigurableStorageTrait;
|
||||
/**
|
||||
* @var SFTP instance
|
||||
*/
|
||||
protected $instance;
|
||||
|
||||
private $config;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$id = $this->getUniqueID();
|
||||
$this->config = include('files_external/tests/config.sftp.php');
|
||||
if (!is_array($this->config) or !$this->config['run']) {
|
||||
$this->markTestSkipped('SFTP backend not configured');
|
||||
}
|
||||
$this->loadConfig('files_external/tests/config.sftp.php');
|
||||
$this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
|
||||
$this->instance = new SFTP($this->config);
|
||||
$this->instance->mkdir('/');
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use PHPUnit\Framework\ExpectationFailedException;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class SmbTest extends \Test\Files\Storage\Storage {
|
||||
use ConfigurableStorageTrait;
|
||||
/**
|
||||
* @var SMB instance
|
||||
*/
|
||||
|
|
@ -31,15 +32,12 @@ class SmbTest extends \Test\Files\Storage\Storage {
|
|||
parent::setUp();
|
||||
|
||||
$id = $this->getUniqueID();
|
||||
$config = include('files_external/tests/config.smb.php');
|
||||
if (!is_array($config) or !$config['run']) {
|
||||
$this->markTestSkipped('Samba backend not configured');
|
||||
$this->loadConfig('files_external/tests/config.smb.php');
|
||||
if (substr($this->config['root'], -1, 1) != '/') {
|
||||
$this->config['root'] .= '/';
|
||||
}
|
||||
if (substr($config['root'], -1, 1) != '/') {
|
||||
$config['root'] .= '/';
|
||||
}
|
||||
$config['root'] .= $id; //make sure we have an new empty folder to work in
|
||||
$this->instance = new SMB($config);
|
||||
$this->config['root'] .= $id; //make sure we have an new empty folder to work in
|
||||
$this->instance = new SMB($this->config);
|
||||
$this->instance->mkdir('/');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use OCA\Files_External\Lib\Storage\Swift;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class SwiftTest extends \Test\Files\Storage\Storage {
|
||||
private $config;
|
||||
use ConfigurableStorageTrait;
|
||||
|
||||
/**
|
||||
* @var Swift instance
|
||||
|
|
@ -29,10 +29,7 @@ class SwiftTest extends \Test\Files\Storage\Storage {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->config = include('files_external/tests/config.swift.php');
|
||||
if (!is_array($this->config) or !$this->config['run']) {
|
||||
$this->markTestSkipped('OpenStack Object Storage backend not configured');
|
||||
}
|
||||
$this->loadConfig('files_external/tests/config.swift.php');
|
||||
$this->instance = new Swift($this->config);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,19 +21,18 @@ use OCP\Server;
|
|||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class WebdavTest extends \Test\Files\Storage\Storage {
|
||||
use ConfigurableStorageTrait;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$id = $this->getUniqueID();
|
||||
$config = include('files_external/tests/config.webdav.php');
|
||||
if (!is_array($config) or !$config['run']) {
|
||||
$this->markTestSkipped('WebDAV backend not configured');
|
||||
$this->loadConfig('files_external/tests/config.webdav.php');
|
||||
if (isset($this->config['wait'])) {
|
||||
$this->waitDelay = $this->config['wait'];
|
||||
}
|
||||
if (isset($config['wait'])) {
|
||||
$this->waitDelay = $config['wait'];
|
||||
}
|
||||
$config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
|
||||
$this->instance = new DAV($config);
|
||||
$this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
|
||||
$this->instance = new DAV($this->config);
|
||||
$this->instance->mkdir('/');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Sharing\Tests;
|
||||
|
||||
use OCA\Files_Sharing\AppInfo\Application;
|
||||
|
|
@ -20,17 +23,15 @@ use OCP\IUser;
|
|||
use OCP\IUserSession;
|
||||
use OCP\Share\IAttributes;
|
||||
use OCP\Share\IShare;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class ApplicationTest extends TestCase {
|
||||
private Application $application;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IRootFolder&MockObject $rootFolder;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -41,54 +42,45 @@ class ApplicationTest extends TestCase {
|
|||
$this->rootFolder = $this->createMock(IRootFolder::class);
|
||||
}
|
||||
|
||||
public function providesDataForCanGet(): array {
|
||||
// normal file (sender) - can download directly
|
||||
$senderFileStorage = $this->createMock(IStorage::class);
|
||||
$senderFileStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(false);
|
||||
$senderFile = $this->createMock(File::class);
|
||||
$senderFile->method('getStorage')->willReturn($senderFileStorage);
|
||||
$senderUserFolder = $this->createMock(Folder::class);
|
||||
$senderUserFolder->method('get')->willReturn($senderFile);
|
||||
|
||||
$result[] = [ '/bar.txt', $senderUserFolder, true ];
|
||||
|
||||
// shared file (receiver) with attribute secure-view-enabled set false -
|
||||
// can download directly
|
||||
$receiverFileShareAttributes = $this->createMock(IAttributes::class);
|
||||
$receiverFileShareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(true);
|
||||
$receiverFileShare = $this->createMock(IShare::class);
|
||||
$receiverFileShare->method('getAttributes')->willReturn($receiverFileShareAttributes);
|
||||
$receiverFileStorage = $this->createMock(SharedStorage::class);
|
||||
$receiverFileStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(true);
|
||||
$receiverFileStorage->method('getShare')->willReturn($receiverFileShare);
|
||||
$receiverFile = $this->createMock(File::class);
|
||||
$receiverFile->method('getStorage')->willReturn($receiverFileStorage);
|
||||
$receiverUserFolder = $this->createMock(Folder::class);
|
||||
$receiverUserFolder->method('get')->willReturn($receiverFile);
|
||||
|
||||
$result[] = [ '/share-bar.txt', $receiverUserFolder, true ];
|
||||
|
||||
// shared file (receiver) with attribute secure-view-enabled set true -
|
||||
// cannot download directly
|
||||
$secureReceiverFileShareAttributes = $this->createMock(IAttributes::class);
|
||||
$secureReceiverFileShareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(false);
|
||||
$secureReceiverFileShare = $this->createMock(IShare::class);
|
||||
$secureReceiverFileShare->method('getAttributes')->willReturn($secureReceiverFileShareAttributes);
|
||||
$secureReceiverFileStorage = $this->createMock(SharedStorage::class);
|
||||
$secureReceiverFileStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(true);
|
||||
$secureReceiverFileStorage->method('getShare')->willReturn($secureReceiverFileShare);
|
||||
$secureReceiverFile = $this->createMock(File::class);
|
||||
$secureReceiverFile->method('getStorage')->willReturn($secureReceiverFileStorage);
|
||||
$secureReceiverUserFolder = $this->createMock(Folder::class);
|
||||
$secureReceiverUserFolder->method('get')->willReturn($secureReceiverFile);
|
||||
|
||||
$result[] = [ '/secure-share-bar.txt', $secureReceiverUserFolder, false ];
|
||||
|
||||
return $result;
|
||||
public static function providesDataForCanGet(): array {
|
||||
return [
|
||||
'normal file (sender)' => [
|
||||
'/bar.txt', IStorage::class, false, null, true
|
||||
],
|
||||
'shared file (receiver) with attribute secure-view-enabled set false' => [
|
||||
'/share-bar.txt', SharedStorage::class, true, true, true
|
||||
],
|
||||
'shared file (receiver) with attribute secure-view-enabled set true' => [
|
||||
'/secure-share-bar.txt', SharedStorage::class, true, false, false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('providesDataForCanGet')]
|
||||
public function testCheckDirectCanBeDownloaded(string $path, Folder $userFolder, bool $run): void {
|
||||
#[DataProvider('providesDataForCanGet')]
|
||||
public function testCheckDirectCanBeDownloaded(
|
||||
string $path,
|
||||
string $storageClass,
|
||||
bool $instanceOfSharedStorage,
|
||||
?bool $storageShareDownloadPermission,
|
||||
bool $canDownloadDirectly,
|
||||
): void {
|
||||
$fileStorage = $this->createMock($storageClass);
|
||||
$fileStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn($instanceOfSharedStorage);
|
||||
if ($storageShareDownloadPermission !== null) {
|
||||
$fileShareAttributes = $this->createMock(IAttributes::class);
|
||||
$fileShareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn($storageShareDownloadPermission);
|
||||
$fileShare = $this->createMock(IShare::class);
|
||||
$fileShare->method('getAttributes')->willReturn($fileShareAttributes);
|
||||
|
||||
$fileStorage->method('getShare')->willReturn($fileShare);
|
||||
}
|
||||
|
||||
$file = $this->createMock(File::class);
|
||||
$file->method('getStorage')->willReturn($fileStorage);
|
||||
|
||||
$userFolder = $this->createMock(Folder::class);
|
||||
$userFolder->method('get')->willReturn($file);
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->method('getUID')->willReturn('test');
|
||||
$this->userSession->method('getUser')->willReturn($user);
|
||||
|
|
@ -103,10 +95,34 @@ class ApplicationTest extends TestCase {
|
|||
);
|
||||
$listener->handle($event);
|
||||
|
||||
$this->assertEquals($run, $event->isSuccessful());
|
||||
$this->assertEquals($canDownloadDirectly, $event->isSuccessful());
|
||||
}
|
||||
|
||||
public function providesDataForCanZip(): array {
|
||||
public static function providesDataForCanZip(): array {
|
||||
return [
|
||||
'can download zipped 2 non-shared files inside non-shared folder' => [
|
||||
'/folder', ['bar1.txt', 'bar2.txt'], 'nonSharedStorage', ['nonSharedStorage','nonSharedStorage'], true
|
||||
],
|
||||
'can download zipped non-shared folder' => [
|
||||
'/', ['folder'], 'nonSharedStorage', ['nonSharedStorage','nonSharedStorage'], true
|
||||
],
|
||||
'cannot download zipped 1 non-shared file and 1 secure-shared inside non-shared folder' => [
|
||||
'/folder', ['secured-bar1.txt', 'bar2.txt'], 'nonSharedStorage', ['nonSharedStorage','secureSharedStorage'], false,
|
||||
],
|
||||
'cannot download zipped secure-shared folder' => [
|
||||
'/', ['secured-folder'], 'secureSharedStorage', [], false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('providesDataForCanZip')]
|
||||
public function testCheckZipCanBeDownloaded(
|
||||
string $dir,
|
||||
array $files,
|
||||
string $folderStorage,
|
||||
array $directoryListing,
|
||||
bool $downloadSuccessful,
|
||||
): void {
|
||||
// Mock: Normal file/folder storage
|
||||
$nonSharedStorage = $this->createMock(IStorage::class);
|
||||
$nonSharedStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(false);
|
||||
|
|
@ -120,54 +136,39 @@ class ApplicationTest extends TestCase {
|
|||
$secureSharedStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(true);
|
||||
$secureSharedStorage->method('getShare')->willReturn($secureReceiverFileShare);
|
||||
|
||||
// 1. can download zipped 2 non-shared files inside non-shared folder
|
||||
// 2. can download zipped non-shared folder
|
||||
$sender1File = $this->createMock(File::class);
|
||||
$sender1File->method('getStorage')->willReturn($nonSharedStorage);
|
||||
$sender1Folder = $this->createMock(Folder::class);
|
||||
$sender1Folder->method('getStorage')->willReturn($nonSharedStorage);
|
||||
$sender1Folder->method('getDirectoryListing')->willReturn([$sender1File, $sender1File]);
|
||||
$sender1RootFolder = $this->createMock(Folder::class);
|
||||
$sender1RootFolder->method('getStorage')->willReturn($nonSharedStorage);
|
||||
$sender1RootFolder->method('getDirectoryListing')->willReturn([$sender1Folder]);
|
||||
$sender1UserFolder = $this->createMock(Folder::class);
|
||||
$sender1UserFolder->method('get')->willReturn($sender1RootFolder);
|
||||
$folder = $this->createMock(Folder::class);
|
||||
if ($folderStorage === 'nonSharedStorage') {
|
||||
$folder->method('getStorage')->willReturn($nonSharedStorage);
|
||||
} elseif ($folderStorage === 'secureSharedStorage') {
|
||||
$folder->method('getStorage')->willReturn($secureSharedStorage);
|
||||
} else {
|
||||
throw new \Exception('Unknown storage ' . $folderStorage);
|
||||
}
|
||||
if (count($directoryListing) > 0) {
|
||||
$directoryListing = array_map(
|
||||
function (string $fileStorage) use ($nonSharedStorage, $secureSharedStorage) {
|
||||
$file = $this->createMock(File::class);
|
||||
if ($fileStorage === 'nonSharedStorage') {
|
||||
$file->method('getStorage')->willReturn($nonSharedStorage);
|
||||
} elseif ($fileStorage === 'secureSharedStorage') {
|
||||
$file->method('getStorage')->willReturn($secureSharedStorage);
|
||||
} else {
|
||||
throw new \Exception('Unknown storage ' . $fileStorage);
|
||||
}
|
||||
return $file;
|
||||
},
|
||||
$directoryListing
|
||||
);
|
||||
$folder->method('getDirectoryListing')->willReturn($directoryListing);
|
||||
}
|
||||
|
||||
$return[] = [ '/folder', ['bar1.txt', 'bar2.txt'], $sender1UserFolder, true ];
|
||||
$return[] = [ '/', ['folder'], $sender1UserFolder, true ];
|
||||
$rootFolder = $this->createMock(Folder::class);
|
||||
$rootFolder->method('getStorage')->willReturn($nonSharedStorage);
|
||||
$rootFolder->method('getDirectoryListing')->willReturn([$folder]);
|
||||
|
||||
// 3. cannot download zipped 1 non-shared file and 1 secure-shared inside non-shared folder
|
||||
$receiver1File = $this->createMock(File::class);
|
||||
$receiver1File->method('getStorage')->willReturn($nonSharedStorage);
|
||||
$receiver1SecureFile = $this->createMock(File::class);
|
||||
$receiver1SecureFile->method('getStorage')->willReturn($secureSharedStorage);
|
||||
$receiver1Folder = $this->createMock(Folder::class);
|
||||
$receiver1Folder->method('getStorage')->willReturn($nonSharedStorage);
|
||||
$receiver1Folder->method('getDirectoryListing')->willReturn([$receiver1File, $receiver1SecureFile]);
|
||||
$receiver1RootFolder = $this->createMock(Folder::class);
|
||||
$receiver1RootFolder->method('getStorage')->willReturn($nonSharedStorage);
|
||||
$receiver1RootFolder->method('getDirectoryListing')->willReturn([$receiver1Folder]);
|
||||
$receiver1UserFolder = $this->createMock(Folder::class);
|
||||
$receiver1UserFolder->method('get')->willReturn($receiver1RootFolder);
|
||||
$userFolder = $this->createMock(Folder::class);
|
||||
$userFolder->method('get')->willReturn($rootFolder);
|
||||
|
||||
$return[] = [ '/folder', ['secured-bar1.txt', 'bar2.txt'], $receiver1UserFolder, false ];
|
||||
|
||||
// 4. cannot download zipped secure-shared folder
|
||||
$receiver2Folder = $this->createMock(Folder::class);
|
||||
$receiver2Folder->method('getStorage')->willReturn($secureSharedStorage);
|
||||
$receiver2RootFolder = $this->createMock(Folder::class);
|
||||
$receiver2RootFolder->method('getStorage')->willReturn($nonSharedStorage);
|
||||
$receiver2RootFolder->method('getDirectoryListing')->willReturn([$receiver2Folder]);
|
||||
$receiver2UserFolder = $this->createMock(Folder::class);
|
||||
$receiver2UserFolder->method('get')->willReturn($receiver2RootFolder);
|
||||
|
||||
$return[] = [ '/', ['secured-folder'], $receiver2UserFolder, false ];
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('providesDataForCanZip')]
|
||||
public function testCheckZipCanBeDownloaded(string $dir, array $files, Folder $userFolder, bool $run): void {
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->method('getUID')->willReturn('test');
|
||||
$this->userSession->method('getUser')->willReturn($user);
|
||||
|
|
@ -183,9 +184,8 @@ class ApplicationTest extends TestCase {
|
|||
);
|
||||
$listener->handle($event);
|
||||
|
||||
|
||||
$this->assertEquals($run, $event->isSuccessful());
|
||||
$this->assertEquals($run, $event->getErrorMessage() === null);
|
||||
$this->assertEquals($downloadSuccessful, $event->isSuccessful());
|
||||
$this->assertEquals($downloadSuccessful, $event->getErrorMessage() === null);
|
||||
}
|
||||
|
||||
public function testCheckFileUserNotFound(): void {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Sharing\Tests\Middleware;
|
||||
|
||||
use OCA\Files_Sharing\Controller\ShareAPIController;
|
||||
|
|
@ -13,18 +14,17 @@ use OCP\AppFramework\OCS\OCSNotFoundException;
|
|||
use OCP\AppFramework\OCSController;
|
||||
use OCP\IL10N;
|
||||
use OCP\Share\IManager;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
/**
|
||||
* @package OCA\Files_Sharing\Middleware\SharingCheckMiddleware
|
||||
*/
|
||||
class OCSShareAPIMiddlewareTest extends \Test\TestCase {
|
||||
private IManager&MockObject $shareManager;
|
||||
private IL10N&MockObject $l;
|
||||
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $shareManager;
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
/** @var OCSShareAPIMiddleware */
|
||||
private $middleware;
|
||||
private OCSShareAPIMiddleware $middleware;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -37,49 +37,44 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
|
|||
$this->middleware = new OCSShareAPIMiddleware($this->shareManager, $this->l);
|
||||
}
|
||||
|
||||
public function dataBeforeController() {
|
||||
public static function dataBeforeController() {
|
||||
return [
|
||||
[
|
||||
$this->createMock(Controller::class),
|
||||
Controller::class,
|
||||
false,
|
||||
false
|
||||
],
|
||||
[
|
||||
$this->createMock(Controller::class),
|
||||
Controller::class,
|
||||
true,
|
||||
false
|
||||
],
|
||||
[
|
||||
$this->createMock(OCSController::class),
|
||||
OCSController::class,
|
||||
false,
|
||||
false
|
||||
],
|
||||
[
|
||||
$this->createMock(OCSController::class),
|
||||
OCSController::class,
|
||||
true,
|
||||
false
|
||||
],
|
||||
[
|
||||
$this->createMock(ShareAPIController::class),
|
||||
ShareAPIController::class,
|
||||
false,
|
||||
true
|
||||
],
|
||||
[
|
||||
$this->createMock(ShareAPIController::class),
|
||||
ShareAPIController::class,
|
||||
true,
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Controller $controller
|
||||
* @param bool $enabled
|
||||
* @param bool $exception
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataBeforeController')]
|
||||
public function testBeforeController(Controller $controller, $enabled, $exception): void {
|
||||
#[DataProvider('dataBeforeController')]
|
||||
public function testBeforeController(string $controllerClass, bool $enabled, bool $exception): void {
|
||||
$controller = $this->createMock($controllerClass);
|
||||
$this->shareManager->method('shareApiEnabled')->willReturn($enabled);
|
||||
|
||||
try {
|
||||
|
|
@ -90,27 +85,23 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function dataAfterController() {
|
||||
public static function dataAfterController(): array {
|
||||
return [
|
||||
[
|
||||
$this->createMock(Controller::class),
|
||||
Controller::class,
|
||||
],
|
||||
[
|
||||
$this->createMock(OCSController::class),
|
||||
OCSController::class,
|
||||
],
|
||||
[
|
||||
$this->createMock(ShareAPIController::class),
|
||||
ShareAPIController::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Controller $controller
|
||||
* @param bool $called
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataAfterController')]
|
||||
public function testAfterController(Controller $controller): void {
|
||||
#[DataProvider('dataAfterController')]
|
||||
public function testAfterController(string $controllerClass): void {
|
||||
$controller = $this->createMock($controllerClass);
|
||||
if ($controller instanceof ShareAPIController) {
|
||||
$controller->expects($this->once())->method('cleanup');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,22 +99,6 @@ class WellKnownUrlsTest extends TestCase {
|
|||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataTestResponses')]
|
||||
public function testResponses($responses, string $expectedSeverity): void {
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValueBool')
|
||||
->with('check_for_working_wellknown_setup')
|
||||
->willReturn(true);
|
||||
|
||||
$this->setupcheck
|
||||
->expects($this->atLeastOnce())
|
||||
->method('runRequest')
|
||||
->willReturnOnConsecutiveCalls(...$responses);
|
||||
|
||||
$result = $this->setupcheck->run();
|
||||
$this->assertEquals($expectedSeverity, $result->getSeverity());
|
||||
}
|
||||
|
||||
public function dataTestResponses(): array {
|
||||
$createResponse = function (int $statuscode, array $header = []): IResponse&MockObject {
|
||||
$response = $this->createMock(IResponse::class);
|
||||
$response->expects($this->any())
|
||||
|
|
@ -126,78 +110,105 @@ class WellKnownUrlsTest extends TestCase {
|
|||
return $response;
|
||||
};
|
||||
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getSystemValueBool')
|
||||
->with('check_for_working_wellknown_setup')
|
||||
->willReturn(true);
|
||||
|
||||
/* Use generate to mock a Generator, and $createResponse to create the response objects */
|
||||
$responses = array_map(
|
||||
fn (array $items) => $this->generate(
|
||||
array_map(
|
||||
fn (array $item) => $createResponse(...$item),
|
||||
$items,
|
||||
)
|
||||
),
|
||||
$responses,
|
||||
);
|
||||
|
||||
$this->setupcheck
|
||||
->expects($this->atLeastOnce())
|
||||
->method('runRequest')
|
||||
->willReturnOnConsecutiveCalls(...$responses);
|
||||
|
||||
$result = $this->setupcheck->run();
|
||||
$this->assertEquals($expectedSeverity, $result->getSeverity());
|
||||
}
|
||||
|
||||
public static function dataTestResponses(): array {
|
||||
$wellKnownHeader = ['X-NEXTCLOUD-WELL-KNOWN' => 'yes'];
|
||||
|
||||
return [
|
||||
'expected codes' => [
|
||||
[
|
||||
$this->generate([$createResponse(200, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(200, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
[[200, $wellKnownHeader]],
|
||||
[[200, $wellKnownHeader]],
|
||||
[[207]],
|
||||
[[207]],
|
||||
],
|
||||
SetupResult::SUCCESS,
|
||||
],
|
||||
'late response with expected codes' => [
|
||||
[
|
||||
$this->generate([$createResponse(404), $createResponse(200, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(404), $createResponse(200, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(404), $createResponse(207)]),
|
||||
$this->generate([$createResponse(404), $createResponse(207)]),
|
||||
[[404], [200, $wellKnownHeader]],
|
||||
[[404], [200, $wellKnownHeader]],
|
||||
[[404], [207]],
|
||||
[[404], [207]],
|
||||
],
|
||||
SetupResult::SUCCESS,
|
||||
],
|
||||
'working but disabled webfinger' => [
|
||||
[
|
||||
$this->generate([$createResponse(404, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(404, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
[[404, $wellKnownHeader]],
|
||||
[[404, $wellKnownHeader]],
|
||||
[[207]],
|
||||
[[207]],
|
||||
],
|
||||
SetupResult::SUCCESS,
|
||||
],
|
||||
'unauthorized webdav but with correct configured redirect' => [
|
||||
[
|
||||
$this->generate([$createResponse(404, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(404, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(401, ['X-Guzzle-Redirect-History' => 'https://example.com,https://example.com/remote.php/dav/'])]),
|
||||
$this->generate([$createResponse(401, ['X-Guzzle-Redirect-History' => 'https://example.com/remote.php/dav/'])]),
|
||||
[[404, $wellKnownHeader]],
|
||||
[[404, $wellKnownHeader]],
|
||||
[[401, ['X-Guzzle-Redirect-History' => 'https://example.com,https://example.com/remote.php/dav/']]],
|
||||
[[401, ['X-Guzzle-Redirect-History' => 'https://example.com/remote.php/dav/']]],
|
||||
],
|
||||
SetupResult::SUCCESS,
|
||||
],
|
||||
'not configured path' => [
|
||||
[
|
||||
$this->generate([$createResponse(404)]),
|
||||
$this->generate([$createResponse(404)]),
|
||||
$this->generate([$createResponse(404)]),
|
||||
$this->generate([$createResponse(404)]),
|
||||
[[404]],
|
||||
[[404]],
|
||||
[[404]],
|
||||
[[404]],
|
||||
],
|
||||
SetupResult::WARNING,
|
||||
],
|
||||
'Invalid webfinger' => [
|
||||
[
|
||||
$this->generate([$createResponse(404)]),
|
||||
$this->generate([$createResponse(404, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
[[404]],
|
||||
[[404, $wellKnownHeader]],
|
||||
[[207]],
|
||||
[[207]],
|
||||
],
|
||||
SetupResult::WARNING,
|
||||
],
|
||||
'Invalid nodeinfo' => [
|
||||
[
|
||||
$this->generate([$createResponse(404, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(404)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
[[404, $wellKnownHeader]],
|
||||
[[404]],
|
||||
[[207]],
|
||||
[[207]],
|
||||
],
|
||||
SetupResult::WARNING,
|
||||
],
|
||||
'Invalid caldav' => [
|
||||
[
|
||||
$this->generate([$createResponse(404, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(404, $wellKnownHeader)]),
|
||||
$this->generate([$createResponse(404)]),
|
||||
$this->generate([$createResponse(207)]),
|
||||
[[404, $wellKnownHeader]],
|
||||
[[404, $wellKnownHeader]],
|
||||
[[404]],
|
||||
[[207]],
|
||||
],
|
||||
SetupResult::WARNING,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ use OCP\IL10N;
|
|||
use OCP\INavigationManager;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
|
|
@ -69,28 +70,30 @@ class PersonalTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestGetForm(): array {
|
||||
public static function dataTestGetForm(): array {
|
||||
return [
|
||||
['', [
|
||||
$this->formatThemeForm('default'),
|
||||
$this->formatThemeForm('light'),
|
||||
$this->formatThemeForm('dark'),
|
||||
$this->formatThemeForm('light-highcontrast'),
|
||||
$this->formatThemeForm('dark-highcontrast'),
|
||||
$this->formatThemeForm('opendyslexic'),
|
||||
'default',
|
||||
'light',
|
||||
'dark',
|
||||
'light-highcontrast',
|
||||
'dark-highcontrast',
|
||||
'opendyslexic',
|
||||
]],
|
||||
['dark', [
|
||||
$this->formatThemeForm('dark'),
|
||||
$this->formatThemeForm('opendyslexic'),
|
||||
'dark',
|
||||
'opendyslexic',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $enabledThemes
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetForm')]
|
||||
#[DataProvider('dataTestGetForm')]
|
||||
public function testGetForm(string $enforcedTheme, array $themesState): void {
|
||||
$themesState = array_map(
|
||||
$this->formatThemeForm(...),
|
||||
$themesState
|
||||
);
|
||||
|
||||
$this->config->expects($this->once())
|
||||
->method('getSystemValueString')
|
||||
->with('enforce_theme', '')
|
||||
|
|
|
|||
|
|
@ -396,8 +396,8 @@ function execute_tests {
|
|||
echo "No coverage"
|
||||
fi
|
||||
|
||||
echo "$PHPUNIT" --colors=always --configuration phpunit-autotest.xml $GROUP $COVER --log-junit "autotest-results-$DB.xml" "$2" "$3"
|
||||
"$PHPUNIT" --colors=always --configuration phpunit-autotest.xml $GROUP $COVER --log-junit "autotest-results-$DB.xml" "$2" "$3"
|
||||
echo "$PHPUNIT" --fail-on-warning --fail-on-risky --display-warnings --display-deprecations --display-phpunit-deprecations --colors=always --configuration phpunit-autotest.xml $GROUP $COVER --log-junit "autotest-results-$DB.xml" "$2" "$3"
|
||||
"$PHPUNIT" --fail-on-warning --fail-on-risky --display-warnings --display-deprecations --display-phpunit-deprecations --colors=always --configuration phpunit-autotest.xml $GROUP $COVER --log-junit "autotest-results-$DB.xml" "$2" "$3"
|
||||
RESULT=$?
|
||||
|
||||
if [ "$PRIMARY_STORAGE_CONFIG" == "swift" ] ; then
|
||||
|
|
|
|||
|
|
@ -68,9 +68,9 @@
|
|||
"Composer\\Config::disableProcessTimeout",
|
||||
"PHP_CLI_SERVER_WORKERS=${NEXTCLOUD_WORKERS:=4} php -S ${NEXTCLOUD_HOST:=localhost}:${NEXTCLOUD_PORT:=8080} -t ./"
|
||||
],
|
||||
"test": "phpunit --colors=always --configuration tests/phpunit-autotest.xml",
|
||||
"test": "phpunit --fail-on-warning --fail-on-risky --display-warnings --display-deprecations --display-phpunit-deprecations --colors=always --configuration tests/phpunit-autotest.xml",
|
||||
"test:db": "@composer run test -- --group DB,SLOWDB",
|
||||
"test:files_external": "phpunit --colors=always --configuration tests/phpunit-autotest-external.xml",
|
||||
"test:files_external": "phpunit --fail-on-warning --fail-on-risky --display-warnings --display-deprecations --display-phpunit-deprecations --colors=always --configuration tests/phpunit-autotest-external.xml",
|
||||
"rector": "rector --config=build/rector.php && composer cs:fix",
|
||||
"openapi": "./build/openapi-checker.sh"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -16,32 +18,23 @@ use OCP\IGroupManager;
|
|||
use OCP\IUser;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Share\IShare;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class GroupPluginTest extends TestCase {
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $config;
|
||||
private IConfig&MockObject $config;
|
||||
private IGroupManager&MockObject $groupManager;
|
||||
private IUserSession&MockObject $session;
|
||||
private IUser&MockObject $user;
|
||||
|
||||
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $groupManager;
|
||||
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $session;
|
||||
|
||||
/** @var ISearchResult */
|
||||
protected $searchResult;
|
||||
protected ISearchResult $searchResult;
|
||||
|
||||
/** @var GroupPlugin */
|
||||
protected $plugin;
|
||||
|
||||
/** @var int */
|
||||
protected $limit = 2;
|
||||
|
||||
/** @var int */
|
||||
protected $offset = 0;
|
||||
|
||||
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $user;
|
||||
protected int $limit = 2;
|
||||
protected int $offset = 0;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -57,7 +50,7 @@ class GroupPluginTest extends TestCase {
|
|||
$this->user = $this->getUserMock('admin', 'Administrator');
|
||||
}
|
||||
|
||||
public function instantiatePlugin() {
|
||||
public function instantiatePlugin(): void {
|
||||
// cannot be done within setUp, because dependent mocks needs to be set
|
||||
// up with configuration etc. first
|
||||
$this->plugin = new GroupPlugin(
|
||||
|
|
@ -67,7 +60,7 @@ class GroupPluginTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function getUserMock($uid, $displayName) {
|
||||
public function getUserMock(string $uid, string $displayName): IUser&MockObject {
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
$user->expects($this->any())
|
||||
|
|
@ -81,13 +74,7 @@ class GroupPluginTest extends TestCase {
|
|||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $gid
|
||||
* @param null $displayName
|
||||
* @param bool $hide
|
||||
* @return IGroup|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected function getGroupMock($gid, $displayName = null, $hide = false) {
|
||||
protected function getGroupMock(string $gid, ?string $displayName = null, bool $hide = false): IGroup&MockObject {
|
||||
$group = $this->createMock(IGroup::class);
|
||||
|
||||
$group->expects($this->any())
|
||||
|
|
@ -109,7 +96,7 @@ class GroupPluginTest extends TestCase {
|
|||
return $group;
|
||||
}
|
||||
|
||||
public function dataGetGroups(): array {
|
||||
public static function dataGetGroups(): array {
|
||||
return [
|
||||
['test', false, true, false, [], [], [], [], true, false],
|
||||
['test', false, false, false, [], [], [], [], true, false],
|
||||
|
|
@ -118,7 +105,7 @@ class GroupPluginTest extends TestCase {
|
|||
// group without display name
|
||||
[
|
||||
'test', false, true, false,
|
||||
[$this->getGroupMock('test1')],
|
||||
[['test1']],
|
||||
[],
|
||||
[],
|
||||
[['label' => 'test1', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]],
|
||||
|
|
@ -128,7 +115,7 @@ class GroupPluginTest extends TestCase {
|
|||
// group with display name, search by id
|
||||
[
|
||||
'test', false, true, false,
|
||||
[$this->getGroupMock('test1', 'Test One')],
|
||||
[['test1', 'Test One']],
|
||||
[],
|
||||
[],
|
||||
[['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]],
|
||||
|
|
@ -138,7 +125,7 @@ class GroupPluginTest extends TestCase {
|
|||
// group with display name, search by display name
|
||||
[
|
||||
'one', false, true, false,
|
||||
[$this->getGroupMock('test1', 'Test One')],
|
||||
[['test1', 'Test One']],
|
||||
[],
|
||||
[],
|
||||
[['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]],
|
||||
|
|
@ -148,7 +135,7 @@ class GroupPluginTest extends TestCase {
|
|||
// group with display name, search by display name, exact expected
|
||||
[
|
||||
'Test One', false, true, false,
|
||||
[$this->getGroupMock('test1', 'Test One')],
|
||||
[['test1', 'Test One']],
|
||||
[],
|
||||
[['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]],
|
||||
[],
|
||||
|
|
@ -157,7 +144,7 @@ class GroupPluginTest extends TestCase {
|
|||
],
|
||||
[
|
||||
'test', false, false, false,
|
||||
[$this->getGroupMock('test1')],
|
||||
[['test1']],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
|
|
@ -167,8 +154,8 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', false, true, false,
|
||||
[
|
||||
$this->getGroupMock('test'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test'],
|
||||
['test1'],
|
||||
],
|
||||
[],
|
||||
[['label' => 'test', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test']]],
|
||||
|
|
@ -179,8 +166,8 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', false, false, false,
|
||||
[
|
||||
$this->getGroupMock('test'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test'],
|
||||
['test1'],
|
||||
],
|
||||
[],
|
||||
[['label' => 'test', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test']]],
|
||||
|
|
@ -191,8 +178,8 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', false, true, false,
|
||||
[
|
||||
$this->getGroupMock('test0'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test0'],
|
||||
['test1'],
|
||||
],
|
||||
[],
|
||||
[],
|
||||
|
|
@ -201,25 +188,25 @@ class GroupPluginTest extends TestCase {
|
|||
['label' => 'test1', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']],
|
||||
],
|
||||
false,
|
||||
null,
|
||||
false,
|
||||
],
|
||||
[
|
||||
'test', false, false, false,
|
||||
[
|
||||
$this->getGroupMock('test0'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test0'],
|
||||
['test1'],
|
||||
],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
true,
|
||||
null,
|
||||
false,
|
||||
],
|
||||
[
|
||||
'test', false, true, false,
|
||||
[
|
||||
$this->getGroupMock('test0'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test0'],
|
||||
['test1'],
|
||||
],
|
||||
[],
|
||||
[
|
||||
|
|
@ -230,13 +217,13 @@ class GroupPluginTest extends TestCase {
|
|||
['label' => 'test1', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']],
|
||||
],
|
||||
false,
|
||||
$this->getGroupMock('test'),
|
||||
['test'],
|
||||
],
|
||||
[
|
||||
'test', false, false, false,
|
||||
[
|
||||
$this->getGroupMock('test0'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test0'],
|
||||
['test1'],
|
||||
],
|
||||
[],
|
||||
[
|
||||
|
|
@ -244,17 +231,17 @@ class GroupPluginTest extends TestCase {
|
|||
],
|
||||
[],
|
||||
true,
|
||||
$this->getGroupMock('test'),
|
||||
['test'],
|
||||
],
|
||||
['test', true, true, false, [], [], [], [], true, false],
|
||||
['test', true, false, false, [], [], [], [], true, false],
|
||||
[
|
||||
'test', true, true, false,
|
||||
[
|
||||
$this->getGroupMock('test1'),
|
||||
$this->getGroupMock('test2'),
|
||||
['test1'],
|
||||
['test2'],
|
||||
],
|
||||
[$this->getGroupMock('test1')],
|
||||
[['test1']],
|
||||
[],
|
||||
[['label' => 'test1', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]],
|
||||
false,
|
||||
|
|
@ -263,10 +250,10 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', true, false, false,
|
||||
[
|
||||
$this->getGroupMock('test1'),
|
||||
$this->getGroupMock('test2'),
|
||||
['test1'],
|
||||
['test2'],
|
||||
],
|
||||
[$this->getGroupMock('test1')],
|
||||
[['test1']],
|
||||
[],
|
||||
[],
|
||||
true,
|
||||
|
|
@ -275,10 +262,10 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', true, true, false,
|
||||
[
|
||||
$this->getGroupMock('test'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test')],
|
||||
[['test']],
|
||||
[['label' => 'test', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test']]],
|
||||
[],
|
||||
false,
|
||||
|
|
@ -287,10 +274,10 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', true, false, false,
|
||||
[
|
||||
$this->getGroupMock('test'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test')],
|
||||
[['test']],
|
||||
[['label' => 'test', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test']]],
|
||||
[],
|
||||
true,
|
||||
|
|
@ -299,10 +286,10 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', true, true, false,
|
||||
[
|
||||
$this->getGroupMock('test'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test1')],
|
||||
[['test1']],
|
||||
[],
|
||||
[['label' => 'test1', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]],
|
||||
false,
|
||||
|
|
@ -311,10 +298,10 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', true, false, false,
|
||||
[
|
||||
$this->getGroupMock('test'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test1')],
|
||||
[['test1']],
|
||||
[],
|
||||
[],
|
||||
true,
|
||||
|
|
@ -323,10 +310,10 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', true, true, false,
|
||||
[
|
||||
$this->getGroupMock('test'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
|
||||
[['test'], ['test0'], ['test1']],
|
||||
[['label' => 'test', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test']]],
|
||||
[['label' => 'test1', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]],
|
||||
false,
|
||||
|
|
@ -335,10 +322,10 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', true, false, false,
|
||||
[
|
||||
$this->getGroupMock('test'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
|
||||
[['test'], ['test0'], ['test1']],
|
||||
[['label' => 'test', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test']]],
|
||||
[],
|
||||
true,
|
||||
|
|
@ -347,37 +334,37 @@ class GroupPluginTest extends TestCase {
|
|||
[
|
||||
'test', true, true, false,
|
||||
[
|
||||
$this->getGroupMock('test0'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test0'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
|
||||
[['test'], ['test0'], ['test1']],
|
||||
[],
|
||||
[
|
||||
['label' => 'test0', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test0']],
|
||||
['label' => 'test1', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']],
|
||||
],
|
||||
false,
|
||||
null,
|
||||
false,
|
||||
],
|
||||
[
|
||||
'test', true, false, false,
|
||||
[
|
||||
$this->getGroupMock('test0'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test0'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
|
||||
[['test'], ['test0'], ['test1']],
|
||||
[],
|
||||
[],
|
||||
true,
|
||||
null,
|
||||
false,
|
||||
],
|
||||
[
|
||||
'test', true, true, false,
|
||||
[
|
||||
$this->getGroupMock('test0'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test0'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
|
||||
[['test'], ['test0'], ['test1']],
|
||||
[
|
||||
['label' => 'test', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test']],
|
||||
],
|
||||
|
|
@ -386,27 +373,27 @@ class GroupPluginTest extends TestCase {
|
|||
['label' => 'test1', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']],
|
||||
],
|
||||
false,
|
||||
$this->getGroupMock('test'),
|
||||
['test'],
|
||||
],
|
||||
[
|
||||
'test', true, false, false,
|
||||
[
|
||||
$this->getGroupMock('test0'),
|
||||
$this->getGroupMock('test1'),
|
||||
['test0'],
|
||||
['test1'],
|
||||
],
|
||||
[$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')],
|
||||
[['test'], ['test0'], ['test1']],
|
||||
[
|
||||
['label' => 'test', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test']],
|
||||
],
|
||||
[],
|
||||
true,
|
||||
$this->getGroupMock('test'),
|
||||
['test'],
|
||||
],
|
||||
[
|
||||
'test', false, false, false,
|
||||
[
|
||||
$this->getGroupMock('test', null, true),
|
||||
$this->getGroupMock('test1'),
|
||||
['test', null, true],
|
||||
['test1'],
|
||||
],
|
||||
[],
|
||||
[],
|
||||
|
|
@ -417,20 +404,7 @@ class GroupPluginTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $searchTerm
|
||||
* @param bool $shareWithGroupOnly
|
||||
* @param bool $shareeEnumeration
|
||||
* @param bool $groupSharingDisabled
|
||||
* @param array $groupResponse
|
||||
* @param array $userGroupsResponse
|
||||
* @param array $exactExpected
|
||||
* @param array $expected
|
||||
* @param bool $reachedEnd
|
||||
* @param bool|IGroup $singleGroup
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')]
|
||||
#[DataProvider('dataGetGroups')]
|
||||
public function testSearch(
|
||||
string $searchTerm,
|
||||
bool $shareWithGroupOnly,
|
||||
|
|
@ -441,8 +415,19 @@ class GroupPluginTest extends TestCase {
|
|||
array $exactExpected,
|
||||
array $expected,
|
||||
bool $reachedEnd,
|
||||
$singleGroup,
|
||||
array|false $singleGroup,
|
||||
): void {
|
||||
$groupResponse = array_map(
|
||||
fn ($args) => $this->getGroupMock(...$args),
|
||||
$groupResponse
|
||||
);
|
||||
if (is_array($singleGroup)) {
|
||||
$singleGroup = $this->getGroupMock(...$singleGroup);
|
||||
}
|
||||
$userGroupsResponse = array_map(
|
||||
fn ($args) => $this->getGroupMock(...$args),
|
||||
$userGroupsResponse
|
||||
);
|
||||
$this->config->expects($this->any())
|
||||
->method('getAppValue')
|
||||
->willReturnCallback(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -12,34 +14,24 @@ use OC\Collaboration\Collaborators\UserPlugin;
|
|||
use OC\KnownUser\KnownUserService;
|
||||
use OCP\Collaboration\Collaborators\ISearchResult;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Share\IShare;
|
||||
use OCP\UserStatus\IManager as IUserStatusManager;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class UserPluginTest extends TestCase {
|
||||
/** @var IConfig|MockObject */
|
||||
protected $config;
|
||||
|
||||
/** @var IUserManager|MockObject */
|
||||
protected $userManager;
|
||||
|
||||
/** @var IGroupManager|MockObject */
|
||||
protected $groupManager;
|
||||
|
||||
/** @var IUserSession|MockObject */
|
||||
protected $session;
|
||||
|
||||
/** @var KnownUserService|MockObject */
|
||||
protected $knownUserService;
|
||||
|
||||
/** @var IUserStatusManager|MockObject */
|
||||
protected $userStatusManager;
|
||||
private IConfig&MockObject $config;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private IGroupManager&MockObject $groupManager;
|
||||
private IUserSession&MockObject $session;
|
||||
private KnownUserService&MockObject $knownUserService;
|
||||
private IUserStatusManager&MockObject $userStatusManager;
|
||||
private IUser&MockObject $user;
|
||||
|
||||
/** @var UserPlugin */
|
||||
protected $plugin;
|
||||
|
|
@ -51,9 +43,6 @@ class UserPluginTest extends TestCase {
|
|||
|
||||
protected int $offset = 0;
|
||||
|
||||
/** @var IUser|MockObject */
|
||||
protected $user;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
|
@ -74,7 +63,7 @@ class UserPluginTest extends TestCase {
|
|||
$this->user = $this->getUserMock('admin', 'Administrator');
|
||||
}
|
||||
|
||||
public function instantiatePlugin() {
|
||||
public function instantiatePlugin(): void {
|
||||
// cannot be done within setUp, because dependent mocks needs to be set
|
||||
// up with configuration etc. first
|
||||
$this->plugin = new UserPlugin(
|
||||
|
|
@ -87,7 +76,7 @@ class UserPluginTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function mockConfig($mockedSettings) {
|
||||
public function mockConfig($mockedSettings): void {
|
||||
$this->config->expects($this->any())
|
||||
->method('getAppValue')
|
||||
->willReturnCallback(
|
||||
|
|
@ -97,7 +86,7 @@ class UserPluginTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function getUserMock($uid, $displayName, $enabled = true, $groups = []) {
|
||||
public function getUserMock(string $uid, string $displayName, bool $enabled = true, array $groups = []): IUser&MockObject {
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
$user->expects($this->any())
|
||||
|
|
@ -115,17 +104,7 @@ class UserPluginTest extends TestCase {
|
|||
return $user;
|
||||
}
|
||||
|
||||
public function getGroupMock($gid) {
|
||||
$group = $this->createMock(IGroup::class);
|
||||
|
||||
$group->expects($this->any())
|
||||
->method('getGID')
|
||||
->willReturn($gid);
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
public function dataGetUsers(): array {
|
||||
public static function dataGetUsers(): array {
|
||||
return [
|
||||
['test', false, true, [], [], [], [], true, false],
|
||||
['test', false, false, [], [], [], [], true, false],
|
||||
|
|
@ -135,33 +114,33 @@ class UserPluginTest extends TestCase {
|
|||
'test', false, true, [], [],
|
||||
[
|
||||
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
||||
], [], true, $this->getUserMock('test', 'Test'),
|
||||
], [], true, ['test', 'Test'],
|
||||
],
|
||||
[
|
||||
'test', false, false, [], [],
|
||||
[
|
||||
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
||||
], [], true, $this->getUserMock('test', 'Test'),
|
||||
], [], true, ['test', 'Test'],
|
||||
],
|
||||
[
|
||||
'test', true, true, [], [],
|
||||
[], [], true, $this->getUserMock('test', 'Test'),
|
||||
[], [], true, ['test', 'Test'],
|
||||
],
|
||||
[
|
||||
'test', true, false, [], [],
|
||||
[], [], true, $this->getUserMock('test', 'Test'),
|
||||
[], [], true, ['test', 'Test'],
|
||||
],
|
||||
[
|
||||
'test', true, true, ['test-group'], [['test-group', 'test', 2, 0, []]],
|
||||
[
|
||||
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
||||
], [], true, $this->getUserMock('test', 'Test'),
|
||||
], [], true, ['test', 'Test'],
|
||||
],
|
||||
[
|
||||
'test', true, false, ['test-group'], [['test-group', 'test', 2, 0, []]],
|
||||
[
|
||||
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test'],
|
||||
], [], true, $this->getUserMock('test', 'Test'),
|
||||
], [], true, ['test', 'Test'],
|
||||
],
|
||||
[
|
||||
'test',
|
||||
|
|
@ -169,7 +148,7 @@ class UserPluginTest extends TestCase {
|
|||
true,
|
||||
[],
|
||||
[
|
||||
$this->getUserMock('test1', 'Test One'),
|
||||
['test1', 'Test One'],
|
||||
],
|
||||
[],
|
||||
[
|
||||
|
|
@ -184,7 +163,7 @@ class UserPluginTest extends TestCase {
|
|||
false,
|
||||
[],
|
||||
[
|
||||
$this->getUserMock('test1', 'Test One'),
|
||||
['test1', 'Test One'],
|
||||
],
|
||||
[],
|
||||
[],
|
||||
|
|
@ -197,8 +176,8 @@ class UserPluginTest extends TestCase {
|
|||
true,
|
||||
[],
|
||||
[
|
||||
$this->getUserMock('test1', 'Test One'),
|
||||
$this->getUserMock('test2', 'Test Two'),
|
||||
['test1', 'Test One'],
|
||||
['test2', 'Test Two'],
|
||||
],
|
||||
[],
|
||||
[
|
||||
|
|
@ -214,8 +193,8 @@ class UserPluginTest extends TestCase {
|
|||
false,
|
||||
[],
|
||||
[
|
||||
$this->getUserMock('test1', 'Test One'),
|
||||
$this->getUserMock('test2', 'Test Two'),
|
||||
['test1', 'Test One'],
|
||||
['test2', 'Test Two'],
|
||||
],
|
||||
[],
|
||||
[],
|
||||
|
|
@ -228,9 +207,9 @@ class UserPluginTest extends TestCase {
|
|||
true,
|
||||
[],
|
||||
[
|
||||
$this->getUserMock('test0', 'Test'),
|
||||
$this->getUserMock('test1', 'Test One'),
|
||||
$this->getUserMock('test2', 'Test Two'),
|
||||
['test0', 'Test'],
|
||||
['test1', 'Test One'],
|
||||
['test2', 'Test Two'],
|
||||
],
|
||||
[
|
||||
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test0'],
|
||||
|
|
@ -248,9 +227,9 @@ class UserPluginTest extends TestCase {
|
|||
true,
|
||||
[],
|
||||
[
|
||||
$this->getUserMock('test0', 'Test'),
|
||||
$this->getUserMock('test1', 'Test One'),
|
||||
$this->getUserMock('test2', 'Test Two'),
|
||||
['test0', 'Test'],
|
||||
['test1', 'Test One'],
|
||||
['test2', 'Test Two'],
|
||||
],
|
||||
[
|
||||
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test0'],
|
||||
|
|
@ -270,9 +249,9 @@ class UserPluginTest extends TestCase {
|
|||
false,
|
||||
[],
|
||||
[
|
||||
$this->getUserMock('test0', 'Test'),
|
||||
$this->getUserMock('test1', 'Test One'),
|
||||
$this->getUserMock('test2', 'Test Two'),
|
||||
['test0', 'Test'],
|
||||
['test1', 'Test One'],
|
||||
['test2', 'Test Two'],
|
||||
],
|
||||
[
|
||||
['label' => 'Test', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test0'], 'icon' => 'icon-user', 'subline' => null, 'status' => [], 'shareWithDisplayNameUnique' => 'test0'],
|
||||
|
|
@ -296,7 +275,7 @@ class UserPluginTest extends TestCase {
|
|||
],
|
||||
true,
|
||||
false,
|
||||
[['test1', $this->getUserMock('test1', 'Test One')]],
|
||||
[['test1', ['test1', 'Test One']]],
|
||||
],
|
||||
[
|
||||
'test',
|
||||
|
|
@ -311,7 +290,7 @@ class UserPluginTest extends TestCase {
|
|||
[],
|
||||
true,
|
||||
false,
|
||||
[['test1', $this->getUserMock('test1', 'Test One')]],
|
||||
[['test1', ['test1', 'Test One']]],
|
||||
],
|
||||
[
|
||||
'test',
|
||||
|
|
@ -336,8 +315,8 @@ class UserPluginTest extends TestCase {
|
|||
true,
|
||||
false,
|
||||
[
|
||||
['test1', $this->getUserMock('test1', 'Test One')],
|
||||
['test2', $this->getUserMock('test2', 'Test Two')],
|
||||
['test1', ['test1', 'Test One']],
|
||||
['test2', ['test2', 'Test Two']],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
@ -360,8 +339,8 @@ class UserPluginTest extends TestCase {
|
|||
true,
|
||||
false,
|
||||
[
|
||||
['test1', $this->getUserMock('test1', 'Test One')],
|
||||
['test2', $this->getUserMock('test2', 'Test Two')],
|
||||
['test1', ['test1', 'Test One']],
|
||||
['test2', ['test2', 'Test Two']],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
@ -386,8 +365,8 @@ class UserPluginTest extends TestCase {
|
|||
false,
|
||||
false,
|
||||
[
|
||||
['test', $this->getUserMock('test', 'Test One')],
|
||||
['test2', $this->getUserMock('test2', 'Test Two')],
|
||||
['test', ['test', 'Test One']],
|
||||
['test2', ['test2', 'Test Two']],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
@ -410,40 +389,34 @@ class UserPluginTest extends TestCase {
|
|||
true,
|
||||
false,
|
||||
[
|
||||
['test', $this->getUserMock('test', 'Test One')],
|
||||
['test2', $this->getUserMock('test2', 'Test Two')],
|
||||
['test', ['test', 'Test One']],
|
||||
['test2', ['test2', 'Test Two']],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $searchTerm
|
||||
* @param bool $shareWithGroupOnly
|
||||
* @param bool $shareeEnumeration
|
||||
* @param array $groupResponse
|
||||
* @param array $userResponse
|
||||
* @param array $exactExpected
|
||||
* @param array $expected
|
||||
* @param bool $reachedEnd
|
||||
* @param bool|IUser $singleUser
|
||||
* @param array $users
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetUsers')]
|
||||
#[DataProvider('dataGetUsers')]
|
||||
public function testSearch(
|
||||
$searchTerm,
|
||||
$shareWithGroupOnly,
|
||||
$shareeEnumeration,
|
||||
string $searchTerm,
|
||||
bool $shareWithGroupOnly,
|
||||
bool $shareeEnumeration,
|
||||
array $groupResponse,
|
||||
array $userResponse,
|
||||
array $exactExpected,
|
||||
array $expected,
|
||||
$reachedEnd,
|
||||
$singleUser,
|
||||
bool $reachedEnd,
|
||||
array|false $singleUser,
|
||||
array $users = [],
|
||||
$shareeEnumerationPhone = false,
|
||||
bool $shareeEnumerationPhone = false,
|
||||
): void {
|
||||
if ($singleUser !== false) {
|
||||
$singleUser = $this->getUserMock(...$singleUser);
|
||||
}
|
||||
$users = array_map(
|
||||
fn ($args) => [$args[0], $this->getUserMock(...$args[1])],
|
||||
$users
|
||||
);
|
||||
$this->mockConfig(['core' => [
|
||||
'shareapi_only_share_with_group_members' => $shareWithGroupOnly ? 'yes' : 'no',
|
||||
'shareapi_allow_share_dialog_user_enumeration' => $shareeEnumeration? 'yes' : 'no',
|
||||
|
|
@ -458,6 +431,10 @@ class UserPluginTest extends TestCase {
|
|||
->willReturn($this->user);
|
||||
|
||||
if (!$shareWithGroupOnly) {
|
||||
$userResponse = array_map(
|
||||
fn ($args) => $this->getUserMock(...$args),
|
||||
$userResponse
|
||||
);
|
||||
if ($shareeEnumerationPhone) {
|
||||
$this->userManager->expects($this->once())
|
||||
->method('searchKnownUsersByDisplayName')
|
||||
|
|
@ -470,12 +447,11 @@ class UserPluginTest extends TestCase {
|
|||
[$this->user->getUID(), 'test1', true],
|
||||
[$this->user->getUID(), 'test2', true],
|
||||
]);
|
||||
} else {
|
||||
$this->userManager->expects($this->once())
|
||||
->method('searchDisplayName')
|
||||
->with($searchTerm, $this->limit, $this->offset)
|
||||
->willReturn($userResponse);
|
||||
}
|
||||
$this->userManager->expects($this->once())
|
||||
->method('searchDisplayName')
|
||||
->with($searchTerm, $this->limit, $this->offset)
|
||||
->willReturn($userResponse);
|
||||
} else {
|
||||
$this->groupManager->method('getUserGroupIds')
|
||||
->with($this->user)
|
||||
|
|
@ -534,13 +510,8 @@ class UserPluginTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $users
|
||||
* @param array $expectedUIDs
|
||||
* @param $currentUserId
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('takeOutCurrentUserProvider')]
|
||||
public function testTakeOutCurrentUser(array $users, array $expectedUIDs, $currentUserId): void {
|
||||
#[DataProvider('takeOutCurrentUserProvider')]
|
||||
public function testTakeOutCurrentUser(array $users, array $expectedUIDs, ?string $currentUserId): void {
|
||||
$this->instantiatePlugin();
|
||||
|
||||
$this->session->expects($this->once())
|
||||
|
|
@ -717,8 +688,8 @@ class UserPluginTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEnumeration')]
|
||||
public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result, $mockedSettings): void {
|
||||
#[DataProvider('dataSearchEnumeration')]
|
||||
public function testSearchEnumerationLimit(string $search, $userGroups, $matchingUsers, $result, $mockedSettings): void {
|
||||
$this->mockConfig($mockedSettings);
|
||||
|
||||
$userResults = [];
|
||||
|
|
@ -765,10 +736,10 @@ class UserPluginTest extends TestCase {
|
|||
->willReturnCallback(function ($search) use ($matchingUsers) {
|
||||
$users = array_filter(
|
||||
$matchingUsers,
|
||||
fn ($user) => str_contains(strtolower($user['displayName']), strtolower($search))
|
||||
fn ($user) => str_contains(strtolower($user['displayName'] ?? ''), strtolower($search))
|
||||
);
|
||||
return array_map(
|
||||
fn ($user) => $this->getUserMock($user['uid'], $user['displayName']),
|
||||
fn ($user) => $this->getUserMock($user['uid'], $user['displayName'] ?? ''),
|
||||
$users);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -726,6 +726,8 @@ class MigrationsTest extends \Test\TestCase {
|
|||
$table->expects($this->any())
|
||||
->method('getName')
|
||||
->willReturn(\str_repeat('a', 30));
|
||||
$table->method('getIndexes')->willReturn([]);
|
||||
$table->method('getForeignKeys')->willReturn([]);
|
||||
|
||||
$table->expects($this->once())
|
||||
->method('getColumns')
|
||||
|
|
@ -735,6 +737,7 @@ class MigrationsTest extends \Test\TestCase {
|
|||
$schema->expects($this->once())
|
||||
->method('getTables')
|
||||
->willReturn([$table]);
|
||||
$schema->method('getSequences')->willReturn([]);
|
||||
|
||||
$sourceSchema = $this->createMock(Schema::class);
|
||||
$sourceSchema->expects($this->any())
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -15,11 +17,11 @@ use OC\DB\QueryBuilder\Parameter;
|
|||
use OC\DB\QueryBuilder\QueryBuilder;
|
||||
use OC\SystemConfig;
|
||||
use OCP\DB\IResult;
|
||||
use OCP\DB\QueryBuilder\ILiteral;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\DB\QueryBuilder\IQueryFunction;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -30,17 +32,11 @@ use Psr\Log\LoggerInterface;
|
|||
* @package Test\DB\QueryBuilder
|
||||
*/
|
||||
class QueryBuilderTest extends \Test\TestCase {
|
||||
/** @var QueryBuilder */
|
||||
protected $queryBuilder;
|
||||
private SystemConfig&MockObject $config;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
|
||||
/** @var IDBConnection */
|
||||
protected $connection;
|
||||
|
||||
/** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $config;
|
||||
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $logger;
|
||||
private QueryBuilder $queryBuilder;
|
||||
private IDBConnection $connection;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -105,7 +101,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param int|null $firstResult
|
||||
* @param array $expectedSet
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataFirstResult')]
|
||||
#[DataProvider('dataFirstResult')]
|
||||
public function testFirstResult($firstResult, $expectedSet): void {
|
||||
$this->deleteTestingRows();
|
||||
$this->createTestingRows();
|
||||
|
|
@ -142,7 +138,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param int $maxResult
|
||||
* @param array $expectedSet
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataMaxResults')]
|
||||
#[DataProvider('dataMaxResults')]
|
||||
public function testMaxResults($maxResult, $expectedSet): void {
|
||||
$this->deleteTestingRows();
|
||||
$this->createTestingRows();
|
||||
|
|
@ -164,10 +160,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
$this->deleteTestingRows();
|
||||
}
|
||||
|
||||
public function dataSelect(): array {
|
||||
$config = $this->createMock(SystemConfig::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$queryBuilder = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
|
||||
public static function dataSelect(): array {
|
||||
return [
|
||||
// select('column1')
|
||||
[['configvalue'], ['configvalue' => '99']],
|
||||
|
|
@ -179,31 +172,30 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
[[['configvalue', 'configkey']], ['configvalue' => '99', 'configkey' => 'testing1']],
|
||||
|
||||
// select(new Literal('column1'))
|
||||
[[$queryBuilder->expr()->literal('column1')], [], 'column1'],
|
||||
[['l::column1'], [], 'column1'],
|
||||
|
||||
// select('column1', 'column2')
|
||||
[[$queryBuilder->expr()->literal('column1'), 'configkey'], ['configkey' => 'testing1'], 'column1'],
|
||||
// select(new Literal('column1'), 'column2')
|
||||
[['l::column1', 'configkey'], ['configkey' => 'testing1'], 'column1'],
|
||||
|
||||
// select(['column1', 'column2'])
|
||||
[[[$queryBuilder->expr()->literal('column1'), 'configkey']], ['configkey' => 'testing1'], 'column1'],
|
||||
// select([new Literal('column1'), 'column2'])
|
||||
[[['l::column1', 'configkey']], ['configkey' => 'testing1'], 'column1'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $selectArguments
|
||||
* @param array $expected
|
||||
* @param string $expectedLiteral
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataSelect')]
|
||||
public function testSelect($selectArguments, $expected, $expectedLiteral = ''): void {
|
||||
#[DataProvider('dataSelect')]
|
||||
public function testSelect(array $selectArguments, array $expected, string $expectedLiteral = ''): void {
|
||||
$this->deleteTestingRows();
|
||||
$this->createTestingRows();
|
||||
|
||||
call_user_func_array(
|
||||
[$this->queryBuilder, 'select'],
|
||||
$selectArguments
|
||||
array_walk_recursive(
|
||||
$selectArguments,
|
||||
function (string &$arg) {
|
||||
if (\str_starts_with($arg, 'l::')) {
|
||||
$arg = $this->queryBuilder->expr()->literal(substr($arg, 3));
|
||||
}
|
||||
},
|
||||
);
|
||||
$this->queryBuilder->select(...$selectArguments);
|
||||
|
||||
$this->queryBuilder->from('*PREFIX*appconfig')
|
||||
->where($this->queryBuilder->expr()->eq(
|
||||
|
|
@ -232,18 +224,19 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
$this->deleteTestingRows();
|
||||
}
|
||||
|
||||
public function dataSelectAlias(): array {
|
||||
$config = $this->createMock(SystemConfig::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$queryBuilder = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
|
||||
public static function dataSelectAlias(): array {
|
||||
return [
|
||||
['configvalue', 'cv', ['cv' => '99']],
|
||||
[$queryBuilder->expr()->literal('column1'), 'thing', ['thing' => 'column1']],
|
||||
['l::column1', 'thing', ['thing' => 'column1']],
|
||||
];
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataSelectAlias')]
|
||||
public function testSelectAlias(string|ILiteral $select, string $alias, array $expected): void {
|
||||
#[DataProvider('dataSelectAlias')]
|
||||
public function testSelectAlias(string $select, string $alias, array $expected): void {
|
||||
if (str_starts_with($select, 'l::')) {
|
||||
$select = $this->queryBuilder->expr()->literal(substr($select, 3));
|
||||
}
|
||||
|
||||
$this->deleteTestingRows();
|
||||
$this->createTestingRows();
|
||||
|
||||
|
|
@ -335,10 +328,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
$this->deleteTestingRows('testFirstResult2');
|
||||
}
|
||||
|
||||
public function dataAddSelect(): array {
|
||||
$config = $this->createMock(SystemConfig::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$queryBuilder = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
|
||||
public static function dataAddSelect(): array {
|
||||
return [
|
||||
// addSelect('column1')
|
||||
[['configvalue'], ['appid' => 'testFirstResult', 'configvalue' => '99']],
|
||||
|
|
@ -350,27 +340,30 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
[[['configvalue', 'configkey']], ['appid' => 'testFirstResult', 'configvalue' => '99', 'configkey' => 'testing1']],
|
||||
|
||||
// select(new Literal('column1'))
|
||||
[[$queryBuilder->expr()->literal('column1')], ['appid' => 'testFirstResult'], 'column1'],
|
||||
[['l::column1'], ['appid' => 'testFirstResult'], 'column1'],
|
||||
|
||||
// select('column1', 'column2')
|
||||
[[$queryBuilder->expr()->literal('column1'), 'configkey'], ['appid' => 'testFirstResult', 'configkey' => 'testing1'], 'column1'],
|
||||
// select(new Literal('column1'), 'column2')
|
||||
[['l::column1', 'configkey'], ['appid' => 'testFirstResult', 'configkey' => 'testing1'], 'column1'],
|
||||
|
||||
// select(['column1', 'column2'])
|
||||
[[[$queryBuilder->expr()->literal('column1'), 'configkey']], ['appid' => 'testFirstResult', 'configkey' => 'testing1'], 'column1'],
|
||||
// select([new Literal('column1'), 'column2'])
|
||||
[[['l::column1', 'configkey']], ['appid' => 'testFirstResult', 'configkey' => 'testing1'], 'column1'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $selectArguments
|
||||
* @param array $expected
|
||||
* @param string $expectedLiteral
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataAddSelect')]
|
||||
public function testAddSelect($selectArguments, $expected, $expectedLiteral = ''): void {
|
||||
#[DataProvider('dataAddSelect')]
|
||||
public function testAddSelect(array $selectArguments, array $expected, string $expectedLiteral = ''): void {
|
||||
$this->deleteTestingRows();
|
||||
$this->createTestingRows();
|
||||
|
||||
array_walk_recursive(
|
||||
$selectArguments,
|
||||
function (string &$arg) {
|
||||
if (\str_starts_with($arg, 'l::')) {
|
||||
$arg = $this->queryBuilder->expr()->literal(substr($arg, 3));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
$this->queryBuilder->select('appid');
|
||||
|
||||
call_user_func_array(
|
||||
|
|
@ -419,7 +412,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataDelete')]
|
||||
#[DataProvider('dataDelete')]
|
||||
public function testDelete($tableName, $tableAlias, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->delete($tableName, $tableAlias);
|
||||
|
||||
|
|
@ -448,7 +441,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataUpdate')]
|
||||
#[DataProvider('dataUpdate')]
|
||||
public function testUpdate($tableName, $tableAlias, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->update($tableName, $tableAlias);
|
||||
|
||||
|
|
@ -475,7 +468,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataInsert')]
|
||||
#[DataProvider('dataInsert')]
|
||||
public function testInsert($tableName, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->insert($tableName);
|
||||
|
||||
|
|
@ -490,12 +483,9 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataFrom(): array {
|
||||
$config = $this->createMock(SystemConfig::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$qb = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
|
||||
public static function dataFrom(): array {
|
||||
return [
|
||||
[$qb->createFunction('(' . $qb->select('*')->from('test')->getSQL() . ')'), 'q', null, null, [
|
||||
['function', 'q', null, null, [
|
||||
['table' => '(SELECT * FROM `*PREFIX*test`)', 'alias' => '`q`']
|
||||
], '(SELECT * FROM `*PREFIX*test`) `q`'],
|
||||
['data', null, null, null, [['table' => '`*PREFIX*data`', 'alias' => null]], '`*PREFIX*data`'],
|
||||
|
|
@ -511,17 +501,15 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string|IQueryFunction $table1Name
|
||||
* @param string $table1Alias
|
||||
* @param string|IQueryFunction $table2Name
|
||||
* @param string $table2Alias
|
||||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataFrom')]
|
||||
public function testFrom($table1Name, $table1Alias, $table2Name, $table2Alias, $expectedQueryPart, $expectedQuery): void {
|
||||
#[DataProvider('dataFrom')]
|
||||
public function testFrom(string $table1Name, ?string $table1Alias, ?string $table2Name, ?string $table2Alias, array $expectedQueryPart, string $expectedQuery): void {
|
||||
$config = $this->createMock(SystemConfig::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$queryBuilder = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
|
||||
|
||||
if ($table1Name === 'function') {
|
||||
$table1Name = $queryBuilder->createFunction('(' . $queryBuilder->select('*')->from('test')->getSQL() . ')');
|
||||
}
|
||||
$this->queryBuilder->from($table1Name, $table1Alias);
|
||||
if ($table2Name !== null) {
|
||||
$this->queryBuilder->from($table2Name, $table2Alias);
|
||||
|
|
@ -568,7 +556,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataJoin')]
|
||||
#[DataProvider('dataJoin')]
|
||||
public function testJoin($fromAlias, $tableName, $tableAlias, $condition, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->from('data1', 'd1');
|
||||
$this->queryBuilder->join(
|
||||
|
|
@ -598,7 +586,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataJoin')]
|
||||
#[DataProvider('dataJoin')]
|
||||
public function testInnerJoin($fromAlias, $tableName, $tableAlias, $condition, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->from('data1', 'd1');
|
||||
$this->queryBuilder->innerJoin(
|
||||
|
|
@ -648,7 +636,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataLeftJoin')]
|
||||
#[DataProvider('dataLeftJoin')]
|
||||
public function testLeftJoin($fromAlias, $tableName, $tableAlias, $condition, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->from('data1', 'd1');
|
||||
$this->queryBuilder->leftJoin(
|
||||
|
|
@ -698,7 +686,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataRightJoin')]
|
||||
#[DataProvider('dataRightJoin')]
|
||||
public function testRightJoin($fromAlias, $tableName, $tableAlias, $condition, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->from('data1', 'd1');
|
||||
$this->queryBuilder->rightJoin(
|
||||
|
|
@ -737,7 +725,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataSet')]
|
||||
#[DataProvider('dataSet')]
|
||||
public function testSet($partOne1, $partOne2, $partTwo1, $partTwo2, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->update('data');
|
||||
$this->queryBuilder->set($partOne1, $partOne2);
|
||||
|
|
@ -769,7 +757,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataWhere')]
|
||||
#[DataProvider('dataWhere')]
|
||||
public function testWhere($whereArguments, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->select('column');
|
||||
call_user_func_array(
|
||||
|
|
@ -794,7 +782,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataWhere')]
|
||||
#[DataProvider('dataWhere')]
|
||||
public function testAndWhere($whereArguments, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->select('column');
|
||||
call_user_func_array(
|
||||
|
|
@ -826,7 +814,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataOrWhere')]
|
||||
#[DataProvider('dataOrWhere')]
|
||||
public function testOrWhere($whereArguments, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->select('column');
|
||||
call_user_func_array(
|
||||
|
|
@ -858,7 +846,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataGroupBy')]
|
||||
#[DataProvider('dataGroupBy')]
|
||||
public function testGroupBy($groupByArguments, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->select('column');
|
||||
call_user_func_array(
|
||||
|
|
@ -890,7 +878,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataAddGroupBy')]
|
||||
#[DataProvider('dataAddGroupBy')]
|
||||
public function testAddGroupBy($groupByArguments, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->select('column');
|
||||
$this->queryBuilder->groupBy('column1');
|
||||
|
|
@ -923,7 +911,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataSetValue')]
|
||||
#[DataProvider('dataSetValue')]
|
||||
public function testSetValue($column, $value, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->insert('data');
|
||||
$this->queryBuilder->setValue($column, $value);
|
||||
|
|
@ -946,7 +934,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataSetValue')]
|
||||
#[DataProvider('dataSetValue')]
|
||||
public function testValues($column, $value, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->insert('data');
|
||||
$this->queryBuilder->values([
|
||||
|
|
@ -987,7 +975,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataHaving')]
|
||||
#[DataProvider('dataHaving')]
|
||||
public function testHaving($havingArguments, $expectedQueryPart, $expectedQuery): void {
|
||||
call_user_func_array(
|
||||
[$this->queryBuilder, 'having'],
|
||||
|
|
@ -1028,7 +1016,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataAndHaving')]
|
||||
#[DataProvider('dataAndHaving')]
|
||||
public function testAndHaving($havingArguments, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->having('condition1');
|
||||
call_user_func_array(
|
||||
|
|
@ -1070,7 +1058,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataOrHaving')]
|
||||
#[DataProvider('dataOrHaving')]
|
||||
public function testOrHaving($havingArguments, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->having('condition1');
|
||||
call_user_func_array(
|
||||
|
|
@ -1104,7 +1092,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataOrderBy')]
|
||||
#[DataProvider('dataOrderBy')]
|
||||
public function testOrderBy($sort, $order, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->orderBy($sort, $order);
|
||||
|
||||
|
|
@ -1141,7 +1129,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param array $expectedQueryPart
|
||||
* @param string $expectedQuery
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataAddOrderBy')]
|
||||
#[DataProvider('dataAddOrderBy')]
|
||||
public function testAddOrderBy($sort2, $order2, $order1, $expectedQueryPart, $expectedQuery): void {
|
||||
$this->queryBuilder->orderBy('column1', $order1);
|
||||
$this->queryBuilder->addOrderBy($sort2, $order2);
|
||||
|
|
@ -1194,10 +1182,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function dataGetTableName(): array {
|
||||
$config = $this->createMock(SystemConfig::class);
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$qb = new QueryBuilder(Server::get(IDBConnection::class), $config, $logger);
|
||||
public static function dataGetTableName(): array {
|
||||
return [
|
||||
['*PREFIX*table', null, '`*PREFIX*table`'],
|
||||
['*PREFIX*table', true, '`*PREFIX*table`'],
|
||||
|
|
@ -1207,20 +1192,18 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
['table', true, '`*PREFIX*table`'],
|
||||
['table', false, '`table`'],
|
||||
|
||||
[$qb->createFunction('(' . $qb->select('*')->from('table')->getSQL() . ')'), null, '(SELECT * FROM `*PREFIX*table`)'],
|
||||
[$qb->createFunction('(' . $qb->select('*')->from('table')->getSQL() . ')'), true, '(SELECT * FROM `*PREFIX*table`)'],
|
||||
[$qb->createFunction('(' . $qb->select('*')->from('table')->getSQL() . ')'), false, '(SELECT * FROM `*PREFIX*table`)'],
|
||||
['function', null, '(SELECT * FROM `*PREFIX*table`)'],
|
||||
['function', true, '(SELECT * FROM `*PREFIX*table`)'],
|
||||
['function', false, '(SELECT * FROM `*PREFIX*table`)'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string|IQueryFunction $tableName
|
||||
* @param bool $automatic
|
||||
* @param string $expected
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetTableName')]
|
||||
public function testGetTableName($tableName, $automatic, $expected): void {
|
||||
#[DataProvider('dataGetTableName')]
|
||||
public function testGetTableName(string $tableName, ?bool $automatic, string $expected): void {
|
||||
if ($tableName === 'function') {
|
||||
$tableName = $this->queryBuilder->createFunction('(' . $this->queryBuilder->select('*')->from('table')->getSQL() . ')');
|
||||
}
|
||||
|
||||
if ($automatic !== null) {
|
||||
$this->queryBuilder->automaticTablePrefix($automatic);
|
||||
}
|
||||
|
|
@ -1243,7 +1226,7 @@ class QueryBuilderTest extends \Test\TestCase {
|
|||
* @param string $prefix
|
||||
* @param string $expected
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetColumnName')]
|
||||
#[DataProvider('dataGetColumnName')]
|
||||
public function testGetColumnName($column, $prefix, $expected): void {
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
|
|
|
|||
|
|
@ -61,6 +61,15 @@ abstract class ObjectStoreTestCase extends TestCase {
|
|||
$this->assertEquals('foobar', stream_get_contents($result));
|
||||
}
|
||||
|
||||
protected function assertOnlyExpectedWarnings(array $warnings): void {
|
||||
$onlyFopenWarnings = array_reduce(
|
||||
$warnings,
|
||||
fn (bool $ok, string $warning) => $ok && str_starts_with($warning, 'fopen('),
|
||||
true,
|
||||
);
|
||||
$this->assertTrue($onlyFopenWarnings);
|
||||
}
|
||||
|
||||
public function testDelete(): void {
|
||||
$stream = $this->stringToStream('foobar');
|
||||
|
||||
|
|
@ -70,25 +79,39 @@ abstract class ObjectStoreTestCase extends TestCase {
|
|||
|
||||
$instance->deleteObject('2');
|
||||
|
||||
$warnings = [];
|
||||
try {
|
||||
set_error_handler(
|
||||
function (int $errno, string $errstr) use (&$warnings): void {
|
||||
$warnings[] = $errstr;
|
||||
},
|
||||
);
|
||||
// to to read to verify that the object no longer exists
|
||||
$instance->readObject('2');
|
||||
$this->fail();
|
||||
} catch (\Exception $e) {
|
||||
// dummy assert to keep phpunit happy
|
||||
$this->assertEquals(1, 1);
|
||||
$this->assertOnlyExpectedWarnings($warnings);
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
public function testReadNonExisting(): void {
|
||||
$instance = $this->getInstance();
|
||||
|
||||
$warnings = [];
|
||||
try {
|
||||
set_error_handler(
|
||||
function (int $errno, string $errstr) use (&$warnings): void {
|
||||
$warnings[] = $errstr;
|
||||
},
|
||||
);
|
||||
$instance->readObject('non-existing');
|
||||
$this->fail();
|
||||
} catch (\Exception $e) {
|
||||
// dummy assert to keep phpunit happy
|
||||
$this->assertEquals(1, 1);
|
||||
$this->assertOnlyExpectedWarnings($warnings);
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,6 +110,13 @@ class S3Test extends ObjectStoreTestCase {
|
|||
$emptyStream = fopen('php://memory', 'r');
|
||||
fwrite($emptyStream, '');
|
||||
|
||||
$warnings = [];
|
||||
set_error_handler(
|
||||
function (int $errno, string $errstr) use (&$warnings): void {
|
||||
$warnings[] = $errstr;
|
||||
},
|
||||
);
|
||||
|
||||
$s3->writeObject('emptystream', $emptyStream);
|
||||
|
||||
$this->assertNoUpload('emptystream');
|
||||
|
|
@ -126,6 +133,8 @@ class S3Test extends ObjectStoreTestCase {
|
|||
self::assertTrue($thrown, 'readObject with range requests are not expected to work on empty objects');
|
||||
|
||||
$s3->deleteObject('emptystream');
|
||||
$this->assertOnlyExpectedWarnings($warnings);
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
/** File size to upload in bytes */
|
||||
|
|
|
|||
|
|
@ -831,183 +831,238 @@ class ManagerTest extends \Test\TestCase {
|
|||
return $share;
|
||||
}
|
||||
|
||||
public function dataGeneralChecks() {
|
||||
public static function dataGeneralChecks(): array {
|
||||
$user0 = 'user0';
|
||||
$user2 = 'user1';
|
||||
$group0 = 'group0';
|
||||
$owner = $this->createMock(IUser::class);
|
||||
$owner->method('getUID')
|
||||
->willReturn($user0);
|
||||
|
||||
$file = $this->createMock(File::class);
|
||||
$node = $this->createMock(Node::class);
|
||||
$storage = $this->createMock(IStorage::class);
|
||||
$storage->method('instanceOfStorage')
|
||||
->with('\OCA\Files_Sharing\External\Storage')
|
||||
->willReturn(false);
|
||||
$file->method('getStorage')
|
||||
->willReturn($storage);
|
||||
$file->method('getId')->willReturn(108);
|
||||
$node->method('getStorage')
|
||||
->willReturn($storage);
|
||||
$node->method('getId')->willReturn(108);
|
||||
|
||||
$data = [
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, null, $user0, $user0, 31, null, null), 'Share recipient is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, $group0, $user0, $user0, 31, null, null), 'Share recipient is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'Share recipient is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, null, $user0, $user0, 31, null, null), 'Share recipient is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, $user2, $user0, $user0, 31, null, null), 'Share recipient is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'Share recipient is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, $user2, $user0, $user0, 31, null, null), 'Share recipient should be empty', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, $group0, $user0, $user0, 31, null, null), 'Share recipient should be empty', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'Share recipient should be empty', true],
|
||||
[$this->createShare(null, -1, $file, null, $user0, $user0, 31, null, null), 'Unknown share type', true],
|
||||
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, $user2, null, $user0, 31, null, null), 'Share initiator must be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'Share initiator must be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, null, null, $user0, 31, null, null), 'Share initiator must be set', true],
|
||||
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Cannot share with yourself', true],
|
||||
|
||||
[$this->createShare(null, IShare::TYPE_USER, null, $user2, $user0, $user0, 31, null, null), 'Shared path must be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Shared path must be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, null, null, $user0, $user0, 31, null, null), 'Shared path must be set', true],
|
||||
|
||||
[$this->createShare(null, IShare::TYPE_USER, $node, $user2, $user0, $user0, 31, null, null), 'Shared path must be either a file or a folder', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $node, $group0, $user0, $user0, 31, null, null), 'Shared path must be either a file or a folder', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $node, null, $user0, $user0, 31, null, null), 'Shared path must be either a file or a folder', true],
|
||||
$file = [
|
||||
File::class,
|
||||
[
|
||||
'getId' => 108,
|
||||
],
|
||||
'default',
|
||||
];
|
||||
|
||||
$nonShareAble = $this->createMock(Folder::class);
|
||||
$nonShareAble->method('getId')->willReturn(108);
|
||||
$nonShareAble->method('isShareable')->willReturn(false);
|
||||
$nonShareAble->method('getPath')->willReturn('path');
|
||||
$nonShareAble->method('getName')->willReturn('name');
|
||||
$nonShareAble->method('getOwner')
|
||||
->willReturn($owner);
|
||||
$nonShareAble->method('getStorage')
|
||||
->willReturn($storage);
|
||||
$node = [
|
||||
Node::class,
|
||||
[
|
||||
'getId' => 108,
|
||||
],
|
||||
'default',
|
||||
];
|
||||
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $nonShareAble, $user2, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
|
||||
$data = [
|
||||
[[null, IShare::TYPE_USER, $file, null, $user0, $user0, 31, null, null], 'Share recipient is not a valid user', true],
|
||||
[[null, IShare::TYPE_USER, $file, $group0, $user0, $user0, 31, null, null], 'Share recipient is not a valid user', true],
|
||||
[[null, IShare::TYPE_USER, $file, 'foo@bar.com', $user0, $user0, 31, null, null], 'Share recipient is not a valid user', true],
|
||||
[[null, IShare::TYPE_GROUP, $file, null, $user0, $user0, 31, null, null], 'Share recipient is not a valid group', true],
|
||||
[[null, IShare::TYPE_GROUP, $file, $user2, $user0, $user0, 31, null, null], 'Share recipient is not a valid group', true],
|
||||
[[null, IShare::TYPE_GROUP, $file, 'foo@bar.com', $user0, $user0, 31, null, null], 'Share recipient is not a valid group', true],
|
||||
[[null, IShare::TYPE_LINK, $file, $user2, $user0, $user0, 31, null, null], 'Share recipient should be empty', true],
|
||||
[[null, IShare::TYPE_LINK, $file, $group0, $user0, $user0, 31, null, null], 'Share recipient should be empty', true],
|
||||
[[null, IShare::TYPE_LINK, $file, 'foo@bar.com', $user0, $user0, 31, null, null], 'Share recipient should be empty', true],
|
||||
[[null, -1, $file, null, $user0, $user0, 31, null, null], 'Unknown share type', true],
|
||||
|
||||
$limitedPermssions = $this->createMock(File::class);
|
||||
$limitedPermssions->method('isShareable')->willReturn(true);
|
||||
$limitedPermssions->method('getPermissions')->willReturn(Constants::PERMISSION_READ);
|
||||
$limitedPermssions->method('getId')->willReturn(108);
|
||||
$limitedPermssions->method('getPath')->willReturn('path');
|
||||
$limitedPermssions->method('getName')->willReturn('name');
|
||||
$limitedPermssions->method('getOwner')
|
||||
->willReturn($owner);
|
||||
$limitedPermssions->method('getStorage')
|
||||
->willReturn($storage);
|
||||
[[null, IShare::TYPE_USER, $file, $user2, null, $user0, 31, null, null], 'Share initiator must be set', true],
|
||||
[[null, IShare::TYPE_GROUP, $file, $group0, null, $user0, 31, null, null], 'Share initiator must be set', true],
|
||||
[[null, IShare::TYPE_LINK, $file, null, null, $user0, 31, null, null], 'Share initiator must be set', true],
|
||||
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, null, null, null), 'Valid permissions are required for sharing', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'Valid permissions are required for sharing', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null), 'Valid permissions are required for sharing', true];
|
||||
[[null, IShare::TYPE_USER, $file, $user0, $user0, $user0, 31, null, null], 'Cannot share with yourself', true],
|
||||
|
||||
$mount = $this->createMock(MoveableMount::class);
|
||||
$limitedPermssions->method('getMountPoint')->willReturn($mount);
|
||||
[[null, IShare::TYPE_USER, null, $user2, $user0, $user0, 31, null, null], 'Shared path must be set', true],
|
||||
[[null, IShare::TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null], 'Shared path must be set', true],
|
||||
[[null, IShare::TYPE_LINK, null, null, $user0, $user0, 31, null, null], 'Shared path must be set', true],
|
||||
|
||||
[[null, IShare::TYPE_USER, $node, $user2, $user0, $user0, 31, null, null], 'Shared path must be either a file or a folder', true],
|
||||
[[null, IShare::TYPE_GROUP, $node, $group0, $user0, $user0, 31, null, null], 'Shared path must be either a file or a folder', true],
|
||||
[[null, IShare::TYPE_LINK, $node, null, $user0, $user0, 31, null, null], 'Shared path must be either a file or a folder', true],
|
||||
];
|
||||
|
||||
$nonShareAble = [
|
||||
Folder::class,
|
||||
[
|
||||
'getId' => 108,
|
||||
'isShareable' => false,
|
||||
'getPath' => 'path',
|
||||
'getName' => 'name',
|
||||
'getOwner' => $user0,
|
||||
],
|
||||
'default',
|
||||
];
|
||||
|
||||
$data[] = [[null, IShare::TYPE_USER, $nonShareAble, $user2, $user0, $user0, 31, null, null], 'You are not allowed to share name', true];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null], 'You are not allowed to share name', true];
|
||||
$data[] = [[null, IShare::TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null], 'You are not allowed to share name', true];
|
||||
|
||||
$limitedPermssions = [
|
||||
File::class,
|
||||
[
|
||||
'isShareable' => true,
|
||||
'getPermissions' => Constants::PERMISSION_READ,
|
||||
'getId' => 108,
|
||||
'getPath' => 'path',
|
||||
'getName' => 'name',
|
||||
'getOwner' => $user0,
|
||||
],
|
||||
'default',
|
||||
];
|
||||
|
||||
$data[] = [[null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, null, null, null], 'Valid permissions are required for sharing', true];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null], 'Valid permissions are required for sharing', true];
|
||||
$data[] = [[null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null], 'Valid permissions are required for sharing', true];
|
||||
|
||||
$limitedPermssions[1]['getMountPoint'] = MoveableMount::class;
|
||||
|
||||
// increase permissions of a re-share
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null], 'Cannot increase permissions of path', true];
|
||||
$data[] = [[null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 3, null, null], 'Cannot increase permissions of path', true];
|
||||
|
||||
$nonMovableStorage = $this->createMock(IStorage::class);
|
||||
$nonMovableStorage->method('instanceOfStorage')
|
||||
->with('\OCA\Files_Sharing\External\Storage')
|
||||
->willReturn(false);
|
||||
$nonMovableStorage->method('getPermissions')->willReturn(Constants::PERMISSION_ALL);
|
||||
$nonMoveableMountPermssions = $this->createMock(Folder::class);
|
||||
$nonMoveableMountPermssions->method('isShareable')->willReturn(true);
|
||||
$nonMoveableMountPermssions->method('getPermissions')->willReturn(Constants::PERMISSION_READ);
|
||||
$nonMoveableMountPermssions->method('getId')->willReturn(108);
|
||||
$nonMoveableMountPermssions->method('getPath')->willReturn('path');
|
||||
$nonMoveableMountPermssions->method('getName')->willReturn('name');
|
||||
$nonMoveableMountPermssions->method('getInternalPath')->willReturn('');
|
||||
$nonMoveableMountPermssions->method('getOwner')
|
||||
->willReturn($owner);
|
||||
$nonMoveableMountPermssions->method('getStorage')
|
||||
->willReturn($nonMovableStorage);
|
||||
$nonMoveableMountPermssions = [
|
||||
Folder::class,
|
||||
[
|
||||
'isShareable' => true,
|
||||
'getPermissions' => Constants::PERMISSION_READ,
|
||||
'getId' => 108,
|
||||
'getPath' => 'path',
|
||||
'getName' => 'name',
|
||||
'getInternalPath' => '',
|
||||
'getOwner' => $user0,
|
||||
],
|
||||
'allPermssions',
|
||||
];
|
||||
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false];
|
||||
$data[] = [[null, IShare::TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null], 'Cannot increase permissions of path', false];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null], 'Cannot increase permissions of path', false];
|
||||
|
||||
$rootFolder = $this->createMock(Folder::class);
|
||||
$rootFolder->method('isShareable')->willReturn(true);
|
||||
$rootFolder->method('getPermissions')->willReturn(Constants::PERMISSION_ALL);
|
||||
$rootFolder->method('getId')->willReturn(42);
|
||||
$rootFolder = [
|
||||
Folder::class,
|
||||
[
|
||||
'isShareable' => true,
|
||||
'getPermissions' => Constants::PERMISSION_ALL,
|
||||
'getId' => 42,
|
||||
],
|
||||
'none',
|
||||
];
|
||||
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You cannot share your root folder', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You cannot share your root folder', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You cannot share your root folder', true];
|
||||
$data[] = [[null, IShare::TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null], 'You cannot share your root folder', true];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null], 'You cannot share your root folder', true];
|
||||
$data[] = [[null, IShare::TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null], 'You cannot share your root folder', true];
|
||||
|
||||
$allPermssionsFiles = $this->createMock(File::class);
|
||||
$allPermssionsFiles->method('isShareable')->willReturn(true);
|
||||
$allPermssionsFiles->method('getPermissions')->willReturn(Constants::PERMISSION_ALL);
|
||||
$allPermssionsFiles->method('getId')->willReturn(187);
|
||||
$allPermssionsFiles->method('getOwner')
|
||||
->willReturn($owner);
|
||||
$allPermssionsFiles->method('getStorage')
|
||||
->willReturn($storage);
|
||||
$allPermssionsFiles = [
|
||||
File::class,
|
||||
[
|
||||
'isShareable' => true,
|
||||
'getPermissions' => Constants::PERMISSION_ALL,
|
||||
'getId' => 187,
|
||||
'getOwner' => $user0,
|
||||
],
|
||||
'default',
|
||||
];
|
||||
|
||||
// test invalid CREATE or DELETE permissions
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $allPermssionsFiles, $user2, $user0, $user0, Constants::PERMISSION_ALL, null, null), 'File shares cannot have create or delete permissions', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $allPermssionsFiles, $group0, $user0, $user0, Constants::PERMISSION_READ | Constants::PERMISSION_CREATE, null, null), 'File shares cannot have create or delete permissions', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $allPermssionsFiles, null, $user0, $user0, Constants::PERMISSION_READ | Constants::PERMISSION_DELETE, null, null), 'File shares cannot have create or delete permissions', true];
|
||||
$data[] = [[null, IShare::TYPE_USER, $allPermssionsFiles, $user2, $user0, $user0, Constants::PERMISSION_ALL, null, null], 'File shares cannot have create or delete permissions', true];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $allPermssionsFiles, $group0, $user0, $user0, Constants::PERMISSION_READ | Constants::PERMISSION_CREATE, null, null], 'File shares cannot have create or delete permissions', true];
|
||||
$data[] = [[null, IShare::TYPE_LINK, $allPermssionsFiles, null, $user0, $user0, Constants::PERMISSION_READ | Constants::PERMISSION_DELETE, null, null], 'File shares cannot have create or delete permissions', true];
|
||||
|
||||
$allPermssions = $this->createMock(Folder::class);
|
||||
$allPermssions->method('isShareable')->willReturn(true);
|
||||
$allPermssions->method('getPermissions')->willReturn(Constants::PERMISSION_ALL);
|
||||
$allPermssions->method('getId')->willReturn(108);
|
||||
$allPermssions->method('getOwner')
|
||||
->willReturn($owner);
|
||||
$allPermssions->method('getStorage')
|
||||
->willReturn($storage);
|
||||
$allPermssions = [
|
||||
Folder::class,
|
||||
[
|
||||
'isShareable' => true,
|
||||
'getPermissions' => Constants::PERMISSION_ALL,
|
||||
'getId' => 108,
|
||||
'getOwner' => $user0,
|
||||
],
|
||||
'default',
|
||||
];
|
||||
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 30, null, null), 'Shares need at least read permissions', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 2, null, null), 'Shares need at least read permissions', true];
|
||||
$data[] = [[null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 30, null, null], 'Shares need at least read permissions', true];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 2, null, null], 'Shares need at least read permissions', true];
|
||||
|
||||
// test invalid permissions
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 32, null, null), 'Valid permissions are required for sharing', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 63, null, null), 'Valid permissions are required for sharing', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $allPermssions, null, $user0, $user0, -1, null, null), 'Valid permissions are required for sharing', true];
|
||||
$data[] = [[null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 32, null, null], 'Valid permissions are required for sharing', true];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 63, null, null], 'Valid permissions are required for sharing', true];
|
||||
$data[] = [[null, IShare::TYPE_LINK, $allPermssions, null, $user0, $user0, -1, null, null], 'Valid permissions are required for sharing', true];
|
||||
|
||||
// working shares
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 31, null, null), null, false];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 3, null, null), null, false];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $allPermssions, null, $user0, $user0, 17, null, null), null, false];
|
||||
$data[] = [[null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 31, null, null], null, false];
|
||||
$data[] = [[null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 3, null, null], null, false];
|
||||
$data[] = [[null, IShare::TYPE_LINK, $allPermssions, null, $user0, $user0, 17, null, null], null, false];
|
||||
|
||||
$remoteFile = [
|
||||
Folder::class,
|
||||
[
|
||||
'isShareable' => true,
|
||||
'getPermissions' => Constants::PERMISSION_READ ^ Constants::PERMISSION_UPDATE,
|
||||
'getId' => 108,
|
||||
'getOwner' => $user0,
|
||||
],
|
||||
'remote',
|
||||
];
|
||||
|
||||
$remoteStorage = $this->createMock(IStorage::class);
|
||||
$remoteStorage->method('instanceOfStorage')
|
||||
->with('\OCA\Files_Sharing\External\Storage')
|
||||
->willReturn(true);
|
||||
$remoteFile = $this->createMock(Folder::class);
|
||||
$remoteFile->method('isShareable')->willReturn(true);
|
||||
$remoteFile->method('getPermissions')->willReturn(Constants::PERMISSION_READ ^ Constants::PERMISSION_UPDATE);
|
||||
$remoteFile->method('getId')->willReturn(108);
|
||||
$remoteFile->method('getOwner')
|
||||
->willReturn($owner);
|
||||
$remoteFile->method('getStorage')
|
||||
->willReturn($storage);
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 1, null, null), null, false];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 3, null, null), null, false];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of ', true];
|
||||
$data[] = [[null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 1, null, null], null, false];
|
||||
$data[] = [[null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 3, null, null], null, false];
|
||||
$data[] = [[null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 31, null, null], 'Cannot increase permissions of ', true];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $share
|
||||
* @param $exceptionMessage
|
||||
* @param $exception
|
||||
*/
|
||||
private function createNodeMock(string $class, array $methods, string $storageType): MockObject {
|
||||
$mock = $this->createMock($class);
|
||||
foreach ($methods as $methodName => $return) {
|
||||
if ($methodName === 'getOwner') {
|
||||
$uid = $return;
|
||||
$return = $this->createMock(IUser::class);
|
||||
$return->method('getUID')
|
||||
->willReturn($uid);
|
||||
} elseif ($methodName === 'getMountPoint') {
|
||||
$return = $this->createMock($return);
|
||||
}
|
||||
$mock->method($methodName)->willReturn($return);
|
||||
}
|
||||
switch ($storageType) {
|
||||
case 'default':
|
||||
$storage = $this->createMock(IStorage::class);
|
||||
$storage->method('instanceOfStorage')
|
||||
->with('\OCA\Files_Sharing\External\Storage')
|
||||
->willReturn(false);
|
||||
break;
|
||||
case 'allPermssions':
|
||||
$storage = $this->createMock(IStorage::class);
|
||||
$storage->method('instanceOfStorage')
|
||||
->with('\OCA\Files_Sharing\External\Storage')
|
||||
->willReturn(false);
|
||||
$storage->method('getPermissions')->willReturn(Constants::PERMISSION_ALL);
|
||||
break;
|
||||
case 'none':
|
||||
$storage = false;
|
||||
break;
|
||||
case 'remote':
|
||||
$storage = $this->createMock(IStorage::class);
|
||||
$storage->method('instanceOfStorage')
|
||||
->with('\OCA\Files_Sharing\External\Storage')
|
||||
->willReturn(true);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Unknown storage type ' . $storageType);
|
||||
}
|
||||
if ($storage === false) {
|
||||
$mock->expects(self::never())->method('getStorage');
|
||||
} else {
|
||||
$mock->method('getStorage')
|
||||
->willReturn($storage);
|
||||
}
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('dataGeneralChecks')]
|
||||
public function testGeneralChecks($share, $exceptionMessage, $exception): void {
|
||||
public function testGeneralChecks(array $shareParams, ?string $exceptionMessage, bool $exception): void {
|
||||
if ($shareParams[2] !== null) {
|
||||
$shareParams[2] = $this->createNodeMock(...$shareParams[2]);
|
||||
}
|
||||
$share = $this->createShare(...$shareParams);
|
||||
|
||||
$thrown = null;
|
||||
|
||||
$this->userManager->method('userExists')->willReturnMap([
|
||||
|
|
|
|||
Loading…
Reference in a new issue