ExpireTrashTest.php 2.0 KB

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