2018-06-28 07:07:33 -04:00
|
|
|
<?php
|
2022-02-22 05:24:38 -05:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2018-06-28 07:07:33 -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-28 07:07:33 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\DAV\Tests\unit\BackgroundJob;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\BackgroundJob\RefreshWebcalJob;
|
2020-02-10 10:04:38 -05:00
|
|
|
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
|
2018-06-28 07:07:33 -04:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
2020-02-10 07:52:57 -05:00
|
|
|
use OCP\IConfig;
|
2020-02-10 10:04:38 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2024-02-08 05:52:40 -05:00
|
|
|
use Psr\Log\LoggerInterface;
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
2018-06-28 07:07:33 -04:00
|
|
|
class RefreshWebcalJobTest extends TestCase {
|
|
|
|
|
|
2020-02-10 10:04:38 -05:00
|
|
|
/** @var RefreshWebcalService | MockObject */
|
|
|
|
|
private $refreshWebcalService;
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2020-02-10 07:52:57 -05:00
|
|
|
/** @var IConfig | MockObject */
|
|
|
|
|
private $config;
|
|
|
|
|
|
2024-02-08 05:52:40 -05:00
|
|
|
private LoggerInterface $logger;
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2020-02-10 10:04:38 -05:00
|
|
|
/** @var ITimeFactory | MockObject */
|
2018-06-28 07:07:33 -04:00
|
|
|
private $timeFactory;
|
|
|
|
|
|
2020-02-10 10:04:38 -05:00
|
|
|
/** @var IJobList | MockObject */
|
2018-06-28 07:07:33 -04:00
|
|
|
private $jobList;
|
|
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2018-06-28 07:07:33 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2020-02-10 10:04:38 -05:00
|
|
|
$this->refreshWebcalService = $this->createMock(RefreshWebcalService::class);
|
2020-02-10 07:52:57 -05:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2024-02-08 05:52:40 -05:00
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
2018-06-28 07:07:33 -04:00
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
|
|
|
|
|
|
$this->jobList = $this->createMock(IJobList::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-02-10 10:04:38 -05:00
|
|
|
*
|
|
|
|
|
* @param int $lastRun
|
|
|
|
|
* @param int $time
|
|
|
|
|
* @param bool $process
|
2018-06-28 07:07:33 -04:00
|
|
|
*
|
|
|
|
|
* @dataProvider runDataProvider
|
|
|
|
|
*/
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testRun(int $lastRun, int $time, bool $process): void {
|
2020-02-10 07:52:57 -05:00
|
|
|
$backgroundJob = new RefreshWebcalJob($this->refreshWebcalService, $this->config, $this->logger, $this->timeFactory);
|
2020-11-24 08:18:47 -05:00
|
|
|
$backgroundJob->setId(42);
|
2018-06-28 07:07:33 -04:00
|
|
|
|
|
|
|
|
$backgroundJob->setArgument([
|
|
|
|
|
'principaluri' => 'principals/users/testuser',
|
|
|
|
|
'uri' => 'sub123',
|
|
|
|
|
]);
|
2020-02-10 10:04:38 -05:00
|
|
|
$backgroundJob->setLastRun($lastRun);
|
|
|
|
|
|
|
|
|
|
$this->refreshWebcalService->expects($this->once())
|
|
|
|
|
->method('getSubscription')
|
|
|
|
|
->with('principals/users/testuser', 'sub123')
|
|
|
|
|
->willReturn([
|
|
|
|
|
'id' => '99',
|
|
|
|
|
'uri' => 'sub456',
|
|
|
|
|
'{http://apple.com/ns/ical/}refreshrate' => 'P1D',
|
|
|
|
|
'{http://calendarserver.org/ns/}subscribed-strip-todos' => '1',
|
|
|
|
|
'{http://calendarserver.org/ns/}subscribed-strip-alarms' => '1',
|
|
|
|
|
'{http://calendarserver.org/ns/}subscribed-strip-attachments' => '1',
|
|
|
|
|
'source' => 'webcal://foo.bar/bla'
|
|
|
|
|
]);
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2020-02-10 07:52:57 -05:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
|
->method('getAppValue')
|
|
|
|
|
->with('dav', 'calendarSubscriptionRefreshRate', 'P1W')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn('P1W');
|
2020-02-10 07:52:57 -05:00
|
|
|
|
2020-11-24 08:18:47 -05:00
|
|
|
$this->timeFactory->method('getTime')
|
2020-02-10 10:04:38 -05:00
|
|
|
->willReturn($time);
|
|
|
|
|
|
|
|
|
|
if ($process) {
|
|
|
|
|
$this->refreshWebcalService->expects($this->once())
|
|
|
|
|
->method('refreshSubscription')
|
|
|
|
|
->with('principals/users/testuser', 'sub123');
|
|
|
|
|
} else {
|
|
|
|
|
$this->refreshWebcalService->expects($this->never())
|
|
|
|
|
->method('refreshSubscription')
|
|
|
|
|
->with('principals/users/testuser', 'sub123');
|
|
|
|
|
}
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2024-02-08 05:52:40 -05:00
|
|
|
$backgroundJob->start($this->jobList);
|
2018-06-28 07:07:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function runDataProvider():array {
|
|
|
|
|
return [
|
2020-02-10 10:04:38 -05:00
|
|
|
[0, 100000, true],
|
|
|
|
|
[100000, 100000, false]
|
2018-06-28 07:07:33 -04:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|