|
|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
/**
|
|
|
|
|
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
@ -8,11 +10,13 @@ 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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -23,28 +27,17 @@ 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;
|
|
|
|
|
|
|
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject | VersionsMapper */
|
|
|
|
|
protected $versionMapper;
|
|
|
|
|
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->versionMapper = $this->getMockBuilder('OCA\Files_Versions\Db\VersionsMapper')
|
|
|
|
|
->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->versionMapper);
|
|
|
|
|
}
|
|
|
|
|
@ -53,7 +46,7 @@ class CleanupTest extends TestCase {
|
|
|
|
|
* @dataProvider dataTestDeleteVersions
|
|
|
|
|
* @param boolean $nodeExists
|
|
|
|
|
*/
|
|
|
|
|
public function testDeleteVersions($nodeExists): void {
|
|
|
|
|
public function testDeleteVersions(bool $nodeExists): void {
|
|
|
|
|
$this->rootFolder->expects($this->once())
|
|
|
|
|
->method('nodeExists')
|
|
|
|
|
->with('/testUser/files_versions')
|
|
|
|
|
@ -92,7 +85,7 @@ class CleanupTest extends TestCase {
|
|
|
|
|
$this->invokePrivate($this->cleanup, 'deleteVersions', ['testUser']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dataTestDeleteVersions() {
|
|
|
|
|
public static function dataTestDeleteVersions(): array {
|
|
|
|
|
return [
|
|
|
|
|
[true],
|
|
|
|
|
[false]
|
|
|
|
|
@ -106,8 +99,8 @@ class CleanupTest extends TestCase {
|
|
|
|
|
public function testExecuteDeleteListOfUsers(): void {
|
|
|
|
|
$userIds = ['user1', 'user2', 'user3'];
|
|
|
|
|
|
|
|
|
|
$instance = $this->getMockBuilder('OCA\Files_Versions\Command\CleanUp')
|
|
|
|
|
->setMethods(['deleteVersions'])
|
|
|
|
|
$instance = $this->getMockBuilder(CleanUp::class)
|
|
|
|
|
->onlyMethods(['deleteVersions'])
|
|
|
|
|
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->versionMapper])
|
|
|
|
|
->getMock();
|
|
|
|
|
$instance->expects($this->exactly(count($userIds)))
|
|
|
|
|
@ -119,14 +112,12 @@ class CleanupTest extends TestCase {
|
|
|
|
|
$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]);
|
|
|
|
|
}
|
|
|
|
|
@ -138,8 +129,8 @@ class CleanupTest extends TestCase {
|
|
|
|
|
$userIds = [];
|
|
|
|
|
$backendUsers = ['user1', 'user2'];
|
|
|
|
|
|
|
|
|
|
$instance = $this->getMockBuilder('OCA\Files_Versions\Command\CleanUp')
|
|
|
|
|
->setMethods(['deleteVersions'])
|
|
|
|
|
$instance = $this->getMockBuilder(CleanUp::class)
|
|
|
|
|
->onlyMethods(['deleteVersions'])
|
|
|
|
|
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->versionMapper])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
@ -155,14 +146,12 @@ class CleanupTest extends TestCase {
|
|
|
|
|
$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')
|
|
|
|
|
|