ExpireVersionsTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Files_Versions\Tests\BackgroundJob;
  7. use OCA\Files_Versions\BackgroundJob\ExpireVersions;
  8. use OCA\Files_Versions\Expiration;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\BackgroundJob\IJobList;
  11. use OCP\IConfig;
  12. use OCP\IUserManager;
  13. use PHPUnit\Framework\MockObject\MockObject;
  14. use Test\TestCase;
  15. class ExpireVersionsTest extends TestCase {
  16. /** @var IConfig|MockObject */
  17. private $config;
  18. /** @var IUserManager|MockObject */
  19. private $userManager;
  20. /** @var Expiration|MockObject */
  21. private $expiration;
  22. /** @var IJobList|MockObject */
  23. private $jobList;
  24. protected function setUp(): void {
  25. parent::setUp();
  26. $this->config = $this->createMock(IConfig::class);
  27. $this->userManager = $this->createMock(IUserManager::class);
  28. $this->expiration = $this->createMock(Expiration::class);
  29. $this->jobList = $this->createMock(IJobList::class);
  30. $this->jobList->expects($this->once())
  31. ->method('setLastRun');
  32. $this->jobList->expects($this->once())
  33. ->method('setExecutionTime');
  34. }
  35. public function testBackgroundJobDeactivated(): void {
  36. $this->config->method('getAppValue')
  37. ->with('files_versions', 'background_job_expire_versions', 'yes')
  38. ->willReturn('no');
  39. $this->expiration->expects($this->never())
  40. ->method('getMaxAgeAsTimestamp');
  41. $timeFactory = $this->createMock(ITimeFactory::class);
  42. $timeFactory->method('getTime')
  43. ->with()
  44. ->willReturn(999999999);
  45. $job = new ExpireVersions($this->config, $this->userManager, $this->expiration, $timeFactory);
  46. $job->start($this->jobList);
  47. }
  48. }