|
|
|
|
@ -26,20 +26,58 @@
|
|
|
|
|
namespace OCA\Files_Trashbin\Tests\BackgroundJob;
|
|
|
|
|
|
|
|
|
|
use OCA\Files_Trashbin\BackgroundJob\ExpireTrash;
|
|
|
|
|
use OCA\Files_Trashbin\Expiration;
|
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\ILogger;
|
|
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class ExpireTrashTest extends \Test\TestCase {
|
|
|
|
|
public function testConstructAndRun() {
|
|
|
|
|
$backgroundJob = new ExpireTrash(
|
|
|
|
|
$this->createMock(IUserManager::class),
|
|
|
|
|
$this->getMockBuilder('OCA\Files_Trashbin\Expiration')->disableOriginalConstructor()->getMock()
|
|
|
|
|
);
|
|
|
|
|
class ExpireTrashTest extends TestCase {
|
|
|
|
|
/** @var IConfig|MockObject */
|
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
|
|
$jobList = $this->createMock(IJobList::class);
|
|
|
|
|
/** @var IUserManager|MockObject */
|
|
|
|
|
private $userManager;
|
|
|
|
|
|
|
|
|
|
/** @var \OC\BackgroundJob\JobList $jobList */
|
|
|
|
|
$backgroundJob->execute($jobList);
|
|
|
|
|
$this->addToAssertionCount(1);
|
|
|
|
|
/** @var Expiration|MockObject */
|
|
|
|
|
private $expiration;
|
|
|
|
|
|
|
|
|
|
/** @var IJobList|MockObject */
|
|
|
|
|
private $jobList;
|
|
|
|
|
|
|
|
|
|
/** @var ILogger|MockObject */
|
|
|
|
|
private $logger;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
|
$this->expiration = $this->createMock(Expiration::class);
|
|
|
|
|
$this->jobList = $this->createMock(IJobList::class);
|
|
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
|
|
|
|
|
|
|
|
$this->jobList->expects($this->once())
|
|
|
|
|
->method('setLastRun');
|
|
|
|
|
$this->jobList->expects($this->once())
|
|
|
|
|
->method('setExecutionTime');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConstructAndRun(): void {
|
|
|
|
|
$job = new ExpireTrash($this->config, $this->userManager, $this->expiration);
|
|
|
|
|
$job->execute($this->jobList, $this->logger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testBackgroundJobDeactivated(): void {
|
|
|
|
|
$this->config->method('getAppValue')
|
|
|
|
|
->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);
|
|
|
|
|
$job->execute($this->jobList, $this->logger);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|