aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin/tests')
-rw-r--r--apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php63
-rw-r--r--apps/files_trashbin/tests/CapabilitiesTest.php35
-rw-r--r--apps/files_trashbin/tests/Command/CleanUpTest.php134
-rw-r--r--apps/files_trashbin/tests/Command/ExpireTest.php27
-rw-r--r--apps/files_trashbin/tests/Command/ExpireTrashTest.php156
-rw-r--r--apps/files_trashbin/tests/Controller/PreviewControllerTest.php67
-rw-r--r--apps/files_trashbin/tests/ExpirationTest.php58
-rw-r--r--apps/files_trashbin/tests/Sabre/TrashbinPluginTest.php70
-rw-r--r--apps/files_trashbin/tests/StorageTest.php247
-rw-r--r--apps/files_trashbin/tests/TrashbinTest.php333
10 files changed, 606 insertions, 584 deletions
diff --git a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
index 3264c11f8fa..9468fb7add0 100644
--- a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
+++ b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
@@ -1,26 +1,10 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Victor Dubiniuk <dubiniuk@owncloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_Trashbin\Tests\BackgroundJob;
@@ -29,34 +13,28 @@ use OCA\Files_Trashbin\BackgroundJob\ExpireTrash;
use OCA\Files_Trashbin\Expiration;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
-use OCP\IConfig;
+use OCP\IAppConfig;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class ExpireTrashTest extends TestCase {
- /** @var IConfig|MockObject */
- private $config;
-
- /** @var IUserManager|MockObject */
- private $userManager;
-
- /** @var Expiration|MockObject */
- private $expiration;
-
- /** @var IJobList|MockObject */
- private $jobList;
-
- /** @var ITimeFactory|MockObject */
- private $time;
+ private IAppConfig&MockObject $appConfig;
+ private IUserManager&MockObject $userManager;
+ private Expiration&MockObject $expiration;
+ private IJobList&MockObject $jobList;
+ private LoggerInterface&MockObject $logger;
+ private ITimeFactory&MockObject $time;
protected function setUp(): void {
parent::setUp();
- $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->expiration = $this->createMock(Expiration::class);
$this->jobList = $this->createMock(IJobList::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->time = $this->createMock(ITimeFactory::class);
$this->time->method('getTime')
@@ -69,22 +47,25 @@ class ExpireTrashTest extends TestCase {
}
public function testConstructAndRun(): void {
- $this->config->method('getAppValue')
+ $this->appConfig->method('getValueString')
->with('files_trashbin', 'background_job_expire_trash', 'yes')
->willReturn('yes');
+ $this->appConfig->method('getValueInt')
+ ->with('files_trashbin', 'background_job_expire_trash_offset', 0)
+ ->willReturn(0);
- $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
+ $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
$job->start($this->jobList);
}
public function testBackgroundJobDeactivated(): void {
- $this->config->method('getAppValue')
+ $this->appConfig->method('getValueString')
->with('files_trashbin', 'background_job_expire_trash', 'yes')
->willReturn('no');
$this->expiration->expects($this->never())
->method('getMaxAgeAsTimestamp');
- $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
+ $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
$job->start($this->jobList);
}
}
diff --git a/apps/files_trashbin/tests/CapabilitiesTest.php b/apps/files_trashbin/tests/CapabilitiesTest.php
index b017b48da8c..1c460cc5665 100644
--- a/apps/files_trashbin/tests/CapabilitiesTest.php
+++ b/apps/files_trashbin/tests/CapabilitiesTest.php
@@ -1,25 +1,9 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016 Unknown <anpz.asutp@gmail.com>
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Unknown <anpz.asutp@gmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Tests;
@@ -27,19 +11,18 @@ use OCA\Files_Trashbin\Capabilities;
use Test\TestCase;
class CapabilitiesTest extends TestCase {
-
- /** @var Capabilities */
- private $capabilities;
+ private Capabilities $capabilities;
protected function setUp(): void {
parent::setUp();
$this->capabilities = new Capabilities();
}
-
- public function testGetCapabilities() {
+
+ public function testGetCapabilities(): void {
$capabilities = [
'files' => [
- 'undelete' => true
+ 'undelete' => true,
+ 'delete_from_trash' => true,
]
];
diff --git a/apps/files_trashbin/tests/Command/CleanUpTest.php b/apps/files_trashbin/tests/Command/CleanUpTest.php
index 2f582ed428b..41ed0e1e960 100644
--- a/apps/files_trashbin/tests/Command/CleanUpTest.php
+++ b/apps/files_trashbin/tests/Command/CleanUpTest.php
@@ -1,35 +1,20 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_Trashbin\Tests\Command;
-use OC\User\Manager;
use OCA\Files_Trashbin\Command\CleanUp;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
+use OCP\IUserManager;
+use OCP\Server;
+use OCP\UserInterface;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\NullOutput;
@@ -44,33 +29,19 @@ use Test\TestCase;
* @package OCA\Files_Trashbin\Tests\Command
*/
class CleanUpTest extends TestCase {
-
- /** @var CleanUp */
- protected $cleanup;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | Manager */
- protected $userManager;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | IRootFolder */
- protected $rootFolder;
-
- /** @var IDBConnection */
- protected $dbConnection;
-
- /** @var string */
- protected $trashTable = 'files_trash';
-
- /** @var string */
- protected $user0 = 'user0';
+ protected IUserManager&MockObject $userManager;
+ protected IRootFolder&MockObject $rootFolder;
+ protected IDBConnection $dbConnection;
+ protected CleanUp $cleanup;
+ protected string $trashTable = 'files_trash';
+ protected string $user0 = 'user0';
protected function setUp(): void {
parent::setUp();
- $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')
- ->disableOriginalConstructor()->getMock();
- $this->userManager = $this->getMockBuilder('OC\User\Manager')
- ->disableOriginalConstructor()->getMock();
+ $this->rootFolder = $this->createMock(IRootFolder::class);
+ $this->userManager = $this->createMock(IUserManager::class);
- $this->dbConnection = \OC::$server->getDatabaseConnection();
+ $this->dbConnection = Server::get(IDBConnection::class);
$this->cleanup = new CleanUp($this->rootFolder, $this->userManager, $this->dbConnection);
}
@@ -78,31 +49,28 @@ class CleanUpTest extends TestCase {
/**
* populate files_trash table with 10 dummy values
*/
- public function initTable() {
+ public function initTable(): void {
$query = $this->dbConnection->getQueryBuilder();
- $query->delete($this->trashTable)->execute();
+ $query->delete($this->trashTable)->executeStatement();
for ($i = 0; $i < 10; $i++) {
$query->insert($this->trashTable)
->values([
- 'id' => $query->expr()->literal('file'.$i),
+ 'id' => $query->expr()->literal('file' . $i),
'timestamp' => $query->expr()->literal($i),
'location' => $query->expr()->literal('.'),
- 'user' => $query->expr()->literal('user'.$i % 2)
- ])->execute();
+ 'user' => $query->expr()->literal('user' . $i % 2)
+ ])->executeStatement();
}
$getAllQuery = $this->dbConnection->getQueryBuilder();
$result = $getAllQuery->select('id')
->from($this->trashTable)
- ->execute()
+ ->executeQuery()
->fetchAll();
- $this->assertSame(10, count($result));
+ $this->assertCount(10, $result);
}
- /**
- * @dataProvider dataTestRemoveDeletedFiles
- * @param boolean $nodeExists
- */
- public function testRemoveDeletedFiles(bool $nodeExists) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRemoveDeletedFiles')]
+ public function testRemoveDeletedFiles(bool $nodeExists): void {
$this->initTable();
$this->rootFolder
->method('nodeExists')
@@ -119,7 +87,7 @@ class CleanUpTest extends TestCase {
$this->rootFolder->expects($this->never())->method('get');
$this->rootFolder->expects($this->never())->method('delete');
}
- $this->invokePrivate($this->cleanup, 'removeDeletedFiles', [$this->user0, new NullOutput(), false]);
+ self::invokePrivate($this->cleanup, 'removeDeletedFiles', [$this->user0, new NullOutput(), false]);
if ($nodeExists) {
// if the delete operation was executed only files from user1
@@ -128,11 +96,11 @@ class CleanUpTest extends TestCase {
$query->select('user')
->from($this->trashTable);
- $qResult = $query->execute();
+ $qResult = $query->executeQuery();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(5, count($result));
+ $this->assertCount(5, $result);
foreach ($result as $r) {
$this->assertSame('user1', $r['user']);
}
@@ -142,12 +110,12 @@ class CleanUpTest extends TestCase {
$getAllQuery = $this->dbConnection->getQueryBuilder();
$result = $getAllQuery->select('id')
->from($this->trashTable)
- ->execute()
+ ->executeQuery()
->fetchAll();
- $this->assertSame(10, count($result));
+ $this->assertCount(10, $result);
}
}
- public function dataTestRemoveDeletedFiles() {
+ public static function dataTestRemoveDeletedFiles(): array {
return [
[true],
[false]
@@ -157,21 +125,20 @@ class CleanUpTest extends TestCase {
/**
* test remove deleted files from users given as parameter
*/
- public function testExecuteDeleteListOfUsers() {
+ public function testExecuteDeleteListOfUsers(): void {
$userIds = ['user1', 'user2', 'user3'];
- $instance = $this->getMockBuilder('OCA\Files_Trashbin\Command\CleanUp')
- ->setMethods(['removeDeletedFiles'])
+ $instance = $this->getMockBuilder(CleanUp::class)
+ ->onlyMethods(['removeDeletedFiles'])
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection])
->getMock();
$instance->expects($this->exactly(count($userIds)))
->method('removeDeletedFiles')
- ->willReturnCallback(function ($user) use ($userIds) {
+ ->willReturnCallback(function ($user) use ($userIds): void {
$this->assertTrue(in_array($user, $userIds));
});
$this->userManager->expects($this->exactly(count($userIds)))
->method('userExists')->willReturn(true);
- $inputInterface = $this->getMockBuilder('\Symfony\Component\Console\Input\InputInterface')
- ->disableOriginalConstructor()->getMock();
+ $inputInterface = $this->createMock(\Symfony\Component\Console\Input\InputInterface::class);
$inputInterface->method('getArgument')
->with('user_id')
->willReturn($userIds);
@@ -180,28 +147,27 @@ class CleanUpTest extends TestCase {
['all-users', false],
['verbose', false],
]);
- $outputInterface = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')
- ->disableOriginalConstructor()->getMock();
- $this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
+ $outputInterface = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
+ self::invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
}
/**
* test remove deleted files of all users
*/
- public function testExecuteAllUsers() {
+ public function testExecuteAllUsers(): void {
$userIds = [];
$backendUsers = ['user1', 'user2'];
- $instance = $this->getMockBuilder('OCA\Files_Trashbin\Command\CleanUp')
- ->setMethods(['removeDeletedFiles'])
+ $instance = $this->getMockBuilder(CleanUp::class)
+ ->onlyMethods(['removeDeletedFiles'])
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection])
->getMock();
- $backend = $this->createMock(\OCP\UserInterface::class);
+ $backend = $this->createMock(UserInterface::class);
$backend->method('getUsers')
->with('', 500, 0)
->willReturn($backendUsers);
$instance->expects($this->exactly(count($backendUsers)))
->method('removeDeletedFiles')
- ->willReturnCallback(function ($user) use ($backendUsers) {
+ ->willReturnCallback(function ($user) use ($backendUsers): void {
$this->assertTrue(in_array($user, $backendUsers));
});
$inputInterface = $this->createMock(InputInterface::class);
@@ -217,10 +183,10 @@ class CleanUpTest extends TestCase {
$this->userManager
->method('getBackends')
->willReturn([$backend]);
- $this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
+ self::invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
}
- public function testExecuteNoUsersAndNoAllUsers() {
+ public function testExecuteNoUsersAndNoAllUsers(): void {
$inputInterface = $this->createMock(InputInterface::class);
$inputInterface->method('getArgument')
->with('user_id')
@@ -235,10 +201,10 @@ class CleanUpTest extends TestCase {
$this->expectException(InvalidOptionException::class);
$this->expectExceptionMessage('Either specify a user_id or --all-users');
- $this->invokePrivate($this->cleanup, 'execute', [$inputInterface, $outputInterface]);
+ self::invokePrivate($this->cleanup, 'execute', [$inputInterface, $outputInterface]);
}
- public function testExecuteUsersAndAllUsers() {
+ public function testExecuteUsersAndAllUsers(): void {
$inputInterface = $this->createMock(InputInterface::class);
$inputInterface->method('getArgument')
->with('user_id')
@@ -253,6 +219,6 @@ class CleanUpTest extends TestCase {
$this->expectException(InvalidOptionException::class);
$this->expectExceptionMessage('Either specify a user_id or --all-users');
- $this->invokePrivate($this->cleanup, 'execute', [$inputInterface, $outputInterface]);
+ self::invokePrivate($this->cleanup, 'execute', [$inputInterface, $outputInterface]);
}
}
diff --git a/apps/files_trashbin/tests/Command/ExpireTest.php b/apps/files_trashbin/tests/Command/ExpireTest.php
index dd9e2c2b254..5a66dac8c6e 100644
--- a/apps/files_trashbin/tests/Command/ExpireTest.php
+++ b/apps/files_trashbin/tests/Command/ExpireTest.php
@@ -1,25 +1,10 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_Trashbin\Tests\Command;
@@ -34,7 +19,7 @@ use Test\TestCase;
* @package OCA\Files_Trashbin\Tests\Command
*/
class ExpireTest extends TestCase {
- public function testExpireNonExistingUser() {
+ public function testExpireNonExistingUser(): void {
$command = new Expire('test');
$command->handle();
diff --git a/apps/files_trashbin/tests/Command/ExpireTrashTest.php b/apps/files_trashbin/tests/Command/ExpireTrashTest.php
new file mode 100644
index 00000000000..23bf0d8f121
--- /dev/null
+++ b/apps/files_trashbin/tests/Command/ExpireTrashTest.php
@@ -0,0 +1,156 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCA\Files_Trashbin\Tests\Command;
+
+use OCA\Files_Trashbin\Command\ExpireTrash;
+use OCA\Files_Trashbin\Expiration;
+use OCA\Files_Trashbin\Helper;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\IRootFolder;
+use OCP\Files\Node;
+use OCP\IConfig;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Server;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+/**
+ * Class ExpireTrashTest
+ *
+ * @group DB
+ *
+ * @package OCA\Files_Trashbin\Tests\Command
+ */
+class ExpireTrashTest extends TestCase {
+ private Expiration $expiration;
+ private Node $userFolder;
+ private IConfig $config;
+ private IUserManager $userManager;
+ private IUser $user;
+ private ITimeFactory $timeFactory;
+
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->config = Server::get(IConfig::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->expiration = Server::get(Expiration::class);
+ $this->invokePrivate($this->expiration, 'timeFactory', [$this->timeFactory]);
+
+ $userId = self::getUniqueID('user');
+ $this->userManager = Server::get(IUserManager::class);
+ $this->user = $this->userManager->createUser($userId, $userId);
+
+ $this->loginAsUser($userId);
+ $this->userFolder = Server::get(IRootFolder::class)->getUserFolder($userId);
+ }
+
+ protected function tearDown(): void {
+ $this->logout();
+
+ if (isset($this->user)) {
+ $this->user->delete();
+ }
+
+ $this->invokePrivate($this->expiration, 'timeFactory', [Server::get(ITimeFactory::class)]);
+ parent::tearDown();
+ }
+
+ /**
+ * @dataProvider retentionObligationProvider
+ */
+ public function testRetentionObligation(string $obligation, string $quota, int $elapsed, int $fileSize, bool $shouldExpire): void {
+ $this->config->setSystemValues(['trashbin_retention_obligation' => $obligation]);
+ $this->expiration->setRetentionObligation($obligation);
+
+ $this->user->setQuota($quota);
+
+ $bytes = 'ABCDEFGHIKLMNOPQRSTUVWXYZ';
+
+ $file = 'foo.txt';
+ $this->userFolder->newFile($file, substr($bytes, 0, $fileSize));
+
+ $filemtime = $this->userFolder->get($file)->getMTime();
+ $this->timeFactory->expects($this->any())
+ ->method('getTime')
+ ->willReturn($filemtime + $elapsed);
+ $this->userFolder->get($file)->delete();
+ $this->userFolder->getStorage()
+ ->getCache()
+ ->put('files_trashbin', ['size' => $fileSize, 'unencrypted_size' => $fileSize]);
+
+ $userId = $this->user->getUID();
+ $trashFiles = Helper::getTrashFiles('/', $userId);
+ $this->assertEquals(1, count($trashFiles));
+
+ $outputInterface = $this->createMock(OutputInterface::class);
+ $inputInterface = $this->createMock(InputInterface::class);
+ $inputInterface->expects($this->any())
+ ->method('getArgument')
+ ->with('user_id')
+ ->willReturn([$userId]);
+
+ $command = new ExpireTrash(
+ Server::get(LoggerInterface::class),
+ Server::get(IUserManager::class),
+ $this->expiration
+ );
+
+ $this->invokePrivate($command, 'execute', [$inputInterface, $outputInterface]);
+
+ $trashFiles = Helper::getTrashFiles('/', $userId);
+ $this->assertEquals($shouldExpire ? 0 : 1, count($trashFiles));
+ }
+
+ public function retentionObligationProvider(): array {
+ $hour = 3600; // 60 * 60
+
+ $oneDay = 24 * $hour;
+ $fiveDays = 24 * 5 * $hour;
+ $tenDays = 24 * 10 * $hour;
+ $elevenDays = 24 * 11 * $hour;
+
+ return [
+ ['disabled', '20 B', 0, 1, false],
+
+ ['auto', '20 B', 0, 5, false],
+ ['auto', '20 B', 0, 21, true],
+
+ ['0, auto', '20 B', 0, 21, true],
+ ['0, auto', '20 B', $oneDay, 5, false],
+ ['0, auto', '20 B', $oneDay, 19, true],
+ ['0, auto', '20 B', 0, 19, true],
+
+ ['auto, 0', '20 B', $oneDay, 19, true],
+ ['auto, 0', '20 B', $oneDay, 21, true],
+ ['auto, 0', '20 B', 0, 5, false],
+ ['auto, 0', '20 B', 0, 19, true],
+
+ ['1, auto', '20 B', 0, 5, false],
+ ['1, auto', '20 B', $fiveDays, 5, false],
+ ['1, auto', '20 B', $fiveDays, 21, true],
+
+ ['auto, 1', '20 B', 0, 21, true],
+ ['auto, 1', '20 B', 0, 5, false],
+ ['auto, 1', '20 B', $fiveDays, 5, true],
+ ['auto, 1', '20 B', $oneDay, 5, false],
+
+ ['2, 10', '20 B', $fiveDays, 5, false],
+ ['2, 10', '20 B', $fiveDays, 20, true],
+ ['2, 10', '20 B', $elevenDays, 5, true],
+
+ ['10, 2', '20 B', $fiveDays, 5, false],
+ ['10, 2', '20 B', $fiveDays, 21, false],
+ ['10, 2', '20 B', $tenDays, 5, false],
+ ['10, 2', '20 B', $elevenDays, 5, true]
+ ];
+ }
+}
diff --git a/apps/files_trashbin/tests/Controller/PreviewControllerTest.php b/apps/files_trashbin/tests/Controller/PreviewControllerTest.php
index 3b114484c7f..bb951c9c8c7 100644
--- a/apps/files_trashbin/tests/Controller/PreviewControllerTest.php
+++ b/apps/files_trashbin/tests/Controller/PreviewControllerTest.php
@@ -1,26 +1,9 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Trashbin\Tests\Controller;
@@ -39,32 +22,18 @@ use OCP\IPreview;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class PreviewControllerTest extends TestCase {
- /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
- private $rootFolder;
-
- /** @var string */
- private $userId;
-
- /** @var IMimeTypeDetector|\PHPUnit\Framework\MockObject\MockObject */
- private $mimeTypeDetector;
-
- /** @var IPreview|\PHPUnit\Framework\MockObject\MockObject */
- private $previewManager;
-
- /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $time;
-
- /** @var PreviewController */
- private $controller;
-
- /** @var ITrashManager|\PHPUnit\Framework\MockObject\MockObject */
- private $trashManager;
-
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- private $userSession;
+ private IRootFolder&MockObject $rootFolder;
+ private string $userId;
+ private IMimeTypeDetector&MockObject $mimeTypeDetector;
+ private IPreview&MockObject $previewManager;
+ private ITimeFactory&MockObject $time;
+ private ITrashManager&MockObject $trashManager;
+ private IUserSession&MockObject $userSession;
+ private PreviewController $controller;
protected function setUp(): void {
parent::setUp();
@@ -97,21 +66,21 @@ class PreviewControllerTest extends TestCase {
);
}
- public function testInvalidWidth() {
+ public function testInvalidWidth(): void {
$res = $this->controller->getPreview(42, 0);
$expected = new DataResponse([], Http::STATUS_BAD_REQUEST);
$this->assertEquals($expected, $res);
}
- public function testInvalidHeight() {
+ public function testInvalidHeight(): void {
$res = $this->controller->getPreview(42, 10, 0);
$expected = new DataResponse([], Http::STATUS_BAD_REQUEST);
$this->assertEquals($expected, $res);
}
- public function testValidPreview() {
+ public function testValidPreview(): void {
$userFolder = $this->createMock(Folder::class);
$userRoot = $this->createMock(Folder::class);
$trash = $this->createMock(Folder::class);
@@ -164,7 +133,7 @@ class PreviewControllerTest extends TestCase {
$this->assertEquals($expected, $res);
}
- public function testTrashFileNotFound() {
+ public function testTrashFileNotFound(): void {
$userFolder = $this->createMock(Folder::class);
$userRoot = $this->createMock(Folder::class);
$trash = $this->createMock(Folder::class);
@@ -188,7 +157,7 @@ class PreviewControllerTest extends TestCase {
$this->assertEquals($expected, $res);
}
- public function testTrashFolder() {
+ public function testTrashFolder(): void {
$userFolder = $this->createMock(Folder::class);
$userRoot = $this->createMock(Folder::class);
$trash = $this->createMock(Folder::class);
diff --git a/apps/files_trashbin/tests/ExpirationTest.php b/apps/files_trashbin/tests/ExpirationTest.php
index b8f37a890b7..3348edc4016 100644
--- a/apps/files_trashbin/tests/ExpirationTest.php
+++ b/apps/files_trashbin/tests/ExpirationTest.php
@@ -1,27 +1,10 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Victor Dubiniuk <dubiniuk@owncloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_Trashbin\Tests;
@@ -35,7 +18,7 @@ class ExpirationTest extends \Test\TestCase {
public const FAKE_TIME_NOW = 1000000;
- public function expirationData() {
+ public static function expirationData(): array {
$today = 100 * self::SECONDS_PER_DAY;
$back10Days = (100 - 10) * self::SECONDS_PER_DAY;
$back20Days = (100 - 20) * self::SECONDS_PER_DAY;
@@ -99,16 +82,8 @@ class ExpirationTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider expirationData
- *
- * @param string $retentionObligation
- * @param int $timeNow
- * @param int $timestamp
- * @param bool $quotaExceeded
- * @param string $expectedResult
- */
- public function testExpiration($retentionObligation, $timeNow, $timestamp, $quotaExceeded, $expectedResult) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('expirationData')]
+ public function testExpiration(string $retentionObligation, int $timeNow, int $timestamp, bool $quotaExceeded, bool $expectedResult): void {
$mockedConfig = $this->getMockedConfig($retentionObligation);
$mockedTimeFactory = $this->getMockedTimeFactory($timeNow);
@@ -119,7 +94,7 @@ class ExpirationTest extends \Test\TestCase {
}
- public function timestampTestData(): array {
+ public static function timestampTestData(): array {
return [
[ 'disabled', false],
[ 'auto', false ],
@@ -133,13 +108,8 @@ class ExpirationTest extends \Test\TestCase {
}
- /**
- * @dataProvider timestampTestData
- *
- * @param string $configValue
- * @param int $expectedMaxAgeTimestamp
- */
- public function testGetMaxAgeAsTimestamp($configValue, $expectedMaxAgeTimestamp) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('timestampTestData')]
+ public function testGetMaxAgeAsTimestamp(string $configValue, bool|int $expectedMaxAgeTimestamp): void {
$mockedConfig = $this->getMockedConfig($configValue);
$mockedTimeFactory = $this->getMockedTimeFactory(
self::FAKE_TIME_NOW
@@ -151,10 +121,9 @@ class ExpirationTest extends \Test\TestCase {
}
/**
- * @param int $time
* @return ITimeFactory|MockObject
*/
- private function getMockedTimeFactory($time) {
+ private function getMockedTimeFactory(int $time) {
$mockedTimeFactory = $this->createMock(ITimeFactory::class);
$mockedTimeFactory->expects($this->any())
->method('getTime')
@@ -164,10 +133,9 @@ class ExpirationTest extends \Test\TestCase {
}
/**
- * @param string $returnValue
* @return IConfig|MockObject
*/
- private function getMockedConfig($returnValue) {
+ private function getMockedConfig(string $returnValue) {
$mockedConfig = $this->createMock(IConfig::class);
$mockedConfig->expects($this->any())
->method('getSystemValue')
diff --git a/apps/files_trashbin/tests/Sabre/TrashbinPluginTest.php b/apps/files_trashbin/tests/Sabre/TrashbinPluginTest.php
new file mode 100644
index 00000000000..87aca2753ef
--- /dev/null
+++ b/apps/files_trashbin/tests/Sabre/TrashbinPluginTest.php
@@ -0,0 +1,70 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\Files_Trashbin\Tests\Sabre;
+
+use OC\Files\FileInfo;
+use OC\Files\View;
+use OCA\Files_Trashbin\Sabre\ITrash;
+use OCA\Files_Trashbin\Sabre\RestoreFolder;
+use OCA\Files_Trashbin\Sabre\TrashbinPlugin;
+use OCA\Files_Trashbin\Trash\ITrashItem;
+use OCP\IPreview;
+use Sabre\DAV\Server;
+use Sabre\DAV\Tree;
+use Test\TestCase;
+
+class TrashbinPluginTest extends TestCase {
+ private Server $server;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $tree = $this->createMock(Tree::class);
+ $this->server = new Server($tree);
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('quotaProvider')]
+ public function testQuota(int $quota, int $fileSize, bool $expectedResult): void {
+ $fileInfo = $this->createMock(ITrashItem::class);
+ $fileInfo->method('getSize')
+ ->willReturn($fileSize);
+
+ $trashNode = $this->createMock(ITrash::class);
+ $trashNode->method('getFileInfo')
+ ->willReturn($fileInfo);
+
+ $restoreNode = $this->createMock(RestoreFolder::class);
+
+ $this->server->tree->method('getNodeForPath')
+ ->willReturn($trashNode, $restoreNode);
+
+ $previewManager = $this->createMock(IPreview::class);
+
+ $view = $this->createMock(View::class);
+ $view->method('free_space')
+ ->willReturn($quota);
+
+ $plugin = new TrashbinPlugin($previewManager, $view);
+ $plugin->initialize($this->server);
+
+ $sourcePath = 'trashbin/test/trash/file1';
+ $destinationPath = 'trashbin/test/restore/file1';
+ $this->assertEquals($expectedResult, $plugin->beforeMove($sourcePath, $destinationPath));
+ }
+
+ public static function quotaProvider(): array {
+ return [
+ [ 1024, 512, true ],
+ [ 512, 513, false ],
+ [ FileInfo::SPACE_NOT_COMPUTED, 1024, true ],
+ [ FileInfo::SPACE_UNKNOWN, 1024, true ],
+ [ FileInfo::SPACE_UNLIMITED, 1024, true ]
+ ];
+ }
+}
diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php
index 59bd7e0f5ef..c58ddec97dd 100644
--- a/apps/files_trashbin/tests/StorageTest.php
+++ b/apps/files_trashbin/tests/StorageTest.php
@@ -1,46 +1,24 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Stefan Weil <sw@weilnetz.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_Trashbin\Tests;
use OC\Files\Filesystem;
use OC\Files\Storage\Common;
-use OC\Files\Storage\Local;
use OC\Files\Storage\Temporary;
+use OC\Files\View;
use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Events\MoveToTrashEvent;
use OCA\Files_Trashbin\Storage;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICache;
use OCP\Files\Folder;
@@ -49,16 +27,18 @@ use OCP\Files\Node;
use OCP\Files\Storage\IStorage;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
+use OCP\Server;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\Traits\MountProviderTrait;
class TemporaryNoCross extends Temporary {
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null) {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, ?bool $preserveMtime = null): bool {
return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime);
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
}
@@ -73,20 +53,9 @@ class TemporaryNoCross extends Temporary {
class StorageTest extends \Test\TestCase {
use MountProviderTrait;
- /**
- * @var string
- */
- private $user;
-
- /**
- * @var \OC\Files\View
- */
- private $rootView;
-
- /**
- * @var \OC\Files\View
- */
- private $userView;
+ private string $user;
+ private View $rootView;
+ private View $userView;
// 239 chars so appended timestamp of 12 chars will exceed max length of 250 chars
private const LONG_FILENAME = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
@@ -104,15 +73,15 @@ class StorageTest extends \Test\TestCase {
$trashbinApp->boot($this->createMock(IBootContext::class));
$this->user = $this->getUniqueId('user');
- \OC::$server->getUserManager()->createUser($this->user, $this->user);
+ Server::get(IUserManager::class)->createUser($this->user, $this->user);
// this will setup the FS
$this->loginAsUser($this->user);
- \OCA\Files_Trashbin\Storage::setupStorage();
+ Storage::setupStorage();
- $this->rootView = new \OC\Files\View('/');
- $this->userView = new \OC\Files\View('/' . $this->user . '/files/');
+ $this->rootView = new View('/');
+ $this->userView = new View('/' . $this->user . '/files/');
$this->userView->file_put_contents('test.txt', 'foo');
$this->userView->file_put_contents(static::LONG_FILENAME, 'foo');
$this->userView->file_put_contents(static::MAX_FILENAME, 'foo');
@@ -122,9 +91,9 @@ class StorageTest extends \Test\TestCase {
}
protected function tearDown(): void {
- \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
+ Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
$this->logout();
- $user = \OC::$server->getUserManager()->get($this->user);
+ $user = Server::get(IUserManager::class)->get($this->user);
if ($user !== null) {
$user->delete();
}
@@ -135,7 +104,7 @@ class StorageTest extends \Test\TestCase {
/**
* Test that deleting a file puts it into the trashbin.
*/
- public function testSingleStorageDeleteFile() {
+ public function testSingleStorageDeleteFile(): void {
$this->assertTrue($this->userView->file_exists('test.txt'));
$this->userView->unlink('test.txt');
[$storage,] = $this->userView->resolvePath('test.txt');
@@ -144,7 +113,7 @@ class StorageTest extends \Test\TestCase {
// check if file is in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('test.txt', substr($name, 0, strrpos($name, '.')));
}
@@ -152,7 +121,7 @@ class StorageTest extends \Test\TestCase {
/**
* Test that deleting a folder puts it into the trashbin.
*/
- public function testSingleStorageDeleteFolder() {
+ public function testSingleStorageDeleteFolder(): void {
$this->assertTrue($this->userView->file_exists('folder/inside.txt'));
$this->userView->rmdir('folder');
[$storage,] = $this->userView->resolvePath('folder/inside.txt');
@@ -161,7 +130,7 @@ class StorageTest extends \Test\TestCase {
// check if folder is in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('folder', substr($name, 0, strrpos($name, '.')));
@@ -174,7 +143,7 @@ class StorageTest extends \Test\TestCase {
/**
* Test that deleting a file with a long filename puts it into the trashbin.
*/
- public function testSingleStorageDeleteLongFilename() {
+ public function testSingleStorageDeleteLongFilename(): void {
$truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
$this->assertTrue($this->userView->file_exists(static::LONG_FILENAME));
@@ -185,7 +154,7 @@ class StorageTest extends \Test\TestCase {
// check if file is in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals($truncatedFilename, substr($name, 0, strrpos($name, '.')));
}
@@ -193,7 +162,7 @@ class StorageTest extends \Test\TestCase {
/**
* Test that deleting a file with the max filename length puts it into the trashbin.
*/
- public function testSingleStorageDeleteMaxLengthFilename() {
+ public function testSingleStorageDeleteMaxLengthFilename(): void {
$truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
$this->assertTrue($this->userView->file_exists(static::MAX_FILENAME));
@@ -204,7 +173,7 @@ class StorageTest extends \Test\TestCase {
// check if file is in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals($truncatedFilename, substr($name, 0, strrpos($name, '.')));
}
@@ -215,9 +184,9 @@ class StorageTest extends \Test\TestCase {
* the trashbin folder is in the root storage while the mounted one
* isn't.
*/
- public function testCrossStorageDeleteFile() {
+ public function testCrossStorageDeleteFile(): void {
$storage2 = new Temporary([]);
- \OC\Files\Filesystem::mount($storage2, [], $this->user . '/files/substorage');
+ Filesystem::mount($storage2, [], $this->user . '/files/substorage');
$this->userView->file_put_contents('substorage/subfile.txt', 'foo');
$storage2->getScanner()->scan('');
@@ -230,7 +199,7 @@ class StorageTest extends \Test\TestCase {
// check if file is in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('subfile.txt', substr($name, 0, strrpos($name, '.')));
}
@@ -241,9 +210,9 @@ class StorageTest extends \Test\TestCase {
* the trashbin folder is in the root storage while the mounted one
* isn't.
*/
- public function testCrossStorageDeleteFolder() {
+ public function testCrossStorageDeleteFolder(): void {
$storage2 = new Temporary([]);
- \OC\Files\Filesystem::mount($storage2, [], $this->user . '/files/substorage');
+ Filesystem::mount($storage2, [], $this->user . '/files/substorage');
$this->userView->mkdir('substorage/folder');
$this->userView->file_put_contents('substorage/folder/subfile.txt', 'bar');
@@ -257,12 +226,12 @@ class StorageTest extends \Test\TestCase {
// check if folder is in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('folder', substr($name, 0, strrpos($name, '.')));
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/' . $name . '/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('subfile.txt', $name);
}
@@ -270,7 +239,7 @@ class StorageTest extends \Test\TestCase {
/**
* Test that deleted versions properly land in the trashbin.
*/
- public function testDeleteVersionsOfFile() {
+ public function testDeleteVersionsOfFile(): void {
// trigger a version (multiple would not work because of the expire logic)
$this->userView->file_put_contents('test.txt', 'v1');
@@ -285,24 +254,24 @@ class StorageTest extends \Test\TestCase {
// check if versions are in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('test.txt.v', substr($name, 0, strlen('test.txt.v')));
// versions deleted
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
}
/**
* Test that deleted versions properly land in the trashbin.
*/
- public function testDeleteVersionsOfFolder() {
+ public function testDeleteVersionsOfFolder(): void {
// trigger a version (multiple would not work because of the expire logic)
$this->userView->file_put_contents('folder/inside.txt', 'v1');
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/folder/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$this->userView->rmdir('folder');
@@ -312,50 +281,50 @@ class StorageTest extends \Test\TestCase {
// check if versions are in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('folder.d', substr($name, 0, strlen('folder.d')));
// check if versions are in trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions/' . $name . '/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('inside.txt.v', substr($name, 0, strlen('inside.txt.v')));
// versions deleted
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/folder/');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
}
/**
* Test that deleted versions properly land in the trashbin when deleting as share recipient.
*/
- public function testDeleteVersionsOfFileAsRecipient() {
+ public function testDeleteVersionsOfFileAsRecipient(): void {
$this->userView->mkdir('share');
// trigger a version (multiple would not work because of the expire logic)
$this->userView->file_put_contents('share/test.txt', 'v1');
$this->userView->file_put_contents('share/test.txt', 'v2');
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/share/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$recipientUser = $this->getUniqueId('recipient_');
- \OC::$server->getUserManager()->createUser($recipientUser, $recipientUser);
+ Server::get(IUserManager::class)->createUser($recipientUser, $recipientUser);
- $node = \OC::$server->getUserFolder($this->user)->get('share');
- $share = \OC::$server->getShareManager()->newShare();
+ $node = Server::get(IRootFolder::class)->getUserFolder($this->user)->get('share');
+ $share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedBy($this->user)
->setSharedWith($recipientUser)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
- $share = \OC::$server->getShareManager()->createShare($share);
- \OC::$server->getShareManager()->acceptShare($share, $recipientUser);
+ ->setPermissions(Constants::PERMISSION_ALL);
+ $share = Server::get(\OCP\Share\IManager::class)->createShare($share);
+ Server::get(\OCP\Share\IManager::class)->acceptShare($share, $recipientUser);
$this->loginAsUser($recipientUser);
// delete as recipient
- $recipientView = new \OC\Files\View('/' . $recipientUser . '/files');
+ $recipientView = new View('/' . $recipientUser . '/files');
$recipientView->unlink('share/test.txt');
// rescan trash storage for both users
@@ -364,24 +333,24 @@ class StorageTest extends \Test\TestCase {
// check if versions are in trashbin for both users
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions');
- $this->assertEquals(1, count($results), 'Versions in owner\'s trashbin');
+ $this->assertCount(1, $results, 'Versions in owner\'s trashbin');
$name = $results[0]->getName();
$this->assertEquals('test.txt.v', substr($name, 0, strlen('test.txt.v')));
$results = $this->rootView->getDirectoryContent($recipientUser . '/files_trashbin/versions');
- $this->assertEquals(1, count($results), 'Versions in recipient\'s trashbin');
+ $this->assertCount(1, $results, 'Versions in recipient\'s trashbin');
$name = $results[0]->getName();
$this->assertEquals('test.txt.v', substr($name, 0, strlen('test.txt.v')));
// versions deleted
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/share/');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
}
/**
* Test that deleted versions properly land in the trashbin when deleting as share recipient.
*/
- public function testDeleteVersionsOfFolderAsRecipient() {
+ public function testDeleteVersionsOfFolderAsRecipient(): void {
$this->userView->mkdir('share');
$this->userView->mkdir('share/folder');
// trigger a version (multiple would not work because of the expire logic)
@@ -389,25 +358,24 @@ class StorageTest extends \Test\TestCase {
$this->userView->file_put_contents('share/folder/test.txt', 'v2');
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/share/folder/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$recipientUser = $this->getUniqueId('recipient_');
- \OC::$server->getUserManager()->createUser($recipientUser, $recipientUser);
-
- $node = \OC::$server->getUserFolder($this->user)->get('share');
- $share = \OC::$server->getShareManager()->newShare();
+ Server::get(IUserManager::class)->createUser($recipientUser, $recipientUser);
+ $node = Server::get(IRootFolder::class)->getUserFolder($this->user)->get('share');
+ $share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedBy($this->user)
->setSharedWith($recipientUser)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
- $share = \OC::$server->getShareManager()->createShare($share);
- \OC::$server->getShareManager()->acceptShare($share, $recipientUser);
+ ->setPermissions(Constants::PERMISSION_ALL);
+ $share = Server::get(\OCP\Share\IManager::class)->createShare($share);
+ Server::get(\OCP\Share\IManager::class)->acceptShare($share, $recipientUser);
$this->loginAsUser($recipientUser);
// delete as recipient
- $recipientView = new \OC\Files\View('/' . $recipientUser . '/files');
+ $recipientView = new View('/' . $recipientUser . '/files');
$recipientView->rmdir('share/folder');
// rescan trash storage
@@ -416,31 +384,31 @@ class StorageTest extends \Test\TestCase {
// check if versions are in trashbin for owner
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('folder.d', substr($name, 0, strlen('folder.d')));
// check if file versions are in trashbin for owner
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions/' . $name . '/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('test.txt.v', substr($name, 0, strlen('test.txt.v')));
// check if versions are in trashbin for recipient
$results = $this->rootView->getDirectoryContent($recipientUser . '/files_trashbin/versions');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('folder.d', substr($name, 0, strlen('folder.d')));
// check if file versions are in trashbin for recipient
$results = $this->rootView->getDirectoryContent($recipientUser . '/files_trashbin/versions/' . $name . '/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$name = $results[0]->getName();
$this->assertEquals('test.txt.v', substr($name, 0, strlen('test.txt.v')));
// versions deleted
$results = $this->rootView->getDirectoryContent($recipientUser . '/files_versions/share/folder/');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
}
/**
@@ -448,18 +416,18 @@ class StorageTest extends \Test\TestCase {
* storages. This is because rename() between storages would call
* unlink() which should NOT trigger the version deletion logic.
*/
- public function testKeepFileAndVersionsWhenMovingFileBetweenStorages() {
+ public function testKeepFileAndVersionsWhenMovingFileBetweenStorages(): void {
$storage2 = new Temporary([]);
- \OC\Files\Filesystem::mount($storage2, [], $this->user . '/files/substorage');
+ Filesystem::mount($storage2, [], $this->user . '/files/substorage');
// trigger a version (multiple would not work because of the expire logic)
$this->userView->file_put_contents('test.txt', 'v1');
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
// move to another storage
$this->userView->rename('test.txt', 'substorage/test.txt');
@@ -471,15 +439,15 @@ class StorageTest extends \Test\TestCase {
// versions were moved too
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/substorage');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
// check that nothing got trashed by the rename's unlink() call
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
// check that versions were moved and not trashed
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions/');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
}
/**
@@ -487,18 +455,18 @@ class StorageTest extends \Test\TestCase {
* storages. This is because rename() between storages would call
* unlink() which should NOT trigger the version deletion logic.
*/
- public function testKeepFileAndVersionsWhenMovingFolderBetweenStorages() {
+ public function testKeepFileAndVersionsWhenMovingFolderBetweenStorages(): void {
$storage2 = new Temporary([]);
- \OC\Files\Filesystem::mount($storage2, [], $this->user . '/files/substorage');
+ Filesystem::mount($storage2, [], $this->user . '/files/substorage');
// trigger a version (multiple would not work because of the expire logic)
$this->userView->file_put_contents('folder/inside.txt', 'v1');
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/folder/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
// move to another storage
$this->userView->rename('folder', 'substorage/folder');
@@ -510,27 +478,27 @@ class StorageTest extends \Test\TestCase {
// versions were moved too
$results = $this->rootView->getDirectoryContent($this->user . '/files_versions/substorage/folder/');
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
// check that nothing got trashed by the rename's unlink() call
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
// check that versions were moved and not trashed
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions/');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
}
/**
* Delete should fail if the source file can't be deleted.
*/
- public function testSingleStorageDeleteFileFail() {
+ public function testSingleStorageDeleteFileFail(): void {
/**
- * @var \OC\Files\Storage\Temporary | \PHPUnit\Framework\MockObject\MockObject $storage
+ * @var Temporary&MockObject $storage
*/
- $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
+ $storage = $this->getMockBuilder(Temporary::class)
->setConstructorArgs([[]])
- ->setMethods(['rename', 'unlink', 'moveFromStorage'])
+ ->onlyMethods(['rename', 'unlink', 'moveFromStorage'])
->getMock();
$storage->expects($this->any())
@@ -555,19 +523,19 @@ class StorageTest extends \Test\TestCase {
// file should not be in the trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
}
/**
* Delete should fail if the source folder can't be deleted.
*/
- public function testSingleStorageDeleteFolderFail() {
+ public function testSingleStorageDeleteFolderFail(): void {
/**
- * @var \OC\Files\Storage\Temporary | \PHPUnit\Framework\MockObject\MockObject $storage
+ * @var Temporary&MockObject $storage
*/
- $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
+ $storage = $this->getMockBuilder(Temporary::class)
->setConstructorArgs([[]])
- ->setMethods(['rename', 'unlink', 'rmdir'])
+ ->onlyMethods(['rename', 'unlink', 'rmdir'])
->getMock();
$storage->expects($this->any())
@@ -589,18 +557,15 @@ class StorageTest extends \Test\TestCase {
// file should not be in the trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
- $this->assertEquals(0, count($results));
+ $this->assertCount(0, $results);
}
- /**
- * @dataProvider dataTestShouldMoveToTrash
- */
- public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisablesTrash, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestShouldMoveToTrash')]
+ public function testShouldMoveToTrash(string $mountPoint, string $path, bool $userExists, bool $appDisablesTrash, bool $expected): void {
$fileID = 1;
$cache = $this->createMock(ICache::class);
$cache->expects($this->any())->method('getId')->willReturn($fileID);
- $tmpStorage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
- ->disableOriginalConstructor()->getMock($cache);
+ $tmpStorage = $this->createMock(Temporary::class);
$tmpStorage->expects($this->any())->method('getCache')->willReturn($cache);
$userManager = $this->getMockBuilder(IUserManager::class)
->disableOriginalConstructor()->getMock();
@@ -616,6 +581,7 @@ class StorageTest extends \Test\TestCase {
$event->expects($this->any())->method('shouldMoveToTrashBin')->willReturn(!$appDisablesTrash);
$userFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]);
+ $rootFolder->expects($this->any())->method('getById')->with($fileID)->willReturn([$node]);
$rootFolder->expects($this->any())->method('getUserFolder')->willReturn($userFolder);
$storage = $this->getMockBuilder(Storage::class)
@@ -628,7 +594,9 @@ class StorageTest extends \Test\TestCase {
$eventDispatcher,
$rootFolder
]
- )->setMethods(['createMoveToTrashEvent'])->getMock();
+ )
+ ->onlyMethods(['createMoveToTrashEvent'])
+ ->getMock();
$storage->expects($this->any())->method('createMoveToTrashEvent')->with($node)
->willReturn($event);
@@ -638,7 +606,7 @@ class StorageTest extends \Test\TestCase {
);
}
- public function dataTestShouldMoveToTrash() {
+ public static function dataTestShouldMoveToTrash(): array {
return [
['/schiesbn/', '/files/test.txt', true, false, true],
['/schiesbn/', '/files/test.txt', false, false, false],
@@ -653,7 +621,7 @@ class StorageTest extends \Test\TestCase {
/**
* Test that deleting a file doesn't error when nobody is logged in
*/
- public function testSingleStorageDeleteFileLoggedOut() {
+ public function testSingleStorageDeleteFileLoggedOut(): void {
$this->logout();
if (!$this->userView->file_exists('test.txt')) {
@@ -664,7 +632,7 @@ class StorageTest extends \Test\TestCase {
}
}
- public function testTrashbinCollision() {
+ public function testTrashbinCollision(): void {
$this->userView->file_put_contents('test.txt', 'foo');
$this->userView->file_put_contents('folder/test.txt', 'bar');
@@ -672,7 +640,7 @@ class StorageTest extends \Test\TestCase {
$timeFactory->method('getTime')
->willReturn(1000);
- $lockingProvider = \OC::$server->getLockingProvider();
+ $lockingProvider = Server::get(ILockingProvider::class);
$this->overwriteService(ITimeFactory::class, $timeFactory);
@@ -696,16 +664,13 @@ class StorageTest extends \Test\TestCase {
$this->assertEquals('bar', $this->rootView->file_get_contents($this->user . '/files_trashbin/files/test.txt.d1001'));
}
- public function testMoveFromStoragePreserveFileId() {
- if (!$this->userView->getMount('')->getStorage()->instanceOfStorage(Local::class)) {
- $this->markTestSkipped("Skipping on non-local users storage");
- }
+ public function testMoveFromStoragePreserveFileId(): void {
$this->userView->file_put_contents('test.txt', 'foo');
$fileId = $this->userView->getFileInfo('test.txt')->getId();
$externalStorage = new TemporaryNoCross([]);
$externalStorage->getScanner()->scan('');
- Filesystem::mount($externalStorage, [], "/" . $this->user . "/files/storage");
+ Filesystem::mount($externalStorage, [], '/' . $this->user . '/files/storage');
$this->assertTrue($this->userView->rename('test.txt', 'storage/test.txt'));
$this->assertTrue($externalStorage->file_exists('test.txt'));
diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php
index 1df93bccb4a..6104a242104 100644
--- a/apps/files_trashbin/tests/TrashbinTest.php
+++ b/apps/files_trashbin/tests/TrashbinTest.php
@@ -1,38 +1,34 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Tobia De Koninck <tobia@ledfan.be>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
+use OC\AllConfig;
use OC\AppFramework\Bootstrap\BootContext;
use OC\AppFramework\DependencyInjection\DIContainer;
+use OC\Files\Cache\Watcher;
+use OC\Files\Filesystem;
+use OC\Files\Storage\Local;
+use OC\Files\View;
+use OC\SystemConfig;
+use OC\User\Database;
use OCA\Files_Sharing\AppInfo\Application;
use OCA\Files_Trashbin\AppInfo\Application as TrashbinApplication;
+use OCA\Files_Trashbin\Expiration;
+use OCA\Files_Trashbin\Helper;
+use OCA\Files_Trashbin\Trashbin;
+use OCP\App\IAppManager;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Constants;
+use OCP\Files\FileInfo;
+use OCP\Files\IRootFolder;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\IUserManager;
+use OCP\Server;
use OCP\Share\IShare;
/**
@@ -41,49 +37,41 @@ use OCP\Share\IShare;
* @group DB
*/
class TrashbinTest extends \Test\TestCase {
- public const TEST_TRASHBIN_USER1 = "test-trashbin-user1";
- public const TEST_TRASHBIN_USER2 = "test-trashbin-user2";
+ public const TEST_TRASHBIN_USER1 = 'test-trashbin-user1';
+ public const TEST_TRASHBIN_USER2 = 'test-trashbin-user2';
private $trashRoot1;
private $trashRoot2;
private static $rememberRetentionObligation;
-
- /**
- * @var bool
- */
- private static $trashBinStatus;
-
- /**
- * @var \OC\Files\View
- */
- private $rootView;
+ private static bool $trashBinStatus;
+ private View $rootView;
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
- $appManager = \OC::$server->getAppManager();
+ $appManager = Server::get(IAppManager::class);
self::$trashBinStatus = $appManager->isEnabledForUser('files_trashbin');
// reset backend
- \OC_User::clearBackends();
- \OC_User::useBackend('database');
+ Server::get(IUserManager::class)->clearBackends();
+ Server::get(IUserManager::class)->registerBackend(new Database());
// clear share hooks
\OC_Hook::clear('OCP\\Share');
- \OC::registerShareHooks(\OC::$server->getSystemConfig());
+ \OC::registerShareHooks(Server::get(SystemConfig::class));
// init files sharing
new Application();
//disable encryption
- \OC::$server->getAppManager()->disableApp('encryption');
+ Server::get(IAppManager::class)->disableApp('encryption');
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
//configure trashbin
- self::$rememberRetentionObligation = $config->getSystemValue('trashbin_retention_obligation', \OCA\Files_Trashbin\Expiration::DEFAULT_RETENTION_OBLIGATION);
- /** @var \OCA\Files_Trashbin\Expiration $expiration */
- $expiration = \OC::$server->query(\OCA\Files_Trashbin\Expiration::class);
+ self::$rememberRetentionObligation = (string)$config->getSystemValue('trashbin_retention_obligation', Expiration::DEFAULT_RETENTION_OBLIGATION);
+ /** @var Expiration $expiration */
+ $expiration = Server::get(Expiration::class);
$expiration->setRetentionObligation('auto, 2');
// register trashbin hooks
@@ -98,21 +86,21 @@ class TrashbinTest extends \Test\TestCase {
public static function tearDownAfterClass(): void {
// cleanup test user
- $user = \OC::$server->getUserManager()->get(self::TEST_TRASHBIN_USER1);
+ $user = Server::get(IUserManager::class)->get(self::TEST_TRASHBIN_USER1);
if ($user !== null) {
$user->delete();
}
- /** @var \OCA\Files_Trashbin\Expiration $expiration */
- $expiration = \OC::$server->query(\OCA\Files_Trashbin\Expiration::class);
+ /** @var Expiration $expiration */
+ $expiration = Server::get(Expiration::class);
$expiration->setRetentionObligation(self::$rememberRetentionObligation);
\OC_Hook::clear();
- \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
+ Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
if (self::$trashBinStatus) {
- \OC::$server->getAppManager()->enableApp('files_trashbin');
+ Server::get(IAppManager::class)->enableApp('files_trashbin');
}
parent::tearDownAfterClass();
@@ -121,40 +109,33 @@ class TrashbinTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- \OC::$server->getAppManager()->enableApp('files_trashbin');
- $config = \OC::$server->getConfig();
- $mockConfig = $this->createMock(\OCP\IConfig::class);
- $mockConfig
+ Server::get(IAppManager::class)->enableApp('files_trashbin');
+ $config = Server::get(IConfig::class);
+ $mockConfig = $this->getMockBuilder(AllConfig::class)
+ ->onlyMethods(['getSystemValue'])
+ ->setConstructorArgs([Server::get(SystemConfig::class)])
+ ->getMock();
+ $mockConfig->expects($this->any())
->method('getSystemValue')
->willReturnCallback(static function ($key, $default) use ($config) {
if ($key === 'filesystem_check_changes') {
- return \OC\Files\Cache\Watcher::CHECK_ONCE;
+ return Watcher::CHECK_ONCE;
} else {
return $config->getSystemValue($key, $default);
}
});
- $mockConfig
- ->method('getUserValue')
- ->willReturnCallback(static function ($userId, $appName, $key, $default = '') use ($config) {
- return $config->getUserValue($userId, $appName, $key, $default);
- });
- $mockConfig
- ->method('getAppValue')
- ->willReturnCallback(static function ($appName, $key, $default = '') use ($config) {
- return $config->getAppValue($appName, $key, $default);
- });
- $this->overwriteService(\OC\AllConfig::class, $mockConfig);
+ $this->overwriteService(AllConfig::class, $mockConfig);
$this->trashRoot1 = '/' . self::TEST_TRASHBIN_USER1 . '/files_trashbin';
$this->trashRoot2 = '/' . self::TEST_TRASHBIN_USER2 . '/files_trashbin';
- $this->rootView = new \OC\Files\View();
+ $this->rootView = new View();
self::loginHelper(self::TEST_TRASHBIN_USER1);
}
protected function tearDown(): void {
- $this->restoreService(\OC\AllConfig::class);
+ $this->restoreService(AllConfig::class);
// disable trashbin to be able to properly clean up
- \OC::$server->getAppManager()->disableApp('files_trashbin');
+ Server::get(IAppManager::class)->disableApp('files_trashbin');
$this->rootView->deleteAll('/' . self::TEST_TRASHBIN_USER1 . '/files');
$this->rootView->deleteAll('/' . self::TEST_TRASHBIN_USER2 . '/files');
@@ -162,7 +143,7 @@ class TrashbinTest extends \Test\TestCase {
$this->rootView->deleteAll($this->trashRoot2);
// clear trash table
- $connection = \OC::$server->getDatabaseConnection();
+ $connection = Server::get(IDBConnection::class);
$connection->executeUpdate('DELETE FROM `*PREFIX*files_trash`');
parent::tearDown();
@@ -171,26 +152,26 @@ class TrashbinTest extends \Test\TestCase {
/**
* test expiration of files older then the max storage time defined for the trash
*/
- public function testExpireOldFiles() {
+ public function testExpireOldFiles(): void {
- /** @var \OCP\AppFramework\Utility\ITimeFactory $time */
- $time = \OC::$server->query(\OCP\AppFramework\Utility\ITimeFactory::class);
+ /** @var ITimeFactory $time */
+ $time = Server::get(ITimeFactory::class);
$currentTime = $time->getTime();
$expireAt = $currentTime - 2 * 24 * 60 * 60;
$expiredDate = $currentTime - 3 * 24 * 60 * 60;
// create some files
- \OC\Files\Filesystem::file_put_contents('file1.txt', 'file1');
- \OC\Files\Filesystem::file_put_contents('file2.txt', 'file2');
- \OC\Files\Filesystem::file_put_contents('file3.txt', 'file3');
+ Filesystem::file_put_contents('file1.txt', 'file1');
+ Filesystem::file_put_contents('file2.txt', 'file2');
+ Filesystem::file_put_contents('file3.txt', 'file3');
// delete them so that they end up in the trash bin
- \OC\Files\Filesystem::unlink('file1.txt');
- \OC\Files\Filesystem::unlink('file2.txt');
- \OC\Files\Filesystem::unlink('file3.txt');
+ Filesystem::unlink('file1.txt');
+ Filesystem::unlink('file2.txt');
+ Filesystem::unlink('file3.txt');
//make sure that files are in the trash bin
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
$this->assertSame(3, count($filesInTrash));
// every second file will get a date in the past so that it will get expired
@@ -204,14 +185,14 @@ class TrashbinTest extends \Test\TestCase {
// only file2.txt should be left
$remainingFiles = array_slice($manipulatedList, $count);
- $this->assertSame(1, count($remainingFiles));
+ $this->assertCount(1, $remainingFiles);
$remainingFile = reset($remainingFiles);
// TODO: failing test
#$this->assertSame('file2.txt', $remainingFile['name']);
// check that file1.txt and file3.txt was really deleted
- $newTrashContent = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
- $this->assertSame(1, count($newTrashContent));
+ $newTrashContent = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
+ $this->assertCount(1, $newTrashContent);
$element = reset($newTrashContent);
// TODO: failing test
#$this->assertSame('file2.txt', $element['name']);
@@ -223,35 +204,35 @@ class TrashbinTest extends \Test\TestCase {
* the owner of the file and the one from the user who deleted the file get expired
* correctly
*/
- public function testExpireOldFilesShared() {
+ public function testExpireOldFilesShared(): void {
$currentTime = time();
- $folder = "trashTest-" . $currentTime . '/';
+ $folder = 'trashTest-' . $currentTime . '/';
$expiredDate = $currentTime - 3 * 24 * 60 * 60;
// create some files
- \OC\Files\Filesystem::mkdir($folder);
- \OC\Files\Filesystem::file_put_contents($folder . 'user1-1.txt', 'file1');
- \OC\Files\Filesystem::file_put_contents($folder . 'user1-2.txt', 'file2');
- \OC\Files\Filesystem::file_put_contents($folder . 'user1-3.txt', 'file3');
- \OC\Files\Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
+ Filesystem::mkdir($folder);
+ Filesystem::file_put_contents($folder . 'user1-1.txt', 'file1');
+ Filesystem::file_put_contents($folder . 'user1-2.txt', 'file2');
+ Filesystem::file_put_contents($folder . 'user1-3.txt', 'file3');
+ Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
//share user1-4.txt with user2
$node = \OC::$server->getUserFolder(self::TEST_TRASHBIN_USER1)->get($folder);
- $share = \OC::$server->getShareManager()->newShare();
+ $share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setShareType(IShare::TYPE_USER)
->setNode($node)
->setSharedBy(self::TEST_TRASHBIN_USER1)
->setSharedWith(self::TEST_TRASHBIN_USER2)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
- $share = \OC::$server->getShareManager()->createShare($share);
- \OC::$server->getShareManager()->acceptShare($share, self::TEST_TRASHBIN_USER2);
+ ->setPermissions(Constants::PERMISSION_ALL);
+ $share = Server::get(\OCP\Share\IManager::class)->createShare($share);
+ Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_TRASHBIN_USER2);
// delete them so that they end up in the trash bin
- \OC\Files\Filesystem::unlink($folder . 'user1-1.txt');
- \OC\Files\Filesystem::unlink($folder . 'user1-2.txt');
- \OC\Files\Filesystem::unlink($folder . 'user1-3.txt');
+ Filesystem::unlink($folder . 'user1-1.txt');
+ Filesystem::unlink($folder . 'user1-2.txt');
+ Filesystem::unlink($folder . 'user1-3.txt');
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
$this->assertSame(3, count($filesInTrash));
// every second file will get a date in the past so that it will get expired
@@ -260,27 +241,27 @@ class TrashbinTest extends \Test\TestCase {
// login as user2
self::loginHelper(self::TEST_TRASHBIN_USER2);
- $this->assertTrue(\OC\Files\Filesystem::file_exists($folder . "user1-4.txt"));
+ $this->assertTrue(Filesystem::file_exists($folder . 'user1-4.txt'));
// create some files
- \OC\Files\Filesystem::file_put_contents('user2-1.txt', 'file1');
- \OC\Files\Filesystem::file_put_contents('user2-2.txt', 'file2');
+ Filesystem::file_put_contents('user2-1.txt', 'file1');
+ Filesystem::file_put_contents('user2-2.txt', 'file2');
// delete them so that they end up in the trash bin
- \OC\Files\Filesystem::unlink('user2-1.txt');
- \OC\Files\Filesystem::unlink('user2-2.txt');
+ Filesystem::unlink('user2-1.txt');
+ Filesystem::unlink('user2-2.txt');
- $filesInTrashUser2 = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2, 'name');
+ $filesInTrashUser2 = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2, 'name');
$this->assertSame(2, count($filesInTrashUser2));
// every second file will get a date in the past so that it will get expired
$this->manipulateDeleteTime($filesInTrashUser2, $this->trashRoot2, $expiredDate);
- \OC\Files\Filesystem::unlink($folder . 'user1-4.txt');
+ Filesystem::unlink($folder . 'user1-4.txt');
$this->runCommands();
- $filesInTrashUser2AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2);
+ $filesInTrashUser2AfterDelete = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2);
// user2-1.txt should have been expired
$this->verifyArray($filesInTrashUser2AfterDelete, ['user2-2.txt', 'user1-4.txt']);
@@ -288,7 +269,7 @@ class TrashbinTest extends \Test\TestCase {
self::loginHelper(self::TEST_TRASHBIN_USER1);
// user1-1.txt and user1-3.txt should have been expired
- $filesInTrashUser1AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
+ $filesInTrashUser1AfterDelete = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
$this->verifyArray($filesInTrashUser1AfterDelete, ['user1-2.txt', 'user1-4.txt']);
}
@@ -296,11 +277,11 @@ class TrashbinTest extends \Test\TestCase {
/**
* verify that the array contains the expected results
*
- * @param OCP\Files\FileInfo[] $result
+ * @param FileInfo[] $result
* @param string[] $expected
*/
- private function verifyArray($result, $expected) {
- $this->assertSame(count($expected), count($result));
+ private function verifyArray(array $result, array $expected): void {
+ $this->assertCount(count($expected), $result);
foreach ($expected as $expectedFile) {
$found = false;
foreach ($result as $fileInTrash) {
@@ -317,18 +298,16 @@ class TrashbinTest extends \Test\TestCase {
}
/**
- * @param OCP\Files\FileInfo[] $files
- * @param string $trashRoot
- * @param integer $expireDate
+ * @param FileInfo[] $files
*/
- private function manipulateDeleteTime($files, $trashRoot, $expireDate) {
+ private function manipulateDeleteTime(array $files, string $trashRoot, int $expireDate): array {
$counter = 0;
foreach ($files as &$file) {
// modify every second file
$counter = ($counter + 1) % 2;
if ($counter === 1) {
$source = $trashRoot . '/files/' . $file['name'] . '.d' . $file['mtime'];
- $target = \OC\Files\Filesystem::normalizePath($trashRoot . '/files/' . $file['name'] . '.d' . $expireDate);
+ $target = Filesystem::normalizePath($trashRoot . '/files/' . $file['name'] . '.d' . $expireDate);
$this->rootView->rename($source, $target);
$file['mtime'] = $expireDate;
}
@@ -341,22 +320,22 @@ class TrashbinTest extends \Test\TestCase {
* test expiration of old files in the trash bin until the max size
* of the trash bin is met again
*/
- public function testExpireOldFilesUtilLimitsAreMet() {
+ public function testExpireOldFilesUtilLimitsAreMet(): void {
// create some files
- \OC\Files\Filesystem::file_put_contents('file1.txt', 'file1');
- \OC\Files\Filesystem::file_put_contents('file2.txt', 'file2');
- \OC\Files\Filesystem::file_put_contents('file3.txt', 'file3');
+ Filesystem::file_put_contents('file1.txt', 'file1');
+ Filesystem::file_put_contents('file2.txt', 'file2');
+ Filesystem::file_put_contents('file3.txt', 'file3');
// delete them so that they end up in the trash bin
- \OC\Files\Filesystem::unlink('file3.txt');
+ Filesystem::unlink('file3.txt');
sleep(1); // make sure that every file has a unique mtime
- \OC\Files\Filesystem::unlink('file2.txt');
+ Filesystem::unlink('file2.txt');
sleep(1); // make sure that every file has a unique mtime
- \OC\Files\Filesystem::unlink('file1.txt');
+ Filesystem::unlink('file1.txt');
//make sure that files are in the trash bin
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertSame(3, count($filesInTrash));
$testClass = new TrashbinForTesting();
@@ -365,7 +344,7 @@ class TrashbinTest extends \Test\TestCase {
// the two oldest files (file3.txt and file2.txt) should be deleted
$this->assertSame(10, $sizeOfDeletedFiles);
- $newTrashContent = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
+ $newTrashContent = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
$this->assertSame(1, count($newTrashContent));
$element = reset($newTrashContent);
$this->assertSame('file1.txt', $element['name']);
@@ -374,8 +353,8 @@ class TrashbinTest extends \Test\TestCase {
/**
* Test restoring a file
*/
- public function testRestoreFileInRoot() {
- $userFolder = \OC::$server->getUserFolder();
+ public function testRestoreFileInRoot(): void {
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$file = $userFolder->newFile('file1.txt');
$file->putContent('foo');
@@ -385,14 +364,14 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
- /** @var \OCP\Files\FileInfo */
+ /** @var FileInfo */
$trashedFile = $filesInTrash[0];
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -406,8 +385,8 @@ class TrashbinTest extends \Test\TestCase {
/**
* Test restoring a file in subfolder
*/
- public function testRestoreFileInSubfolder() {
- $userFolder = \OC::$server->getUserFolder();
+ public function testRestoreFileInSubfolder(): void {
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -418,14 +397,14 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
- /** @var \OCP\Files\FileInfo */
+ /** @var FileInfo */
$trashedFile = $filesInTrash[0];
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -439,8 +418,8 @@ class TrashbinTest extends \Test\TestCase {
/**
* Test restoring a folder
*/
- public function testRestoreFolder() {
- $userFolder = \OC::$server->getUserFolder();
+ public function testRestoreFolder(): void {
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -451,14 +430,14 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
- /** @var \OCP\Files\FileInfo */
+ /** @var FileInfo */
$trashedFolder = $filesInTrash[0];
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'folder.d' . $trashedFolder->getMtime(),
$trashedFolder->getName(),
$trashedFolder->getMtime()
@@ -472,8 +451,8 @@ class TrashbinTest extends \Test\TestCase {
/**
* Test restoring a file from inside a trashed folder
*/
- public function testRestoreFileFromTrashedSubfolder() {
- $userFolder = \OC::$server->getUserFolder();
+ public function testRestoreFileFromTrashedSubfolder(): void {
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -484,14 +463,14 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
- /** @var \OCP\Files\FileInfo */
+ /** @var FileInfo */
$trashedFile = $filesInTrash[0];
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'folder.d' . $trashedFile->getMtime() . '/file1.txt',
'file1.txt',
$trashedFile->getMtime()
@@ -506,8 +485,8 @@ class TrashbinTest extends \Test\TestCase {
* Test restoring a file whenever the source folder was removed.
* The file should then land in the root.
*/
- public function testRestoreFileWithMissingSourceFolder() {
- $userFolder = \OC::$server->getUserFolder();
+ public function testRestoreFileWithMissingSourceFolder(): void {
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -518,17 +497,17 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
- /** @var \OCP\Files\FileInfo */
+ /** @var FileInfo */
$trashedFile = $filesInTrash[0];
// delete source folder
$folder->delete();
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -543,8 +522,8 @@ class TrashbinTest extends \Test\TestCase {
* Test restoring a file in the root folder whenever there is another file
* with the same name in the root folder
*/
- public function testRestoreFileDoesNotOverwriteExistingInRoot() {
- $userFolder = \OC::$server->getUserFolder();
+ public function testRestoreFileDoesNotOverwriteExistingInRoot(): void {
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$file = $userFolder->newFile('file1.txt');
$file->putContent('foo');
@@ -554,10 +533,10 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
- /** @var \OCP\Files\FileInfo */
+ /** @var FileInfo */
$trashedFile = $filesInTrash[0];
// create another file
@@ -565,7 +544,7 @@ class TrashbinTest extends \Test\TestCase {
$file->putContent('bar');
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -583,8 +562,8 @@ class TrashbinTest extends \Test\TestCase {
* Test restoring a file whenever there is another file
* with the same name in the source folder
*/
- public function testRestoreFileDoesNotOverwriteExistingInSubfolder() {
- $userFolder = \OC::$server->getUserFolder();
+ public function testRestoreFileDoesNotOverwriteExistingInSubfolder(): void {
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -595,10 +574,10 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
- /** @var \OCP\Files\FileInfo */
+ /** @var FileInfo */
$trashedFile = $filesInTrash[0];
// create another file
@@ -606,7 +585,7 @@ class TrashbinTest extends \Test\TestCase {
$file->putContent('bar');
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -623,9 +602,9 @@ class TrashbinTest extends \Test\TestCase {
/**
* Test restoring a non-existing file from trashbin, returns false
*/
- public function testRestoreUnexistingFile() {
+ public function testRestoreUnexistingFile(): void {
$this->assertFalse(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'unexist.txt.d123456',
'unexist.txt',
'123456'
@@ -637,8 +616,8 @@ class TrashbinTest extends \Test\TestCase {
* Test restoring a file into a read-only folder, will restore
* the file to root instead
*/
- public function testRestoreFileIntoReadOnlySourceFolder() {
- $userFolder = \OC::$server->getUserFolder();
+ public function testRestoreFileIntoReadOnlySourceFolder(): void {
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -649,21 +628,21 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
- /** @var \OCP\Files\FileInfo */
+ /** @var FileInfo */
$trashedFile = $filesInTrash[0];
// delete source folder
[$storage, $internalPath] = $this->rootView->resolvePath('/' . self::TEST_TRASHBIN_USER1 . '/files/folder');
- if ($storage instanceof \OC\Files\Storage\Local) {
+ if ($storage instanceof Local) {
$folderAbsPath = $storage->getSourcePath($internalPath);
// make folder read-only
chmod($folderAbsPath, 0555);
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -684,26 +663,26 @@ class TrashbinTest extends \Test\TestCase {
public static function loginHelper($user, $create = false) {
if ($create) {
try {
- \OC::$server->getUserManager()->createUser($user, $user);
+ Server::get(IUserManager::class)->createUser($user, $user);
} catch (\Exception $e) { // catch username is already being used from previous aborted runs
}
}
\OC_Util::tearDownFS();
\OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
+ Filesystem::tearDown();
\OC_User::setUserId($user);
\OC_Util::setupFS($user);
- \OC::$server->getUserFolder($user);
+ Server::get(IRootFolder::class)->getUserFolder($user);
}
}
// just a dummy class to make protected methods available for testing
-class TrashbinForTesting extends \OCA\Files_Trashbin\Trashbin {
+class TrashbinForTesting extends Trashbin {
/**
- * @param OCP\Files\FileInfo[] $files
+ * @param FileInfo[] $files
* @param integer $limit
*/
public function dummyDeleteExpiredFiles($files) {
@@ -712,7 +691,7 @@ class TrashbinForTesting extends \OCA\Files_Trashbin\Trashbin {
}
/**
- * @param OCP\Files\FileInfo[] $files
+ * @param FileInfo[] $files
* @param integer $availableSpace
*/
public function dummyDeleteFiles($files, $availableSpace) {