ExpireTrashTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Files_Trashbin\Tests\BackgroundJob;
  26. use OCA\Files_Trashbin\BackgroundJob\ExpireTrash;
  27. use OCA\Files_Trashbin\Expiration;
  28. use OCP\AppFramework\Utility\ITimeFactory;
  29. use OCP\BackgroundJob\IJobList;
  30. use OCP\IConfig;
  31. use OCP\IUserManager;
  32. use PHPUnit\Framework\MockObject\MockObject;
  33. use Test\TestCase;
  34. class ExpireTrashTest extends TestCase {
  35. /** @var IConfig|MockObject */
  36. private $config;
  37. /** @var IUserManager|MockObject */
  38. private $userManager;
  39. /** @var Expiration|MockObject */
  40. private $expiration;
  41. /** @var IJobList|MockObject */
  42. private $jobList;
  43. /** @var ITimeFactory|MockObject */
  44. private $time;
  45. protected function setUp(): void {
  46. parent::setUp();
  47. $this->config = $this->createMock(IConfig::class);
  48. $this->userManager = $this->createMock(IUserManager::class);
  49. $this->expiration = $this->createMock(Expiration::class);
  50. $this->jobList = $this->createMock(IJobList::class);
  51. $this->time = $this->createMock(ITimeFactory::class);
  52. $this->time->method('getTime')
  53. ->willReturn(999999999);
  54. $this->jobList->expects($this->once())
  55. ->method('setLastRun');
  56. $this->jobList->expects($this->once())
  57. ->method('setExecutionTime');
  58. }
  59. public function testConstructAndRun(): void {
  60. $this->config->method('getAppValue')
  61. ->with('files_trashbin', 'background_job_expire_trash', 'yes')
  62. ->willReturn('yes');
  63. $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
  64. $job->start($this->jobList);
  65. }
  66. public function testBackgroundJobDeactivated(): void {
  67. $this->config->method('getAppValue')
  68. ->with('files_trashbin', 'background_job_expire_trash', 'yes')
  69. ->willReturn('no');
  70. $this->expiration->expects($this->never())
  71. ->method('getMaxAgeAsTimestamp');
  72. $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
  73. $job->start($this->jobList);
  74. }
  75. }