1
0

ExpireTrashTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. use Psr\Log\LoggerInterface;
  35. class ExpireTrashTest extends TestCase {
  36. /** @var IConfig|MockObject */
  37. private $config;
  38. /** @var IUserManager|MockObject */
  39. private $userManager;
  40. /** @var Expiration|MockObject */
  41. private $expiration;
  42. /** @var IJobList|MockObject */
  43. private $jobList;
  44. /** @var ITimeFactory|MockObject */
  45. private $time;
  46. protected function setUp(): void {
  47. parent::setUp();
  48. $this->config = $this->createMock(IConfig::class);
  49. $this->userManager = $this->createMock(IUserManager::class);
  50. $this->expiration = $this->createMock(Expiration::class);
  51. $this->jobList = $this->createMock(IJobList::class);
  52. $this->time = $this->createMock(ITimeFactory::class);
  53. $this->time->method('getTime')
  54. ->willReturn(99999999999);
  55. $this->jobList->expects($this->once())
  56. ->method('setLastRun');
  57. $this->jobList->expects($this->once())
  58. ->method('setExecutionTime');
  59. }
  60. public function testConstructAndRun(): void {
  61. $this->config->method('getAppValue')
  62. ->with('files_trashbin', 'background_job_expire_trash', 'yes')
  63. ->willReturn('yes');
  64. $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
  65. $job->start($this->jobList);
  66. }
  67. public function testBackgroundJobDeactivated(): void {
  68. $this->config->method('getAppValue')
  69. ->with('files_trashbin', 'background_job_expire_trash', 'yes')
  70. ->willReturn('no');
  71. $this->expiration->expects($this->never())
  72. ->method('getMaxAgeAsTimestamp');
  73. $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
  74. $job->start($this->jobList);
  75. }
  76. }