aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/tests/Command
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/tests/Command')
-rw-r--r--apps/files_versions/tests/Command/CleanupTest.php115
-rw-r--r--apps/files_versions/tests/Command/ExpireTest.php27
2 files changed, 60 insertions, 82 deletions
diff --git a/apps/files_versions/tests/Command/CleanupTest.php b/apps/files_versions/tests/Command/CleanupTest.php
index b5463aa61db..dd6665f5aef 100644
--- a/apps/files_versions/tests/Command/CleanupTest.php
+++ b/apps/files_versions/tests/Command/CleanupTest.php
@@ -1,33 +1,22 @@
<?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 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_Versions\Tests\Command;
use OC\User\Manager;
use OCA\Files_Versions\Command\CleanUp;
+use OCA\Files_Versions\Db\VersionsMapper;
+use OCP\Files\Cache\ICache;
+use OCP\Files\Folder;
use OCP\Files\IRootFolder;
+use OCP\Files\Storage\IStorage;
+use OCP\UserInterface;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/**
@@ -38,38 +27,46 @@ use Test\TestCase;
* @package OCA\Files_Versions\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;
+ protected Manager&MockObject $userManager;
+ protected IRootFolder&MockObject $rootFolder;
+ protected VersionsMapper&MockObject $versionMapper;
+ protected CleanUp $cleanup;
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(Manager::class);
+ $this->versionMapper = $this->createMock(VersionsMapper::class);
-
- $this->cleanup = new CleanUp($this->rootFolder, $this->userManager);
+ $this->cleanup = new CleanUp($this->rootFolder, $this->userManager, $this->versionMapper);
}
/**
- * @dataProvider dataTestDeleteVersions
* @param boolean $nodeExists
*/
- public function testDeleteVersions($nodeExists) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestDeleteVersions')]
+ public function testDeleteVersions(bool $nodeExists): void {
$this->rootFolder->expects($this->once())
->method('nodeExists')
->with('/testUser/files_versions')
->willReturn($nodeExists);
+ $userFolder = $this->createMock(Folder::class);
+ $userHomeStorage = $this->createMock(IStorage::class);
+ $userHomeStorageCache = $this->createMock(ICache::class);
+ $this->rootFolder->expects($this->once())
+ ->method('getUserFolder')
+ ->willReturn($userFolder);
+ $userFolder->expects($this->once())
+ ->method('getStorage')
+ ->willReturn($userHomeStorage);
+ $userHomeStorage->expects($this->once())
+ ->method('getCache')
+ ->willReturn($userHomeStorageCache);
+ $userHomeStorageCache->expects($this->once())
+ ->method('getNumericStorageId')
+ ->willReturn(1);
if ($nodeExists) {
$this->rootFolder->expects($this->once())
@@ -88,7 +85,7 @@ class CleanupTest extends TestCase {
$this->invokePrivate($this->cleanup, 'deleteVersions', ['testUser']);
}
- public function dataTestDeleteVersions() {
+ public static function dataTestDeleteVersions(): array {
return [
[true],
[false]
@@ -99,30 +96,28 @@ class CleanupTest extends TestCase {
/**
* test delete versions from users given as parameter
*/
- public function testExecuteDeleteListOfUsers() {
+ public function testExecuteDeleteListOfUsers(): void {
$userIds = ['user1', 'user2', 'user3'];
- $instance = $this->getMockBuilder('OCA\Files_Versions\Command\CleanUp')
- ->setMethods(['deleteVersions'])
- ->setConstructorArgs([$this->rootFolder, $this->userManager])
+ $instance = $this->getMockBuilder(CleanUp::class)
+ ->onlyMethods(['deleteVersions'])
+ ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->versionMapper])
->getMock();
$instance->expects($this->exactly(count($userIds)))
->method('deleteVersions')
- ->willReturnCallback(function ($user) use ($userIds) {
+ ->willReturnCallback(function ($user) use ($userIds): void {
$this->assertTrue(in_array($user, $userIds));
});
$this->userManager->expects($this->exactly(count($userIds)))
->method('userExists')->willReturn(true);
- $inputInterface = $this->getMockBuilder('\Symfony\Component\Console\Input\InputInterface')
- ->disableOriginalConstructor()->getMock();
+ $inputInterface = $this->createMock(\Symfony\Component\Console\Input\InputInterface::class);
$inputInterface->expects($this->once())->method('getArgument')
->with('user_id')
->willReturn($userIds);
- $outputInterface = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')
- ->disableOriginalConstructor()->getMock();
+ $outputInterface = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
$this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
}
@@ -130,16 +125,16 @@ class CleanupTest extends TestCase {
/**
* test delete versions of all users
*/
- public function testExecuteAllUsers() {
+ public function testExecuteAllUsers(): void {
$userIds = [];
$backendUsers = ['user1', 'user2'];
- $instance = $this->getMockBuilder('OCA\Files_Versions\Command\CleanUp')
- ->setMethods(['deleteVersions'])
- ->setConstructorArgs([$this->rootFolder, $this->userManager])
+ $instance = $this->getMockBuilder(CleanUp::class)
+ ->onlyMethods(['deleteVersions'])
+ ->setConstructorArgs([$this->rootFolder, $this->userManager, $this->versionMapper])
->getMock();
- $backend = $this->getMockBuilder(\OCP\UserInterface::class)
+ $backend = $this->getMockBuilder(UserInterface::class)
->disableOriginalConstructor()->getMock();
$backend->expects($this->once())->method('getUsers')
->with('', 500, 0)
@@ -147,22 +142,20 @@ class CleanupTest extends TestCase {
$instance->expects($this->exactly(count($backendUsers)))
->method('deleteVersions')
- ->willReturnCallback(function ($user) use ($backendUsers) {
+ ->willReturnCallback(function ($user) use ($backendUsers): void {
$this->assertTrue(in_array($user, $backendUsers));
});
- $inputInterface = $this->getMockBuilder('\Symfony\Component\Console\Input\InputInterface')
- ->disableOriginalConstructor()->getMock();
+ $inputInterface = $this->createMock(\Symfony\Component\Console\Input\InputInterface::class);
$inputInterface->expects($this->once())->method('getArgument')
->with('user_id')
->willReturn($userIds);
- $outputInterface = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')
- ->disableOriginalConstructor()->getMock();
+ $outputInterface = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
$this->userManager->expects($this->once())
- ->method('getBackends')
- ->willReturn([$backend]);
+ ->method('getBackends')
+ ->willReturn([$backend]);
$this->invokePrivate($instance, 'execute', [$inputInterface, $outputInterface]);
}
diff --git a/apps/files_versions/tests/Command/ExpireTest.php b/apps/files_versions/tests/Command/ExpireTest.php
index 9b0b68e71ea..b74457a7fd6 100644
--- a/apps/files_versions/tests/Command/ExpireTest.php
+++ b/apps/files_versions/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 Jörn Friedrich Dreyer <jfd@butonic.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 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_Versions\Tests\Command;
@@ -34,7 +19,7 @@ use Test\TestCase;
* @package OCA\Files_Versions\Tests\Command
*/
class ExpireTest extends TestCase {
- public function testExpireNonExistingUser() {
+ public function testExpireNonExistingUser(): void {
$command = new Expire($this->getUniqueID('test'), '');
$command->handle();