2019-03-16 11:19:25 -04:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2019-03-16 11:19:25 -04:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2019-03-16 11:19:25 -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
|
2019-03-16 11:19:25 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\DAV\Tests\unit\BackgroundJob;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\BackgroundJob\EventReminderJob;
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\ReminderService;
|
2022-02-22 05:24:38 -05:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2019-03-16 11:19:25 -04:00
|
|
|
use OCP\IConfig;
|
2022-02-22 05:24:38 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2019-03-16 11:19:25 -04:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class EventReminderJobTest extends TestCase {
|
2025-05-24 17:00:05 -04:00
|
|
|
private ITimeFactory&MockObject $time;
|
|
|
|
|
private ReminderService&MockObject $reminderService;
|
|
|
|
|
private IConfig&MockObject $config;
|
|
|
|
|
private EventReminderJob $backgroundJob;
|
2019-03-16 11:19:25 -04:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2019-03-16 11:19:25 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2022-02-22 05:24:38 -05:00
|
|
|
$this->time = $this->createMock(ITimeFactory::class);
|
2019-03-16 11:19:25 -04:00
|
|
|
$this->reminderService = $this->createMock(ReminderService::class);
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
|
|
2022-02-22 05:24:38 -05:00
|
|
|
$this->backgroundJob = new EventReminderJob(
|
|
|
|
|
$this->time,
|
|
|
|
|
$this->reminderService,
|
|
|
|
|
$this->config,
|
|
|
|
|
);
|
2019-03-16 11:19:25 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-24 17:00:05 -04:00
|
|
|
public static function data(): array {
|
2019-08-12 07:20:03 -04:00
|
|
|
return [
|
|
|
|
|
[true, true, true],
|
|
|
|
|
[true, false, false],
|
|
|
|
|
[false, true, false],
|
|
|
|
|
[false, false, false],
|
|
|
|
|
];
|
2019-03-16 11:19:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-12 07:20:03 -04:00
|
|
|
*
|
2019-03-16 11:19:25 -04:00
|
|
|
* @param bool $sendEventReminders
|
2019-08-12 07:20:03 -04:00
|
|
|
* @param bool $sendEventRemindersMode
|
|
|
|
|
* @param bool $expectCall
|
2019-03-16 11:19:25 -04:00
|
|
|
*/
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('data')]
|
2019-08-12 07:20:03 -04:00
|
|
|
public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
|
2023-01-05 12:25:31 -05:00
|
|
|
$this->config->expects($this->exactly($sendEventReminders ? 2 : 1))
|
2019-08-12 07:20:03 -04:00
|
|
|
->method('getAppValue')
|
2025-05-24 17:00:05 -04:00
|
|
|
->willReturnMap([
|
|
|
|
|
['dav', 'sendEventReminders', 'yes', ($sendEventReminders ? 'yes' : 'no')],
|
|
|
|
|
['dav', 'sendEventRemindersMode', 'backgroundjob', ($sendEventRemindersMode ? 'backgroundjob' : 'cron')],
|
|
|
|
|
]);
|
2019-08-12 07:20:03 -04:00
|
|
|
|
|
|
|
|
if ($expectCall) {
|
|
|
|
|
$this->reminderService->expects($this->once())
|
|
|
|
|
->method('processReminders');
|
|
|
|
|
} else {
|
|
|
|
|
$this->reminderService->expects($this->never())
|
|
|
|
|
->method('processReminders');
|
|
|
|
|
}
|
2019-03-16 11:19:25 -04:00
|
|
|
|
|
|
|
|
$this->backgroundJob->run([]);
|
|
|
|
|
}
|
|
|
|
|
}
|