|
22 | 22 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
23 | 23 | * |
24 | 24 | */ |
| 25 | + |
25 | 26 | namespace OCA\Files_Trashbin\Tests\BackgroundJob; |
26 | 27 |
|
27 | 28 | use OCA\Files_Trashbin\BackgroundJob\ExpireTrash; |
| 29 | +use OCA\Files_Trashbin\Expiration; |
28 | 30 | use OCP\BackgroundJob\IJobList; |
| 31 | +use OCP\IConfig; |
| 32 | +use OCP\ILogger; |
29 | 33 | use OCP\IUserManager; |
| 34 | +use PHPUnit\Framework\MockObject\MockObject; |
| 35 | +use Test\TestCase; |
| 36 | + |
| 37 | +class ExpireTrashTest extends TestCase { |
| 38 | + /** @var IConfig|MockObject */ |
| 39 | + private $config; |
| 40 | + |
| 41 | + /** @var IUserManager|MockObject */ |
| 42 | + private $userManager; |
| 43 | + |
| 44 | + /** @var Expiration|MockObject */ |
| 45 | + private $expiration; |
| 46 | + |
| 47 | + /** @var IJobList|MockObject */ |
| 48 | + private $jobList; |
| 49 | + |
| 50 | + /** @var ILogger|MockObject */ |
| 51 | + private $logger; |
30 | 52 |
|
31 | | -class ExpireTrashTest extends \Test\TestCase { |
32 | | - public function testConstructAndRun() { |
33 | | - $backgroundJob = new ExpireTrash( |
34 | | - $this->createMock(IUserManager::class), |
35 | | - $this->getMockBuilder('OCA\Files_Trashbin\Expiration')->disableOriginalConstructor()->getMock() |
36 | | - ); |
| 53 | + protected function setUp(): void { |
| 54 | + parent::setUp(); |
| 55 | + |
| 56 | + $this->config = $this->createMock(IConfig::class); |
| 57 | + $this->userManager = $this->createMock(IUserManager::class); |
| 58 | + $this->expiration = $this->createMock(Expiration::class); |
| 59 | + $this->jobList = $this->createMock(IJobList::class); |
| 60 | + $this->logger = $this->createMock(ILogger::class); |
| 61 | + |
| 62 | + $this->jobList->expects($this->once()) |
| 63 | + ->method('setLastRun'); |
| 64 | + $this->jobList->expects($this->once()) |
| 65 | + ->method('setExecutionTime'); |
| 66 | + } |
| 67 | + |
| 68 | + public function testConstructAndRun(): void { |
| 69 | + $job = new ExpireTrash($this->config, $this->userManager, $this->expiration); |
| 70 | + $job->execute($this->jobList, $this->logger); |
| 71 | + } |
37 | 72 |
|
38 | | - $jobList = $this->createMock(IJobList::class); |
| 73 | + public function testBackgroundJobDeactivated(): void { |
| 74 | + $this->config->method('getAppValue') |
| 75 | + ->with('files_trashbin', 'background_job_expire_trash', 'yes') |
| 76 | + ->willReturn('no'); |
| 77 | + $this->expiration->expects($this->never()) |
| 78 | + ->method('getMaxAgeAsTimestamp'); |
39 | 79 |
|
40 | | - /** @var \OC\BackgroundJob\JobList $jobList */ |
41 | | - $backgroundJob->execute($jobList); |
42 | | - $this->addToAssertionCount(1); |
| 80 | + $job = new ExpireTrash($this->config, $this->userManager, $this->expiration); |
| 81 | + $job->execute($this->jobList, $this->logger); |
43 | 82 | } |
44 | 83 | } |
0 commit comments