aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/CalDAV/CachedSubscriptionProviderTest.php
blob: 22998eec3d922e49ffdd9ea32b02d979b453ab68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCA\DAV\Tests\unit\CalDAV;

use OCA\DAV\CalDAV\CachedSubscriptionImpl;
use OCA\DAV\CalDAV\CachedSubscriptionProvider;
use OCA\DAV\CalDAV\CalDavBackend;
use Test\TestCase;

class CachedSubscriptionProviderTest extends TestCase {

	private CalDavBackend $backend;
	private CachedSubscriptionProvider $provider;

	protected function setUp(): void {
		parent::setUp();

		$this->backend = $this->createMock(CalDavBackend::class);
		$this->backend
			->expects(self::once())
			->method('getSubscriptionsForUser')
			->with('user-principal-123')
			->willReturn([
				[
					'id' => 'subscription-1',
					'uri' => 'subscription-1',
					'principaluris' => 'user-principal-123',
					'source' => 'https://localhost/subscription-1',
					// A subscription array has actually more properties.
				],
				[
					'id' => 'subscription-2',
					'uri' => 'subscription-2',
					'principaluri' => 'user-principal-123',
					'source' => 'https://localhost/subscription-2',
					// A subscription array has actually more properties.
				]
			]);

		$this->provider = new CachedSubscriptionProvider($this->backend);
	}

	public function testGetCalendars() {
		$calendars = $this->provider->getCalendars(
			'user-principal-123',
			[]
		);

		$this->assertCount(2, $calendars);
		$this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]);
		$this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[1]);
	}

	public function testGetCalendarsFilterByUri() {
		$calendars = $this->provider->getCalendars(
			'user-principal-123',
			['subscription-1']
		);

		$this->assertCount(1, $calendars);
		$this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]);
		$this->assertEquals('subscription-1', $calendars[0]->getUri());
	}
}