2018-06-28 07:07:33 -04:00
|
|
|
<?php
|
2025-05-27 17:36:08 -04: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\DAV\Migration;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\BackgroundJob\RefreshWebcalJob;
|
|
|
|
|
use OCA\DAV\Migration\RefreshWebcalJobRegistrar;
|
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
Fix DAV unit tests
6) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAccept
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
7) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAcceptSequence
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
8) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAcceptRecurrenceId
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
9) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAcceptTokenNotFound
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
10) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAcceptExpiredToken
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
11) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testDecline
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
12) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testProcessMoreOptionsResult
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
13) OCA\DAV\Tests\unit\CalDAV\CalendarTest::testConfidentialClassification with data set #0 (3, false)
No method rule is set
14) OCA\DAV\Tests\unit\DAV\Migration\RefreshWebcalJobRegistrarTest::testRun
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
Signed-off-by: Joas Schilling <coding@schilljs.com>
2021-04-20 11:30:21 -04:00
|
|
|
use OCP\DB\IResult;
|
2018-06-28 07:07:33 -04:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\Migration\IOutput;
|
2025-05-27 17:36:08 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-06-28 07:07:33 -04:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class RefreshWebcalJobRegistrarTest extends TestCase {
|
2025-05-27 17:36:08 -04:00
|
|
|
private IDBConnection&MockObject $db;
|
|
|
|
|
private IJobList&MockObject $jobList;
|
|
|
|
|
private RefreshWebcalJobRegistrar $migration;
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2018-06-28 07:07:33 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->db = $this->createMock(IDBConnection::class);
|
|
|
|
|
$this->jobList = $this->createMock(IJobList::class);
|
|
|
|
|
|
|
|
|
|
$this->migration = new RefreshWebcalJobRegistrar($this->db, $this->jobList);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetName(): void {
|
2018-06-28 07:07:33 -04:00
|
|
|
$this->assertEquals($this->migration->getName(), 'Registering background jobs to update cache for webcal calendars');
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testRun(): void {
|
2018-06-28 07:07:33 -04:00
|
|
|
$output = $this->createMock(IOutput::class);
|
|
|
|
|
|
|
|
|
|
$queryBuilder = $this->createMock(IQueryBuilder::class);
|
Fix DAV unit tests
6) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAccept
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
7) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAcceptSequence
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
8) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAcceptRecurrenceId
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
9) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAcceptTokenNotFound
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
10) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testAcceptExpiredToken
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
11) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testDecline
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
12) OCA\DAV\Tests\Unit\DAV\Controller\InvitationResponseControllerTest::testProcessMoreOptionsResult
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
13) OCA\DAV\Tests\unit\CalDAV\CalendarTest::testConfidentialClassification with data set #0 (3, false)
No method rule is set
14) OCA\DAV\Tests\unit\DAV\Migration\RefreshWebcalJobRegistrarTest::testRun
Trying to configure method "fetch" which cannot be configured because it does not exist, has not been specified, is final, or is static
Signed-off-by: Joas Schilling <coding@schilljs.com>
2021-04-20 11:30:21 -04:00
|
|
|
$statement = $this->createMock(IResult::class);
|
2018-06-28 07:07:33 -04:00
|
|
|
|
|
|
|
|
$this->db->expects($this->once())
|
|
|
|
|
->method('getQueryBuilder')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($queryBuilder);
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2023-01-05 12:25:31 -05:00
|
|
|
$queryBuilder->expects($this->once())
|
2018-06-28 07:07:33 -04:00
|
|
|
->method('select')
|
|
|
|
|
->with(['principaluri', 'uri'])
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($queryBuilder);
|
2023-01-05 12:25:31 -05:00
|
|
|
$queryBuilder->expects($this->once())
|
2018-06-28 07:07:33 -04:00
|
|
|
->method('from')
|
|
|
|
|
->with('calendarsubscriptions')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($queryBuilder);
|
2023-01-05 12:25:31 -05:00
|
|
|
$queryBuilder->expects($this->once())
|
2025-09-12 11:17:17 -04:00
|
|
|
->method('executeQuery')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn($statement);
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2023-01-05 12:25:31 -05:00
|
|
|
$statement->expects($this->exactly(4))
|
2018-06-28 07:07:33 -04:00
|
|
|
->method('fetch')
|
|
|
|
|
->with(\PDO::FETCH_ASSOC)
|
2023-01-05 12:25:31 -05:00
|
|
|
->willReturnOnConsecutiveCalls(
|
|
|
|
|
[
|
|
|
|
|
'principaluri' => 'foo1',
|
|
|
|
|
'uri' => 'bar1',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'principaluri' => 'foo2',
|
|
|
|
|
'uri' => 'bar2',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'principaluri' => 'foo3',
|
|
|
|
|
'uri' => 'bar3',
|
|
|
|
|
],
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->jobList->expects($this->exactly(3))
|
2018-06-28 07:07:33 -04:00
|
|
|
->method('has')
|
2025-05-27 17:36:08 -04:00
|
|
|
->willReturnMap([
|
2023-01-05 12:25:31 -05:00
|
|
|
[RefreshWebcalJob::class, [
|
|
|
|
|
'principaluri' => 'foo1',
|
|
|
|
|
'uri' => 'bar1',
|
2025-05-27 17:36:08 -04:00
|
|
|
], false],
|
2023-01-05 12:25:31 -05:00
|
|
|
[RefreshWebcalJob::class, [
|
|
|
|
|
'principaluri' => 'foo2',
|
|
|
|
|
'uri' => 'bar2',
|
2025-05-27 17:36:08 -04:00
|
|
|
], true ],
|
2023-01-05 12:25:31 -05:00
|
|
|
[RefreshWebcalJob::class, [
|
|
|
|
|
'principaluri' => 'foo3',
|
|
|
|
|
'uri' => 'bar3',
|
2025-05-27 17:36:08 -04:00
|
|
|
], false],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$calls = [
|
|
|
|
|
[RefreshWebcalJob::class, [
|
|
|
|
|
'principaluri' => 'foo1',
|
|
|
|
|
'uri' => 'bar1',
|
|
|
|
|
]],
|
|
|
|
|
[RefreshWebcalJob::class, [
|
|
|
|
|
'principaluri' => 'foo3',
|
|
|
|
|
'uri' => 'bar3',
|
|
|
|
|
]]
|
|
|
|
|
];
|
2023-01-05 12:25:31 -05:00
|
|
|
$this->jobList->expects($this->exactly(2))
|
2018-06-28 07:07:33 -04:00
|
|
|
->method('add')
|
2025-06-30 10:56:59 -04:00
|
|
|
->willReturnCallback(function () use (&$calls): void {
|
2025-05-27 17:36:08 -04:00
|
|
|
$expected = array_shift($calls);
|
|
|
|
|
$this->assertEquals($expected, func_get_args());
|
|
|
|
|
});
|
2018-06-28 07:07:33 -04:00
|
|
|
|
|
|
|
|
$output->expects($this->once())
|
|
|
|
|
->method('info')
|
|
|
|
|
->with('Added 2 background jobs to update webcal calendars');
|
|
|
|
|
|
|
|
|
|
$this->migration->run($output);
|
|
|
|
|
}
|
|
|
|
|
}
|