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.php66
-rw-r--r--apps/files_trashbin/tests/CapabilitiesTest.php35
-rw-r--r--apps/files_trashbin/tests/Command/CleanUpTest.php182
-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.php69
-rw-r--r--apps/files_trashbin/tests/ExpirationTest.php60
-rw-r--r--apps/files_trashbin/tests/Sabre/TrashbinPluginTest.php70
-rw-r--r--apps/files_trashbin/tests/StorageTest.php290
-rw-r--r--apps/files_trashbin/tests/TrashbinTest.php333
-rw-r--r--apps/files_trashbin/tests/js/appSpec.js70
-rw-r--r--apps/files_trashbin/tests/js/filelistSpec.js397
12 files changed, 683 insertions, 1072 deletions
diff --git a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
index bf5d6bc65ae..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,39 +13,32 @@ 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 Test\TestCase;
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')
- ->willReturn(99999999999);
+ ->willReturn(999999999);
$this->jobList->expects($this->once())
->method('setLastRun');
@@ -70,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 949d0529fd6..41ed0e1e960 100644
--- a/apps/files_trashbin/tests/Command/CleanUpTest.php
+++ b/apps/files_trashbin/tests/Command/CleanUpTest.php
@@ -1,37 +1,23 @@
<?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;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@@ -43,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);
}
@@ -77,76 +49,73 @@ 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($nodeExists) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRemoveDeletedFiles')]
+ public function testRemoveDeletedFiles(bool $nodeExists): void {
$this->initTable();
- $this->rootFolder->expects($this->once())
+ $this->rootFolder
->method('nodeExists')
->with('/' . $this->user0 . '/files_trashbin')
- ->willReturn($nodeExists);
+ ->willReturnOnConsecutiveCalls($nodeExists, false);
if ($nodeExists) {
- $this->rootFolder->expects($this->once())
+ $this->rootFolder
->method('get')
->with('/' . $this->user0 . '/files_trashbin')
->willReturn($this->rootFolder);
- $this->rootFolder->expects($this->once())
+ $this->rootFolder
->method('delete');
} else {
$this->rootFolder->expects($this->never())->method('get');
$this->rootFolder->expects($this->never())->method('delete');
}
- $this->invokePrivate($this->cleanup, 'removeDeletedFiles', [$this->user0]);
+ self::invokePrivate($this->cleanup, 'removeDeletedFiles', [$this->user0, new NullOutput(), false]);
if ($nodeExists) {
- // if the delete operation was execute only files from user1
+ // if the delete operation was executed only files from user1
// should be left.
$query = $this->dbConnection->getQueryBuilder();
$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']);
}
} else {
- // if no delete operation was execute we should still have all 10
+ // if no delete operation was executed we should still have all 10
// database entries
$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]
@@ -156,91 +125,100 @@ 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->expects($this->once())->method('getArgument')
+ $inputInterface = $this->createMock(\Symfony\Component\Console\Input\InputInterface::class);
+ $inputInterface->method('getArgument')
->with('user_id')
->willReturn($userIds);
- $outputInterface = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')
- ->disableOriginalConstructor()->getMock();
- $this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
+ $inputInterface->method('getOption')
+ ->willReturnMap([
+ ['all-users', false],
+ ['verbose', false],
+ ]);
+ $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->expects($this->once())->method('getUsers')
+ $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);
- $inputInterface->expects($this->once())->method('getArgument')
+ $inputInterface->method('getArgument')
->with('user_id')
->willReturn($userIds);
$inputInterface->method('getOption')
- ->with('all-users')
- ->willReturn(true);
+ ->willReturnMap([
+ ['all-users', true],
+ ['verbose', false],
+ ]);
$outputInterface = $this->createMock(OutputInterface::class);
- $this->userManager->expects($this->once())
+ $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->expects($this->once())->method('getArgument')
+ $inputInterface->method('getArgument')
->with('user_id')
->willReturn([]);
$inputInterface->method('getOption')
- ->with('all-users')
- ->willReturn(false);
+ ->willReturnMap([
+ ['all-users', false],
+ ['verbose', false],
+ ]);
$outputInterface = $this->createMock(OutputInterface::class);
$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->expects($this->once())->method('getArgument')
+ $inputInterface->method('getArgument')
->with('user_id')
->willReturn(['user1', 'user2']);
$inputInterface->method('getOption')
- ->with('all-users')
- ->willReturn(true);
+ ->willReturnMap([
+ ['all-users', true],
+ ['verbose', false],
+ ]);
$outputInterface = $this->createMock(OutputInterface::class);
$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 441222bea19..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);
@@ -157,14 +126,14 @@ class PreviewControllerTest extends TestCase {
$this->overwriteService(ITimeFactory::class, $this->time);
- $res = $this->controller->getPreview(42, 10, 10);
+ $res = $this->controller->getPreview(42, 10, 10, false);
$expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'previewMime']);
$expected->cacheFor(3600 * 24);
$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 2f304b17881..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,16 +108,11 @@ 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
+ self::FAKE_TIME_NOW
);
$expiration = new Expiration($mockedConfig, $mockedTimeFactory);
@@ -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 b4892d2deb0..c58ddec97dd 100644
--- a/apps/files_trashbin/tests/StorageTest.php
+++ b/apps/files_trashbin/tests/StorageTest.php
@@ -1,64 +1,44 @@
<?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;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\Storage\IStorage;
-use OCP\ILogger;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
+use OCP\Server;
use OCP\Share\IShare;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+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,14 @@ class TemporaryNoCross extends Temporary {
class StorageTest extends \Test\TestCase {
use MountProviderTrait;
- /**
- * @var string
- */
- private $user;
+ private string $user;
+ private View $rootView;
+ private View $userView;
- /**
- * @var \OC\Files\View
- */
- private $rootView;
-
- /**
- * @var \OC\Files\View
- */
- private $userView;
+ // 239 chars so appended timestamp of 12 chars will exceed max length of 250 chars
+ private const LONG_FILENAME = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
+ // 250 chars
+ private const MAX_FILENAME = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
protected function setUp(): void {
parent::setUp();
@@ -99,25 +73,27 @@ 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');
$this->userView->mkdir('folder');
$this->userView->file_put_contents('folder/inside.txt', 'bar');
}
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();
}
@@ -128,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');
@@ -137,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, '.')));
}
@@ -145,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');
@@ -154,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, '.')));
@@ -165,14 +141,52 @@ class StorageTest extends \Test\TestCase {
}
/**
+ * Test that deleting a file with a long filename puts it into the trashbin.
+ */
+ public function testSingleStorageDeleteLongFilename(): void {
+ $truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
+
+ $this->assertTrue($this->userView->file_exists(static::LONG_FILENAME));
+ $this->userView->unlink(static::LONG_FILENAME);
+ [$storage,] = $this->userView->resolvePath(static::LONG_FILENAME);
+ $storage->getScanner()->scan(''); // make sure we check the storage
+ $this->assertFalse($this->userView->getFileInfo(static::LONG_FILENAME));
+
+ // check if file is in trashbin
+ $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
+ $this->assertCount(1, $results);
+ $name = $results[0]->getName();
+ $this->assertEquals($truncatedFilename, substr($name, 0, strrpos($name, '.')));
+ }
+
+ /**
+ * Test that deleting a file with the max filename length puts it into the trashbin.
+ */
+ public function testSingleStorageDeleteMaxLengthFilename(): void {
+ $truncatedFilename = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt';
+
+ $this->assertTrue($this->userView->file_exists(static::MAX_FILENAME));
+ $this->userView->unlink(static::MAX_FILENAME);
+ [$storage,] = $this->userView->resolvePath(static::MAX_FILENAME);
+ $storage->getScanner()->scan(''); // make sure we check the storage
+ $this->assertFalse($this->userView->getFileInfo(static::MAX_FILENAME));
+
+ // check if file is in trashbin
+ $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
+ $this->assertCount(1, $results);
+ $name = $results[0]->getName();
+ $this->assertEquals($truncatedFilename, substr($name, 0, strrpos($name, '.')));
+ }
+
+ /**
* Test that deleting a file from another mounted storage properly
* lands in the trashbin. This is a cross-storage situation because
* 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('');
@@ -185,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, '.')));
}
@@ -196,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');
@@ -212,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);
}
@@ -225,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');
@@ -240,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');
@@ -267,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
@@ -319,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)
@@ -344,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
@@ -371,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);
}
/**
@@ -403,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');
@@ -426,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);
}
/**
@@ -442,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');
@@ -465,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())
@@ -510,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())
@@ -544,25 +557,22 @@ 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();
$userManager->expects($this->any())
->method('userExists')->willReturn($userExists);
- $logger = $this->getMockBuilder(ILogger::class)->getMock();
- $eventDispatcher = $this->createMock(EventDispatcherInterface::class);
+ $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
+ $eventDispatcher = $this->createMock(IEventDispatcher::class);
$rootFolder = $this->createMock(IRootFolder::class);
$userFolder = $this->createMock(Folder::class);
$node = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
@@ -571,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)
@@ -583,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);
@@ -593,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],
@@ -608,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')) {
@@ -619,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');
@@ -627,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);
@@ -651,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) {
diff --git a/apps/files_trashbin/tests/js/appSpec.js b/apps/files_trashbin/tests/js/appSpec.js
deleted file mode 100644
index 281e7bbc2ba..00000000000
--- a/apps/files_trashbin/tests/js/appSpec.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
-* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
- *
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0-or-later
- *
- * 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/>.
- *
- */
-
-describe('OCA.Trashbin.App tests', function() {
- var App = OCA.Trashbin.App;
-
- beforeEach(function() {
- $('#testArea').append(
- '<div id="app-navigation">' +
- '<ul><li data-id="files"><a>Files</a></li>' +
- '<li data-id="trashbin"><a>Trashbin</a></li>' +
- '</div>' +
- '<div id="app-content">' +
- '<div id="app-content-files" class="hidden">' +
- '</div>' +
- '<div id="app-content-trashbin" class="hidden">' +
- '</div>' +
- '</div>' +
- '</div>'
- );
- App.initialize($('#app-content-trashbin'));
- });
- afterEach(function() {
- App._initialized = false;
- App.fileList = null;
- });
-
- describe('initialization', function() {
- it('creates a custom filelist instance', function() {
- App.initialize();
- expect(App.fileList).toBeDefined();
- expect(App.fileList.$el.is('#app-content-trashbin')).toEqual(true);
- });
-
- it('registers custom file actions', function() {
- var fileActions;
- App.initialize();
-
- fileActions = App.fileList.fileActions;
-
- expect(fileActions.actions.all).toBeDefined();
- expect(fileActions.actions.all.Restore).toBeDefined();
- expect(fileActions.actions.all.Delete).toBeDefined();
-
- expect(fileActions.actions.all.Rename).not.toBeDefined();
- expect(fileActions.actions.all.Download).not.toBeDefined();
-
- expect(fileActions.defaults.dir).toEqual('Open');
- });
- });
-});
diff --git a/apps/files_trashbin/tests/js/filelistSpec.js b/apps/files_trashbin/tests/js/filelistSpec.js
deleted file mode 100644
index 9e27188efb8..00000000000
--- a/apps/files_trashbin/tests/js/filelistSpec.js
+++ /dev/null
@@ -1,397 +0,0 @@
-/**
- * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
- *
- * @author Abijeet <abijeetpatro@gmail.com>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Jan C. Borchardt <hey@jancborchardt.net>
- * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0-or-later
- *
- * 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/>.
- *
- */
-
-describe('OCA.Trashbin.FileList tests', function () {
- var testFiles, alertStub, notificationStub, fileList, client;
-
- beforeEach(function () {
- alertStub = sinon.stub(OC.dialogs, 'alert');
- notificationStub = sinon.stub(OC.Notification, 'show');
-
- client = new OC.Files.Client({
- host: 'localhost',
- port: 80,
- root: '/remote.php/dav/trashbin/user',
- useHTTPS: OC.getProtocol() === 'https'
- });
-
- // init parameters and test table elements
- $('#testArea').append(
- '<div id="app-content">' +
- // set this but it shouldn't be used (could be the one from the
- // files app)
- '<input type="hidden" id="permissions" value="31"></input>' +
- // dummy controls
- '<div class="files-controls">' +
- ' <div class="actions creatable"></div>' +
- ' <div class="notCreatable"></div>' +
- '</div>' +
- // dummy table
- // TODO: at some point this will be rendered by the fileList class itself!
- '<table class="files-filestable list-container view-grid">' +
- '<thead><tr><th class="hidden column-name">' +
- '<input type="checkbox" id="select_all_trash" class="select-all">' +
- '<span class="name">Name</span>' +
- '<span class="selectedActions hidden">' +
- '<a href="" class="actions-selected"><span class="icon icon-more"></span><span>Actions</span>' +
- '</span>' +
- '</th></tr></thead>' +
- '<tbody class="files-fileList"></tbody>' +
- '<tfoot></tfoot>' +
- '</table>' +
- '<div class="emptyfilelist emptycontent">Empty content message</div>' +
- '</div>'
- );
-
- testFiles = [{
- id: 1,
- type: 'file',
- name: 'One.txt.d11111',
- displayName: 'One.txt',
- mtime: 11111000,
- mimetype: 'text/plain',
- etag: 'abc'
- }, {
- id: 2,
- type: 'file',
- name: 'Two.jpg.d22222',
- displayName: 'Two.jpg',
- mtime: 22222000,
- mimetype: 'image/jpeg',
- etag: 'def',
- }, {
- id: 3,
- type: 'file',
- name: 'Three.pdf.d33333',
- displayName: 'Three.pdf',
- mtime: 33333000,
- mimetype: 'application/pdf',
- etag: '123',
- }, {
- id: 4,
- type: 'dir',
- mtime: 99999000,
- name: 'somedir.d99999',
- displayName: 'somedir',
- mimetype: 'httpd/unix-directory',
- etag: '456'
- }];
-
- // register file actions like the trashbin App does
- var fileActions = OCA.Trashbin.App._createFileActions(fileList);
- fileList = new OCA.Trashbin.FileList(
- $('#app-content'), {
- fileActions: fileActions,
- multiSelectMenu: [{
- name: 'restore',
- displayName: t('files', 'Restore'),
- iconClass: 'icon-history',
- },
- {
- name: 'delete',
- displayName: t('files', 'Delete'),
- iconClass: 'icon-delete',
- }
- ],
- client: client
- }
- );
- });
- afterEach(function () {
- testFiles = undefined;
- fileList.destroy();
- fileList = undefined;
-
- notificationStub.restore();
- alertStub.restore();
- });
- describe('Initialization', function () {
- it('Sorts by mtime by default', function () {
- expect(fileList._sort).toEqual('mtime');
- expect(fileList._sortDirection).toEqual('desc');
- });
- it('Always returns read and delete permission', function () {
- expect(fileList.getDirectoryPermissions()).toEqual(OC.PERMISSION_READ | OC.PERMISSION_DELETE);
- });
- });
- describe('Breadcrumbs', function () {
- beforeEach(function () {
- var data = {
- status: 'success',
- data: {
- files: testFiles,
- permissions: 1
- }
- };
- fakeServer.respondWith(/\/index\.php\/apps\/files_trashbin\/ajax\/list.php\?dir=%2Fsubdir/, [
- 200, {
- "Content-Type": "application/json"
- },
- JSON.stringify(data)
- ]);
- });
- it('links the breadcrumb to the trashbin view', function () {
- fileList.changeDirectory('/subdir', false, true);
- fakeServer.respond();
- var $crumbs = fileList.$el.find('.files-controls .crumb');
- expect($crumbs.length).toEqual(3);
- expect($crumbs.eq(1).find('a').text()).toEqual('Home');
- expect($crumbs.eq(1).find('a').attr('href'))
- .toEqual(OC.getRootPath() + '/index.php/apps/files?view=trashbin&dir=/');
- expect($crumbs.eq(2).find('a').text()).toEqual('subdir');
- expect($crumbs.eq(2).find('a').attr('href'))
- .toEqual(OC.getRootPath() + '/index.php/apps/files?view=trashbin&dir=/subdir');
- });
- });
- describe('Rendering rows', function () {
- it('renders rows with the correct data when in root', function () {
- // dir listing is false when in root
- fileList.setFiles(testFiles);
- var $rows = fileList.$el.find('tbody tr');
- var $tr = $rows.eq(0);
- expect($rows.length).toEqual(4);
- expect($tr.attr('data-id')).toEqual('1');
- expect($tr.attr('data-type')).toEqual('file');
- expect($tr.attr('data-file')).toEqual('One.txt.d11111');
- expect($tr.attr('data-size')).not.toBeDefined();
- expect($tr.attr('data-etag')).toEqual('abc');
- expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
- expect($tr.attr('data-mime')).toEqual('text/plain');
- expect($tr.attr('data-mtime')).toEqual('11111000');
- expect($tr.find('a.name').attr('href')).toEqual('#');
-
- expect($tr.find('.nametext').text().trim()).toEqual('One.txt');
-
- expect(fileList.findFileEl('One.txt.d11111')[0]).toEqual($tr[0]);
- });
- it('renders rows with the correct data when in root after calling setFiles with the same data set', function () {
- // dir listing is false when in root
- fileList.setFiles(testFiles);
- fileList.setFiles(fileList.files);
- var $rows = fileList.$el.find('tbody tr');
- var $tr = $rows.eq(0);
- expect($rows.length).toEqual(4);
- expect($tr.attr('data-id')).toEqual('1');
- expect($tr.attr('data-type')).toEqual('file');
- expect($tr.attr('data-file')).toEqual('One.txt.d11111');
- expect($tr.attr('data-size')).not.toBeDefined();
- expect($tr.attr('data-etag')).toEqual('abc');
- expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
- expect($tr.attr('data-mime')).toEqual('text/plain');
- expect($tr.attr('data-mtime')).toEqual('11111000');
- expect($tr.find('a.name').attr('href')).toEqual('#');
-
- expect($tr.find('.nametext').text().trim()).toEqual('One.txt');
-
- expect(fileList.findFileEl('One.txt.d11111')[0]).toEqual($tr[0]);
- });
- it('renders rows with the correct data when in subdirectory', function () {
- fileList.setFiles(testFiles.map(function (file) {
- file.name = file.displayName;
- return file;
- }));
- var $rows = fileList.$el.find('tbody tr');
- var $tr = $rows.eq(0);
- expect($rows.length).toEqual(4);
- expect($tr.attr('data-id')).toEqual('1');
- expect($tr.attr('data-type')).toEqual('file');
- expect($tr.attr('data-file')).toEqual('One.txt');
- expect($tr.attr('data-size')).not.toBeDefined();
- expect($tr.attr('data-etag')).toEqual('abc');
- expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
- expect($tr.attr('data-mime')).toEqual('text/plain');
- expect($tr.attr('data-mtime')).toEqual('11111000');
- expect($tr.find('a.name').attr('href')).toEqual('#');
-
- expect($tr.find('.nametext').text().trim()).toEqual('One.txt');
-
- expect(fileList.findFileEl('One.txt')[0]).toEqual($tr[0]);
- });
- it('does not render a size column', function () {
- expect(fileList.$el.find('tbody tr .filesize').length).toEqual(0);
- });
- });
- describe('File actions', function () {
- describe('Deleting single files', function () {
- // TODO: checks ajax call
- // TODO: checks spinner
- // TODO: remove item after delete
- // TODO: bring back item if delete failed
- });
- describe('Restoring single files', function () {
- // TODO: checks ajax call
- // TODO: checks spinner
- // TODO: remove item after restore
- // TODO: bring back item if restore failed
- });
- });
- describe('file previews', function () {
- // TODO: check that preview URL is going through files_trashbin
- });
- describe('loading file list', function () {
- // TODO: check that ajax URL is going through files_trashbin
- });
- describe('breadcrumbs', function () {
- // TODO: test label + URL
- });
- describe('elementToFile', function () {
- var $tr;
-
- beforeEach(function () {
- fileList.setFiles(testFiles);
- $tr = fileList.findFileEl('One.txt.d11111');
- });
-
- it('converts data attributes to file info structure', function () {
- var fileInfo = fileList.elementToFile($tr);
- expect(fileInfo.id).toEqual(1);
- expect(fileInfo.name).toEqual('One.txt.d11111');
- expect(fileInfo.displayName).toEqual('One.txt');
- expect(fileInfo.mtime).toEqual(11111000);
- expect(fileInfo.etag).toEqual('abc');
- expect(fileInfo.permissions).toEqual(OC.PERMISSION_READ | OC.PERMISSION_DELETE);
- expect(fileInfo.mimetype).toEqual('text/plain');
- expect(fileInfo.type).toEqual('file');
- });
- });
- describe('Global Actions', function () {
- beforeEach(function () {
- fileList.setFiles(testFiles);
- fileList.findFileEl('One.txt.d11111').find('input:checkbox').click();
- fileList.findFileEl('Three.pdf.d33333').find('input:checkbox').click();
- fileList.findFileEl('somedir.d99999').find('input:checkbox').click();
- fileList.$el.find('.actions-selected').click();
- });
-
- afterEach(function () {
- fileList.$el.find('.actions-selected').click();
- });
-
- describe('Delete', function () {
- it('Shows trashbin actions', function () {
- // visible because a few files were selected
- expect($('.selectedActions').is(':visible')).toEqual(true);
- expect($('.selectedActions .item-delete').is(':visible')).toEqual(true);
- expect($('.selectedActions .item-restore').is(':visible')).toEqual(true);
-
- // check
- fileList.$el.find('.select-all').click();
-
- // stays visible
- expect($('.selectedActions').is(':visible')).toEqual(true);
- expect($('.selectedActions .item-delete').is(':visible')).toEqual(true);
- expect($('.selectedActions .item-restore').is(':visible')).toEqual(true);
-
- // uncheck
- fileList.$el.find('.select-all').click();
-
- // becomes hidden now
- expect($('.selectedActions').is(':visible')).toEqual(false);
- expect($('.selectedActions .item-delete').is(':visible')).toEqual(false);
- expect($('.selectedActions .item-restore').is(':visible')).toEqual(false);
- });
- it('Deletes selected files when "Delete" clicked', function (done) {
- var request;
- var promise = fileList._onClickDeleteSelected({
- preventDefault: function () {
- }
- });
- var files = ["One.txt.d11111", "Three.pdf.d33333", "somedir.d99999"];
- expect(fakeServer.requests.length).toEqual(files.length);
- for (var i = 0; i < files.length; i++) {
- request = fakeServer.requests[i];
- expect(request.url).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/trash/' + files[i]);
- request.respond(200);
- }
- return promise.then(function () {
- expect(fileList.findFileEl('One.txt.d11111').length).toEqual(0);
- expect(fileList.findFileEl('Three.pdf.d33333').length).toEqual(0);
- expect(fileList.findFileEl('somedir.d99999').length).toEqual(0);
- expect(fileList.findFileEl('Two.jpg.d22222').length).toEqual(1);
- }).then(done, done);
- });
- it('Deletes all files when all selected when "Delete" clicked', function (done) {
- var request;
- $('.select-all').click();
- var promise = fileList._onClickDeleteSelected({
- preventDefault: function () {
- }
- });
- expect(fakeServer.requests.length).toEqual(1);
- request = fakeServer.requests[0];
- expect(request.url).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/trash');
- request.respond(200);
- return promise.then(function () {
- expect(fileList.isEmpty).toEqual(true);
- }).then(done, done);
- });
- });
- describe('Restore', function () {
- it('Restores selected files when "Restore" clicked', function (done) {
- var request;
- var promise = fileList._onClickRestoreSelected({
- preventDefault: function () {
- }
- });
- var files = ["One.txt.d11111", "Three.pdf.d33333", "somedir.d99999"];
- expect(fakeServer.requests.length).toEqual(files.length);
- for (var i = 0; i < files.length; i++) {
- request = fakeServer.requests[i];
- expect(request.url).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/trash/' + files[i]);
- expect(request.requestHeaders.Destination).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/restore/' + files[i]);
- request.respond(200);
- }
- return promise.then(function() {
- expect(fileList.findFileEl('One.txt.d11111').length).toEqual(0);
- expect(fileList.findFileEl('Three.pdf.d33333').length).toEqual(0);
- expect(fileList.findFileEl('somedir.d99999').length).toEqual(0);
- expect(fileList.findFileEl('Two.jpg.d22222').length).toEqual(1);
- }).then(done, done);
- });
- it('Restores all files when all selected when "Restore" clicked', function (done) {
- var request;
- $('.select-all').click();
- var promise = fileList._onClickRestoreSelected({
- preventDefault: function () {
- }
- });
- var files = ["One.txt.d11111", "Two.jpg.d22222", "Three.pdf.d33333", "somedir.d99999"];
- expect(fakeServer.requests.length).toEqual(files.length);
- for (var i = 0; i < files.length; i++) {
- request = fakeServer.requests[i];
- expect(request.url).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/trash/' + files[i]);
- expect(request.requestHeaders.Destination).toEqual(OC.getRootPath() + '/remote.php/dav/trashbin/user/restore/' + files[i]);
- request.respond(200);
- }
- return promise.then(function() {
- expect(fileList.isEmpty).toEqual(true);
- }).then(done, done);
- });
- });
- });
-});