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 {
|
2022-02-22 05:24:38 -05:00
|
|
|
/** @var ITimeFactory|MockObject */
|
|
|
|
|
private $time;
|
|
|
|
|
|
|
|
|
|
/** @var ReminderService|MockObject */
|
2019-03-16 11:19:25 -04:00
|
|
|
private $reminderService;
|
|
|
|
|
|
2022-02-22 05:24:38 -05:00
|
|
|
/** @var IConfig|MockObject */
|
2019-03-16 11:19:25 -04:00
|
|
|
private $config;
|
|
|
|
|
|
2022-02-22 05:24:38 -05:00
|
|
|
/** @var EventReminderJob|MockObject */
|
2019-03-16 11:19:25 -04:00
|
|
|
private $backgroundJob;
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider data
|
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
|
|
|
*/
|
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')
|
2023-01-05 12:25:31 -05:00
|
|
|
->withConsecutive(
|
|
|
|
|
['dav', 'sendEventReminders', 'yes'],
|
|
|
|
|
['dav', 'sendEventRemindersMode', 'backgroundjob'],
|
|
|
|
|
)
|
|
|
|
|
->willReturnOnConsecutiveCalls(
|
|
|
|
|
$sendEventReminders ? 'yes' : 'no',
|
|
|
|
|
$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([]);
|
|
|
|
|
}
|
|
|
|
|
}
|