aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/tests/TrashbinTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin/tests/TrashbinTest.php')
-rw-r--r--apps/files_trashbin/tests/TrashbinTest.php47
1 files changed, 20 insertions, 27 deletions
diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php
index 3d2ceee0dcd..d8486ccbdc2 100644
--- a/apps/files_trashbin/tests/TrashbinTest.php
+++ b/apps/files_trashbin/tests/TrashbinTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -22,6 +24,7 @@ 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;
@@ -41,16 +44,8 @@ class TrashbinTest extends \Test\TestCase {
private $trashRoot2;
private static $rememberRetentionObligation;
-
- /**
- * @var bool
- */
- private static $trashBinStatus;
-
- /**
- * @var View
- */
- private $rootView;
+ private static bool $trashBinStatus;
+ private View $rootView;
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
@@ -74,7 +69,7 @@ class TrashbinTest extends \Test\TestCase {
$config = Server::get(IConfig::class);
//configure trashbin
- self::$rememberRetentionObligation = $config->getSystemValue('trashbin_retention_obligation', Expiration::DEFAULT_RETENTION_OBLIGATION);
+ self::$rememberRetentionObligation = (string)$config->getSystemValue('trashbin_retention_obligation', Expiration::DEFAULT_RETENTION_OBLIGATION);
/** @var Expiration $expiration */
$expiration = Server::get(Expiration::class);
$expiration->setRetentionObligation('auto, 2');
@@ -190,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 = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
- $this->assertSame(1, count($newTrashContent));
+ $this->assertCount(1, $newTrashContent);
$element = reset($newTrashContent);
// TODO: failing test
#$this->assertSame('file2.txt', $element['name']);
@@ -285,8 +280,8 @@ class TrashbinTest extends \Test\TestCase {
* @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) {
@@ -304,10 +299,8 @@ class TrashbinTest extends \Test\TestCase {
/**
* @param FileInfo[] $files
- * @param string $trashRoot
- * @param integer $expireDate
*/
- 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
@@ -361,7 +354,7 @@ class TrashbinTest extends \Test\TestCase {
* Test restoring a file
*/
public function testRestoreFileInRoot(): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = \OCP\Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$file = $userFolder->newFile('file1.txt');
$file->putContent('foo');
@@ -393,7 +386,7 @@ class TrashbinTest extends \Test\TestCase {
* Test restoring a file in subfolder
*/
public function testRestoreFileInSubfolder(): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = \OCP\Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -426,7 +419,7 @@ class TrashbinTest extends \Test\TestCase {
* Test restoring a folder
*/
public function testRestoreFolder(): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = \OCP\Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -459,7 +452,7 @@ class TrashbinTest extends \Test\TestCase {
* Test restoring a file from inside a trashed folder
*/
public function testRestoreFileFromTrashedSubfolder(): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = \OCP\Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -493,7 +486,7 @@ class TrashbinTest extends \Test\TestCase {
* The file should then land in the root.
*/
public function testRestoreFileWithMissingSourceFolder(): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = \OCP\Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -530,7 +523,7 @@ class TrashbinTest extends \Test\TestCase {
* with the same name in the root folder
*/
public function testRestoreFileDoesNotOverwriteExistingInRoot(): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = \OCP\Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$file = $userFolder->newFile('file1.txt');
$file->putContent('foo');
@@ -570,7 +563,7 @@ class TrashbinTest extends \Test\TestCase {
* with the same name in the source folder
*/
public function testRestoreFileDoesNotOverwriteExistingInSubfolder(): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = \OCP\Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -624,7 +617,7 @@ class TrashbinTest extends \Test\TestCase {
* the file to root instead
*/
public function testRestoreFileIntoReadOnlySourceFolder(): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = \OCP\Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1);
$folder = $userFolder->newFolder('folder');
$file = $folder->newFile('file1.txt');
$file->putContent('foo');
@@ -680,7 +673,7 @@ class TrashbinTest extends \Test\TestCase {
Filesystem::tearDown();
\OC_User::setUserId($user);
\OC_Util::setupFS($user);
- \OC::$server->getUserFolder($user);
+ \OCP\Server::get(IRootFolder::class)->getUserFolder($user);
}
}