2018-06-19 15:01:14 -04:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-06-19 15:01:14 -04:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-06-19 15:01:14 -04:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-06-19 15:01:14 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\DAV\Tests\unit\BackgroundJob;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\BackgroundJob\CleanupInvitationTokenJob;
|
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCP\DB\QueryBuilder\IExpressionBuilder;
|
2018-06-19 15:01:14 -04:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
|
use OCP\IDBConnection;
|
2025-05-24 17:00:05 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-06-19 15:01:14 -04:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class CleanupInvitationTokenJobTest extends TestCase {
|
2025-05-24 17:00:05 -04:00
|
|
|
private IDBConnection&MockObject $dbConnection;
|
|
|
|
|
private ITimeFactory&MockObject $timeFactory;
|
|
|
|
|
private CleanupInvitationTokenJob $backgroundJob;
|
2018-06-19 15:01:14 -04:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2018-06-19 15:01:14 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->dbConnection = $this->createMock(IDBConnection::class);
|
|
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
|
|
|
|
|
|
$this->backgroundJob = new CleanupInvitationTokenJob(
|
|
|
|
|
$this->dbConnection, $this->timeFactory);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testRun(): void {
|
2018-06-19 15:01:14 -04:00
|
|
|
$this->timeFactory->expects($this->once())
|
|
|
|
|
->method('getTime')
|
|
|
|
|
->with()
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(1337);
|
2018-06-19 15:01:14 -04:00
|
|
|
|
|
|
|
|
$queryBuilder = $this->createMock(IQueryBuilder::class);
|
2024-10-10 06:40:31 -04:00
|
|
|
$expr = $this->createMock(IExpressionBuilder::class);
|
2018-06-19 15:01:14 -04:00
|
|
|
|
|
|
|
|
$this->dbConnection->expects($this->once())
|
|
|
|
|
->method('getQueryBuilder')
|
|
|
|
|
->with()
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($queryBuilder);
|
2018-06-19 15:01:14 -04:00
|
|
|
$queryBuilder->method('expr')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($expr);
|
2018-06-19 15:01:14 -04:00
|
|
|
$queryBuilder->method('createNamedParameter')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnMap([
|
2018-06-19 15:01:14 -04:00
|
|
|
[1337, \PDO::PARAM_STR, null, 'namedParameter1337']
|
2020-03-25 17:21:27 -04:00
|
|
|
]);
|
2018-06-19 15:01:14 -04:00
|
|
|
|
2022-11-14 11:06:28 -05:00
|
|
|
$function = 'function1337';
|
2018-06-19 15:01:14 -04:00
|
|
|
$expr->expects($this->once())
|
|
|
|
|
->method('lt')
|
|
|
|
|
->with('expiration', 'namedParameter1337')
|
2022-06-14 09:26:15 -04:00
|
|
|
->willReturn($function);
|
2018-06-19 15:01:14 -04:00
|
|
|
|
|
|
|
|
$this->dbConnection->expects($this->once())
|
|
|
|
|
->method('getQueryBuilder')
|
|
|
|
|
->with()
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($queryBuilder);
|
2018-06-19 15:01:14 -04:00
|
|
|
|
2023-01-05 12:25:31 -05:00
|
|
|
$queryBuilder->expects($this->once())
|
2018-06-19 15:01:14 -04:00
|
|
|
->method('delete')
|
2018-07-12 06:11:11 -04:00
|
|
|
->with('calendar_invitations')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($queryBuilder);
|
2023-01-05 12:25:31 -05:00
|
|
|
$queryBuilder->expects($this->once())
|
2018-06-19 15:01:14 -04:00
|
|
|
->method('where')
|
2022-06-14 09:26:15 -04:00
|
|
|
->with($function)
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($queryBuilder);
|
2023-01-05 12:25:31 -05:00
|
|
|
$queryBuilder->expects($this->once())
|
2025-09-12 11:17:17 -04:00
|
|
|
->method('executeStatement')
|
2018-06-19 15:01:14 -04:00
|
|
|
->with()
|
2025-09-12 11:17:17 -04:00
|
|
|
->willReturn(1);
|
2018-06-19 15:01:14 -04:00
|
|
|
|
|
|
|
|
$this->backgroundJob->run([]);
|
|
|
|
|
}
|
2018-07-12 06:11:11 -04:00
|
|
|
}
|