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