2018-06-28 14:07:33 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018, Georg Ehrke
|
|
|
|
*
|
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-02-10 18:04:38 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2018-06-28 14:07:33 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
2018-06-28 14:07:33 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-06-28 14:07:33 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2019-12-03 21:57:53 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-06-28 14:07:33 +03:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-06-28 14:07:33 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Tests\unit\BackgroundJob;
|
|
|
|
|
|
|
|
use OCA\DAV\BackgroundJob\RefreshWebcalJob;
|
2020-02-10 18:04:38 +03:00
|
|
|
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
|
2018-06-28 14:07:33 +03:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
|
|
|
use OCP\ILogger;
|
2020-02-10 18:04:38 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-06-28 14:07:33 +03:00
|
|
|
|
2019-11-22 22:52:10 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
2018-06-28 14:07:33 +03:00
|
|
|
class RefreshWebcalJobTest extends TestCase {
|
|
|
|
|
2020-02-10 18:04:38 +03:00
|
|
|
/** @var RefreshWebcalService | MockObject */
|
|
|
|
private $refreshWebcalService;
|
2018-06-28 14:07:33 +03:00
|
|
|
|
2020-02-10 18:04:38 +03:00
|
|
|
/** @var ILogger | MockObject */
|
2018-06-28 14:07:33 +03:00
|
|
|
private $logger;
|
|
|
|
|
2020-02-10 18:04:38 +03:00
|
|
|
/** @var ITimeFactory | MockObject */
|
2018-06-28 14:07:33 +03:00
|
|
|
private $timeFactory;
|
|
|
|
|
2020-02-10 18:04:38 +03:00
|
|
|
/** @var IJobList | MockObject */
|
2018-06-28 14:07:33 +03:00
|
|
|
private $jobList;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2018-06-28 14:07:33 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2020-02-10 18:04:38 +03:00
|
|
|
$this->refreshWebcalService = $this->createMock(RefreshWebcalService::class);
|
2018-06-28 14:07:33 +03:00
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
|
|
|
|
$this->jobList = $this->createMock(IJobList::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-10 18:04:38 +03:00
|
|
|
*
|
|
|
|
* @param int $lastRun
|
|
|
|
* @param int $time
|
|
|
|
* @param bool $process
|
2018-06-28 14:07:33 +03:00
|
|
|
*
|
|
|
|
* @dataProvider runDataProvider
|
|
|
|
*/
|
2020-02-10 18:04:38 +03:00
|
|
|
public function testRun(int $lastRun, int $time, bool $process) {
|
|
|
|
$backgroundJob = new RefreshWebcalJob($this->refreshWebcalService, $this->logger, $this->timeFactory);
|
2018-06-28 14:07:33 +03:00
|
|
|
|
|
|
|
$backgroundJob->setArgument([
|
|
|
|
'principaluri' => 'principals/users/testuser',
|
|
|
|
'uri' => 'sub123',
|
|
|
|
]);
|
2020-02-10 18:04:38 +03: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 14:07:33 +03:00
|
|
|
|
|
|
|
$this->timeFactory->expects($this->once())
|
|
|
|
->method('getTime')
|
2020-02-10 18:04:38 +03: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 14:07:33 +03:00
|
|
|
|
|
|
|
$backgroundJob->execute($this->jobList, $this->logger);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function runDataProvider():array {
|
|
|
|
return [
|
2020-02-10 18:04:38 +03:00
|
|
|
[0, 100000, true],
|
|
|
|
[100000, 100000, false]
|
2018-06-28 14:07:33 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|