2018-06-28 14:07:33 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018, Georg Ehrke
|
|
|
|
*
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2018-06-28 14:07:33 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
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\DAV\Migration;
|
|
|
|
|
|
|
|
use OCA\DAV\BackgroundJob\RefreshWebcalJob;
|
|
|
|
use OCA\DAV\Migration\RefreshWebcalJobRegistrar;
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class RefreshWebcalJobRegistrarTest extends TestCase {
|
|
|
|
|
|
|
|
/** @var IDBConnection | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $db;
|
|
|
|
|
|
|
|
/** @var IJobList | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $jobList;
|
|
|
|
|
|
|
|
/** @var RefreshWebcalJobRegistrar */
|
|
|
|
private $migration;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2018-06-28 14:07:33 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->db = $this->createMock(IDBConnection::class);
|
|
|
|
$this->jobList = $this->createMock(IJobList::class);
|
|
|
|
|
|
|
|
$this->migration = new RefreshWebcalJobRegistrar($this->db, $this->jobList);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetName() {
|
|
|
|
$this->assertEquals($this->migration->getName(), 'Registering background jobs to update cache for webcal calendars');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRun() {
|
|
|
|
$output = $this->createMock(IOutput::class);
|
|
|
|
|
|
|
|
$queryBuilder = $this->createMock(IQueryBuilder::class);
|
|
|
|
$statement = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
|
|
|
|
|
|
|
|
$this->db->expects($this->once())
|
|
|
|
->method('getQueryBuilder')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($queryBuilder);
|
2018-06-28 14:07:33 +03:00
|
|
|
|
|
|
|
$queryBuilder->expects($this->at(0))
|
|
|
|
->method('select')
|
|
|
|
->with(['principaluri', 'uri'])
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($queryBuilder);
|
2018-06-28 14:07:33 +03:00
|
|
|
$queryBuilder->expects($this->at(1))
|
|
|
|
->method('from')
|
|
|
|
->with('calendarsubscriptions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($queryBuilder);
|
2018-06-28 14:07:33 +03:00
|
|
|
$queryBuilder->expects($this->at(2))
|
|
|
|
->method('execute')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($statement);
|
2018-06-28 14:07:33 +03:00
|
|
|
|
|
|
|
$statement->expects($this->at(0))
|
|
|
|
->method('fetch')
|
|
|
|
->with(\PDO::FETCH_ASSOC)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([
|
2018-06-28 14:07:33 +03:00
|
|
|
'principaluri' => 'foo1',
|
|
|
|
'uri' => 'bar1',
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2018-06-28 14:07:33 +03:00
|
|
|
$statement->expects($this->at(1))
|
|
|
|
->method('fetch')
|
|
|
|
->with(\PDO::FETCH_ASSOC)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([
|
2018-06-28 14:07:33 +03:00
|
|
|
'principaluri' => 'foo2',
|
|
|
|
'uri' => 'bar2',
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2018-06-28 14:07:33 +03:00
|
|
|
$statement->expects($this->at(2))
|
|
|
|
->method('fetch')
|
|
|
|
->with(\PDO::FETCH_ASSOC)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([
|
2018-06-28 14:07:33 +03:00
|
|
|
'principaluri' => 'foo3',
|
|
|
|
'uri' => 'bar3',
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2018-06-28 14:07:33 +03:00
|
|
|
$statement->expects($this->at(0))
|
|
|
|
->method('fetch')
|
|
|
|
->with(\PDO::FETCH_ASSOC)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2018-06-28 14:07:33 +03:00
|
|
|
|
|
|
|
$this->jobList->expects($this->at(0))
|
|
|
|
->method('has')
|
|
|
|
->with(RefreshWebcalJob::class, [
|
|
|
|
'principaluri' => 'foo1',
|
|
|
|
'uri' => 'bar1',
|
|
|
|
])
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2018-06-28 14:07:33 +03:00
|
|
|
$this->jobList->expects($this->at(1))
|
|
|
|
->method('add')
|
|
|
|
->with(RefreshWebcalJob::class, [
|
|
|
|
'principaluri' => 'foo1',
|
|
|
|
'uri' => 'bar1',
|
|
|
|
]);
|
|
|
|
$this->jobList->expects($this->at(2))
|
|
|
|
->method('has')
|
|
|
|
->with(RefreshWebcalJob::class, [
|
|
|
|
'principaluri' => 'foo2',
|
|
|
|
'uri' => 'bar2',
|
|
|
|
])
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2018-06-28 14:07:33 +03:00
|
|
|
$this->jobList->expects($this->at(3))
|
|
|
|
->method('has')
|
|
|
|
->with(RefreshWebcalJob::class, [
|
|
|
|
'principaluri' => 'foo3',
|
|
|
|
'uri' => 'bar3',
|
|
|
|
])
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2018-06-28 14:07:33 +03:00
|
|
|
$this->jobList->expects($this->at(4))
|
|
|
|
->method('add')
|
|
|
|
->with(RefreshWebcalJob::class, [
|
|
|
|
'principaluri' => 'foo3',
|
|
|
|
'uri' => 'bar3',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$output->expects($this->once())
|
|
|
|
->method('info')
|
|
|
|
->with('Added 2 background jobs to update webcal calendars');
|
|
|
|
|
|
|
|
$this->migration->run($output);
|
|
|
|
}
|
|
|
|
}
|