2017-11-11 05:25:40 -05:00
|
|
|
<?php
|
2022-02-22 05:24:38 -05:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-11-11 05:25:40 -05:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-11-11 05:25:40 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\DAV\Tests\unit\BackgroundJob;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
|
|
|
|
|
use OCA\DAV\CalDAV\BirthdayService;
|
2022-02-22 05:24:38 -05:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2017-11-11 05:25:40 -05:00
|
|
|
use OCP\IConfig;
|
2022-02-22 05:24:38 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2017-11-11 05:25:40 -05:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class GenerateBirthdayCalendarBackgroundJobTest extends TestCase {
|
2025-05-24 17:00:05 -04:00
|
|
|
private ITimeFactory&MockObject $time;
|
|
|
|
|
private BirthdayService&MockObject $birthdayService;
|
|
|
|
|
private IConfig&MockObject $config;
|
|
|
|
|
private GenerateBirthdayCalendarBackgroundJob $backgroundJob;
|
2017-11-11 05:25:40 -05:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2017-11-11 05:25:40 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2022-02-22 05:24:38 -05:00
|
|
|
$this->time = $this->createMock(ITimeFactory::class);
|
2017-11-11 05:25:40 -05:00
|
|
|
$this->birthdayService = $this->createMock(BirthdayService::class);
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
|
|
|
|
|
|
$this->backgroundJob = new GenerateBirthdayCalendarBackgroundJob(
|
2022-02-22 05:24:38 -05:00
|
|
|
$this->time,
|
|
|
|
|
$this->birthdayService,
|
|
|
|
|
$this->config,
|
|
|
|
|
);
|
2017-11-11 05:25:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testRun(): void {
|
2017-11-11 05:25:40 -05:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
|
->method('getAppValue')
|
|
|
|
|
->with('dav', 'generateBirthdayCalendar', 'yes')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('yes');
|
2017-11-11 05:25:40 -05:00
|
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
|
->method('getUserValue')
|
|
|
|
|
->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('yes');
|
2017-11-11 05:25:40 -05:00
|
|
|
|
2019-02-16 10:18:58 -05:00
|
|
|
$this->birthdayService->expects($this->never())
|
|
|
|
|
->method('resetForUser')
|
|
|
|
|
->with('user123');
|
|
|
|
|
|
2017-11-11 05:25:40 -05:00
|
|
|
$this->birthdayService->expects($this->once())
|
|
|
|
|
->method('syncUser')
|
|
|
|
|
->with('user123');
|
|
|
|
|
|
|
|
|
|
$this->backgroundJob->run(['userId' => 'user123']);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testRunAndReset(): void {
|
2019-02-16 10:18:58 -05:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
|
->method('getAppValue')
|
|
|
|
|
->with('dav', 'generateBirthdayCalendar', 'yes')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('yes');
|
2019-02-16 10:18:58 -05:00
|
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
|
->method('getUserValue')
|
|
|
|
|
->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('yes');
|
2019-02-16 10:18:58 -05:00
|
|
|
|
|
|
|
|
$this->birthdayService->expects($this->once())
|
|
|
|
|
->method('resetForUser')
|
|
|
|
|
->with('user123');
|
|
|
|
|
|
|
|
|
|
$this->birthdayService->expects($this->once())
|
|
|
|
|
->method('syncUser')
|
|
|
|
|
->with('user123');
|
|
|
|
|
|
|
|
|
|
$this->backgroundJob->run(['userId' => 'user123', 'purgeBeforeGenerating' => true]);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testRunGloballyDisabled(): void {
|
2017-11-11 05:25:40 -05:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
|
->method('getAppValue')
|
|
|
|
|
->with('dav', 'generateBirthdayCalendar', 'yes')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('no');
|
2017-11-11 05:25:40 -05:00
|
|
|
|
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
|
->method('getUserValue');
|
|
|
|
|
|
|
|
|
|
$this->birthdayService->expects($this->never())
|
|
|
|
|
->method('syncUser');
|
|
|
|
|
|
|
|
|
|
$this->backgroundJob->run(['userId' => 'user123']);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testRunUserDisabled(): void {
|
2017-11-11 05:25:40 -05:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
|
->method('getAppValue')
|
|
|
|
|
->with('dav', 'generateBirthdayCalendar', 'yes')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('yes');
|
2017-11-11 05:25:40 -05:00
|
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
|
->method('getUserValue')
|
|
|
|
|
->with('user123', 'dav', 'generateBirthdayCalendar', 'yes')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('no');
|
2017-11-11 05:25:40 -05:00
|
|
|
|
|
|
|
|
$this->birthdayService->expects($this->never())
|
|
|
|
|
->method('syncUser');
|
|
|
|
|
|
|
|
|
|
$this->backgroundJob->run(['userId' => 'user123']);
|
|
|
|
|
}
|
|
|
|
|
}
|