Completed
Push — master ( 5d14f8...2337bd )
by Robin
27:19 queued 16s
created
apps/dav/tests/unit/CardDAV/AddressBookTest.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -19,166 +19,166 @@
 block discarded – undo
19 19
 use Test\TestCase;
20 20
 
21 21
 class AddressBookTest extends TestCase {
22
-	public function testMove(): void {
23
-		$backend = $this->createMock(CardDavBackend::class);
24
-		$addressBookInfo = [
25
-			'{http://owncloud.org/ns}owner-principal' => 'user1',
26
-			'{DAV:}displayname' => 'Test address book',
27
-			'principaluri' => 'user2',
28
-			'id' => 666,
29
-			'uri' => 'default',
30
-		];
31
-		$l10n = $this->createMock(IL10N::class);
32
-		$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
33
-
34
-		$card = new Card($backend, $addressBookInfo, ['id' => 5, 'carddata' => 'RANDOM VCF DATA', 'uri' => 'something', 'addressbookid' => 23]);
35
-
36
-		$backend->expects($this->once())->method('moveCard')
37
-			->with(23, 666, 'something', 'user1')
38
-			->willReturn(true);
39
-
40
-		$addressBook->moveInto('new', 'old', $card);
41
-	}
42
-
43
-	public function testDelete(): void {
44
-		/** @var MockObject | CardDavBackend $backend */
45
-		$backend = $this->createMock(CardDavBackend::class);
46
-		$backend->expects($this->once())->method('updateShares');
47
-		$backend->expects($this->any())->method('getShares')->willReturn([
48
-			['href' => 'principal:user2']
49
-		]);
50
-		$addressBookInfo = [
51
-			'{http://owncloud.org/ns}owner-principal' => 'user1',
52
-			'{DAV:}displayname' => 'Test address book',
53
-			'principaluri' => 'user2',
54
-			'id' => 666,
55
-			'uri' => 'default',
56
-		];
57
-		$l10n = $this->createMock(IL10N::class);
58
-		$logger = $this->createMock(LoggerInterface::class);
59
-		$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
60
-		$addressBook->delete();
61
-	}
62
-
63
-
64
-	public function testDeleteFromGroup(): void {
65
-		$this->expectException(Forbidden::class);
66
-
67
-		/** @var MockObject | CardDavBackend $backend */
68
-		$backend = $this->createMock(CardDavBackend::class);
69
-		$backend->expects($this->never())->method('updateShares');
70
-		$backend->expects($this->any())->method('getShares')->willReturn([
71
-			['href' => 'principal:group2']
72
-		]);
73
-		$addressBookInfo = [
74
-			'{http://owncloud.org/ns}owner-principal' => 'user1',
75
-			'{DAV:}displayname' => 'Test address book',
76
-			'principaluri' => 'user2',
77
-			'id' => 666,
78
-			'uri' => 'default',
79
-		];
80
-		$l10n = $this->createMock(IL10N::class);
81
-		$logger = $this->createMock(LoggerInterface::class);
82
-		$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
83
-		$addressBook->delete();
84
-	}
85
-
86
-
87
-	public function testPropPatchShared(): void {
88
-		/** @var MockObject | CardDavBackend $backend */
89
-		$backend = $this->createMock(CardDavBackend::class);
90
-		$backend->expects($this->never())->method('updateAddressBook');
91
-		$addressBookInfo = [
92
-			'{http://owncloud.org/ns}owner-principal' => 'user1',
93
-			'{DAV:}displayname' => 'Test address book',
94
-			'principaluri' => 'user2',
95
-			'id' => 666,
96
-			'uri' => 'default',
97
-		];
98
-		$l10n = $this->createMock(IL10N::class);
99
-		$logger = $this->createMock(LoggerInterface::class);
100
-		$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
101
-		$addressBook->propPatch(new PropPatch(['{DAV:}displayname' => 'Test address book']));
102
-	}
103
-
104
-	public function testPropPatchNotShared(): void {
105
-		/** @var MockObject | CardDavBackend $backend */
106
-		$backend = $this->createMock(CardDavBackend::class);
107
-		$backend->expects($this->atLeast(1))->method('updateAddressBook');
108
-		$addressBookInfo = [
109
-			'{DAV:}displayname' => 'Test address book',
110
-			'principaluri' => 'user1',
111
-			'id' => 666,
112
-			'uri' => 'default',
113
-		];
114
-		$l10n = $this->createMock(IL10N::class);
115
-		$logger = $this->createMock(LoggerInterface::class);
116
-		$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
117
-		$addressBook->propPatch(new PropPatch(['{DAV:}displayname' => 'Test address book']));
118
-	}
119
-
120
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesReadOnlyInfo')]
121
-	public function testAcl(bool $expectsWrite, ?bool $readOnlyValue, bool $hasOwnerSet): void {
122
-		/** @var MockObject | CardDavBackend $backend */
123
-		$backend = $this->createMock(CardDavBackend::class);
124
-		$backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
125
-		$addressBookInfo = [
126
-			'{DAV:}displayname' => 'Test address book',
127
-			'principaluri' => 'user2',
128
-			'id' => 666,
129
-			'uri' => 'default'
130
-		];
131
-		if (!is_null($readOnlyValue)) {
132
-			$addressBookInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue;
133
-		}
134
-		if ($hasOwnerSet) {
135
-			$addressBookInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
136
-		}
137
-		$l10n = $this->createMock(IL10N::class);
138
-		$logger = $this->createMock(LoggerInterface::class);
139
-		$addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
140
-		$acl = $addressBook->getACL();
141
-		$childAcl = $addressBook->getChildACL();
142
-
143
-		$expectedAcl = [[
144
-			'privilege' => '{DAV:}read',
145
-			'principal' => $hasOwnerSet ? 'user1' : 'user2',
146
-			'protected' => true
147
-		], [
148
-			'privilege' => '{DAV:}write',
149
-			'principal' => $hasOwnerSet ? 'user1' : 'user2',
150
-			'protected' => true
151
-		], [
152
-			'privilege' => '{DAV:}write-properties',
153
-			'principal' => $hasOwnerSet ? 'user1' : 'user2',
154
-			'protected' => true
155
-		]];
156
-		if ($hasOwnerSet) {
157
-			$expectedAcl[] = [
158
-				'privilege' => '{DAV:}read',
159
-				'principal' => 'user2',
160
-				'protected' => true
161
-			];
162
-			if ($expectsWrite) {
163
-				$expectedAcl[] = [
164
-					'privilege' => '{DAV:}write',
165
-					'principal' => 'user2',
166
-					'protected' => true
167
-				];
168
-			}
169
-		}
170
-		$this->assertEquals($expectedAcl, $acl);
171
-		$this->assertEquals($expectedAcl, $childAcl);
172
-	}
173
-
174
-	public static function providesReadOnlyInfo(): array {
175
-		return [
176
-			'read-only property not set' => [true, null, true],
177
-			'read-only property is false' => [true, false, true],
178
-			'read-only property is true' => [false, true, true],
179
-			'read-only property not set and no owner' => [true, null, false],
180
-			'read-only property is false and no owner' => [true, false, false],
181
-			'read-only property is true and no owner' => [false, true, false],
182
-		];
183
-	}
22
+    public function testMove(): void {
23
+        $backend = $this->createMock(CardDavBackend::class);
24
+        $addressBookInfo = [
25
+            '{http://owncloud.org/ns}owner-principal' => 'user1',
26
+            '{DAV:}displayname' => 'Test address book',
27
+            'principaluri' => 'user2',
28
+            'id' => 666,
29
+            'uri' => 'default',
30
+        ];
31
+        $l10n = $this->createMock(IL10N::class);
32
+        $addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
33
+
34
+        $card = new Card($backend, $addressBookInfo, ['id' => 5, 'carddata' => 'RANDOM VCF DATA', 'uri' => 'something', 'addressbookid' => 23]);
35
+
36
+        $backend->expects($this->once())->method('moveCard')
37
+            ->with(23, 666, 'something', 'user1')
38
+            ->willReturn(true);
39
+
40
+        $addressBook->moveInto('new', 'old', $card);
41
+    }
42
+
43
+    public function testDelete(): void {
44
+        /** @var MockObject | CardDavBackend $backend */
45
+        $backend = $this->createMock(CardDavBackend::class);
46
+        $backend->expects($this->once())->method('updateShares');
47
+        $backend->expects($this->any())->method('getShares')->willReturn([
48
+            ['href' => 'principal:user2']
49
+        ]);
50
+        $addressBookInfo = [
51
+            '{http://owncloud.org/ns}owner-principal' => 'user1',
52
+            '{DAV:}displayname' => 'Test address book',
53
+            'principaluri' => 'user2',
54
+            'id' => 666,
55
+            'uri' => 'default',
56
+        ];
57
+        $l10n = $this->createMock(IL10N::class);
58
+        $logger = $this->createMock(LoggerInterface::class);
59
+        $addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
60
+        $addressBook->delete();
61
+    }
62
+
63
+
64
+    public function testDeleteFromGroup(): void {
65
+        $this->expectException(Forbidden::class);
66
+
67
+        /** @var MockObject | CardDavBackend $backend */
68
+        $backend = $this->createMock(CardDavBackend::class);
69
+        $backend->expects($this->never())->method('updateShares');
70
+        $backend->expects($this->any())->method('getShares')->willReturn([
71
+            ['href' => 'principal:group2']
72
+        ]);
73
+        $addressBookInfo = [
74
+            '{http://owncloud.org/ns}owner-principal' => 'user1',
75
+            '{DAV:}displayname' => 'Test address book',
76
+            'principaluri' => 'user2',
77
+            'id' => 666,
78
+            'uri' => 'default',
79
+        ];
80
+        $l10n = $this->createMock(IL10N::class);
81
+        $logger = $this->createMock(LoggerInterface::class);
82
+        $addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
83
+        $addressBook->delete();
84
+    }
85
+
86
+
87
+    public function testPropPatchShared(): void {
88
+        /** @var MockObject | CardDavBackend $backend */
89
+        $backend = $this->createMock(CardDavBackend::class);
90
+        $backend->expects($this->never())->method('updateAddressBook');
91
+        $addressBookInfo = [
92
+            '{http://owncloud.org/ns}owner-principal' => 'user1',
93
+            '{DAV:}displayname' => 'Test address book',
94
+            'principaluri' => 'user2',
95
+            'id' => 666,
96
+            'uri' => 'default',
97
+        ];
98
+        $l10n = $this->createMock(IL10N::class);
99
+        $logger = $this->createMock(LoggerInterface::class);
100
+        $addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
101
+        $addressBook->propPatch(new PropPatch(['{DAV:}displayname' => 'Test address book']));
102
+    }
103
+
104
+    public function testPropPatchNotShared(): void {
105
+        /** @var MockObject | CardDavBackend $backend */
106
+        $backend = $this->createMock(CardDavBackend::class);
107
+        $backend->expects($this->atLeast(1))->method('updateAddressBook');
108
+        $addressBookInfo = [
109
+            '{DAV:}displayname' => 'Test address book',
110
+            'principaluri' => 'user1',
111
+            'id' => 666,
112
+            'uri' => 'default',
113
+        ];
114
+        $l10n = $this->createMock(IL10N::class);
115
+        $logger = $this->createMock(LoggerInterface::class);
116
+        $addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
117
+        $addressBook->propPatch(new PropPatch(['{DAV:}displayname' => 'Test address book']));
118
+    }
119
+
120
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesReadOnlyInfo')]
121
+    public function testAcl(bool $expectsWrite, ?bool $readOnlyValue, bool $hasOwnerSet): void {
122
+        /** @var MockObject | CardDavBackend $backend */
123
+        $backend = $this->createMock(CardDavBackend::class);
124
+        $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
125
+        $addressBookInfo = [
126
+            '{DAV:}displayname' => 'Test address book',
127
+            'principaluri' => 'user2',
128
+            'id' => 666,
129
+            'uri' => 'default'
130
+        ];
131
+        if (!is_null($readOnlyValue)) {
132
+            $addressBookInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue;
133
+        }
134
+        if ($hasOwnerSet) {
135
+            $addressBookInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
136
+        }
137
+        $l10n = $this->createMock(IL10N::class);
138
+        $logger = $this->createMock(LoggerInterface::class);
139
+        $addressBook = new AddressBook($backend, $addressBookInfo, $l10n);
140
+        $acl = $addressBook->getACL();
141
+        $childAcl = $addressBook->getChildACL();
142
+
143
+        $expectedAcl = [[
144
+            'privilege' => '{DAV:}read',
145
+            'principal' => $hasOwnerSet ? 'user1' : 'user2',
146
+            'protected' => true
147
+        ], [
148
+            'privilege' => '{DAV:}write',
149
+            'principal' => $hasOwnerSet ? 'user1' : 'user2',
150
+            'protected' => true
151
+        ], [
152
+            'privilege' => '{DAV:}write-properties',
153
+            'principal' => $hasOwnerSet ? 'user1' : 'user2',
154
+            'protected' => true
155
+        ]];
156
+        if ($hasOwnerSet) {
157
+            $expectedAcl[] = [
158
+                'privilege' => '{DAV:}read',
159
+                'principal' => 'user2',
160
+                'protected' => true
161
+            ];
162
+            if ($expectsWrite) {
163
+                $expectedAcl[] = [
164
+                    'privilege' => '{DAV:}write',
165
+                    'principal' => 'user2',
166
+                    'protected' => true
167
+                ];
168
+            }
169
+        }
170
+        $this->assertEquals($expectedAcl, $acl);
171
+        $this->assertEquals($expectedAcl, $childAcl);
172
+    }
173
+
174
+    public static function providesReadOnlyInfo(): array {
175
+        return [
176
+            'read-only property not set' => [true, null, true],
177
+            'read-only property is false' => [true, false, true],
178
+            'read-only property is true' => [false, true, true],
179
+            'read-only property not set and no owner' => [true, null, false],
180
+            'read-only property is false and no owner' => [true, false, false],
181
+            'read-only property is true and no owner' => [false, true, false],
182
+        ];
183
+    }
184 184
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/CardDAV/SyncServiceTest.php 1 patch
Indentation   +371 added lines, -371 removed lines patch added patch discarded remove patch
@@ -29,103 +29,103 @@  discard block
 block discarded – undo
29 29
 
30 30
 class SyncServiceTest extends TestCase {
31 31
 
32
-	protected CardDavBackend&MockObject $backend;
33
-	protected IUserManager&MockObject $userManager;
34
-	protected IDBConnection&MockObject $dbConnection;
35
-	protected LoggerInterface $logger;
36
-	protected Converter&MockObject $converter;
37
-	protected IClient&MockObject $client;
38
-	protected IConfig&MockObject $config;
39
-	protected SyncService $service;
40
-
41
-	public function setUp(): void {
42
-		parent::setUp();
43
-
44
-		$addressBook = [
45
-			'id' => 1,
46
-			'uri' => 'system',
47
-			'principaluri' => 'principals/system/system',
48
-			'{DAV:}displayname' => 'system',
49
-			// watch out, incomplete address book mock.
50
-		];
51
-
52
-		$this->backend = $this->createMock(CardDavBackend::class);
53
-		$this->backend->method('getAddressBooksByUri')
54
-			->with('principals/system/system', 1)
55
-			->willReturn($addressBook);
56
-
57
-		$this->userManager = $this->createMock(IUserManager::class);
58
-		$this->dbConnection = $this->createMock(IDBConnection::class);
59
-		$this->logger = new NullLogger();
60
-		$this->converter = $this->createMock(Converter::class);
61
-		$this->client = $this->createMock(IClient::class);
62
-		$this->config = $this->createMock(IConfig::class);
63
-
64
-		$clientService = $this->createMock(IClientService::class);
65
-		$clientService->method('newClient')
66
-			->willReturn($this->client);
67
-
68
-		$this->service = new SyncService(
69
-			$this->backend,
70
-			$this->userManager,
71
-			$this->dbConnection,
72
-			$this->logger,
73
-			$this->converter,
74
-			$clientService,
75
-			$this->config
76
-		);
77
-	}
78
-
79
-	public function testEmptySync(): void {
80
-		$this->backend->expects($this->exactly(0))
81
-			->method('createCard');
82
-		$this->backend->expects($this->exactly(0))
83
-			->method('updateCard');
84
-		$this->backend->expects($this->exactly(0))
85
-			->method('deleteCard');
86
-
87
-		$body = '<?xml version="1.0"?>
32
+    protected CardDavBackend&MockObject $backend;
33
+    protected IUserManager&MockObject $userManager;
34
+    protected IDBConnection&MockObject $dbConnection;
35
+    protected LoggerInterface $logger;
36
+    protected Converter&MockObject $converter;
37
+    protected IClient&MockObject $client;
38
+    protected IConfig&MockObject $config;
39
+    protected SyncService $service;
40
+
41
+    public function setUp(): void {
42
+        parent::setUp();
43
+
44
+        $addressBook = [
45
+            'id' => 1,
46
+            'uri' => 'system',
47
+            'principaluri' => 'principals/system/system',
48
+            '{DAV:}displayname' => 'system',
49
+            // watch out, incomplete address book mock.
50
+        ];
51
+
52
+        $this->backend = $this->createMock(CardDavBackend::class);
53
+        $this->backend->method('getAddressBooksByUri')
54
+            ->with('principals/system/system', 1)
55
+            ->willReturn($addressBook);
56
+
57
+        $this->userManager = $this->createMock(IUserManager::class);
58
+        $this->dbConnection = $this->createMock(IDBConnection::class);
59
+        $this->logger = new NullLogger();
60
+        $this->converter = $this->createMock(Converter::class);
61
+        $this->client = $this->createMock(IClient::class);
62
+        $this->config = $this->createMock(IConfig::class);
63
+
64
+        $clientService = $this->createMock(IClientService::class);
65
+        $clientService->method('newClient')
66
+            ->willReturn($this->client);
67
+
68
+        $this->service = new SyncService(
69
+            $this->backend,
70
+            $this->userManager,
71
+            $this->dbConnection,
72
+            $this->logger,
73
+            $this->converter,
74
+            $clientService,
75
+            $this->config
76
+        );
77
+    }
78
+
79
+    public function testEmptySync(): void {
80
+        $this->backend->expects($this->exactly(0))
81
+            ->method('createCard');
82
+        $this->backend->expects($this->exactly(0))
83
+            ->method('updateCard');
84
+        $this->backend->expects($this->exactly(0))
85
+            ->method('deleteCard');
86
+
87
+        $body = '<?xml version="1.0"?>
88 88
 <d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:oc="http://owncloud.org/ns">
89 89
     <d:sync-token>http://sabre.io/ns/sync/1</d:sync-token>
90 90
 </d:multistatus>';
91 91
 
92
-		$requestResponse = new Response(new PsrResponse(
93
-			207,
94
-			['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
95
-			$body
96
-		));
97
-
98
-		$this->client
99
-			->method('request')
100
-			->willReturn($requestResponse);
101
-
102
-		$token = $this->service->syncRemoteAddressBook(
103
-			'',
104
-			'system',
105
-			'system',
106
-			'1234567890',
107
-			null,
108
-			'1',
109
-			'principals/system/system',
110
-			[]
111
-		);
112
-
113
-		$this->assertEquals('http://sabre.io/ns/sync/1', $token);
114
-	}
115
-
116
-	public function testSyncWithNewElement(): void {
117
-		$this->backend->expects($this->exactly(1))
118
-			->method('createCard');
119
-		$this->backend->expects($this->exactly(0))
120
-			->method('updateCard');
121
-		$this->backend->expects($this->exactly(0))
122
-			->method('deleteCard');
123
-
124
-		$this->backend->method('getCard')
125
-			->willReturn(false);
126
-
127
-
128
-		$body = '<?xml version="1.0"?>
92
+        $requestResponse = new Response(new PsrResponse(
93
+            207,
94
+            ['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
95
+            $body
96
+        ));
97
+
98
+        $this->client
99
+            ->method('request')
100
+            ->willReturn($requestResponse);
101
+
102
+        $token = $this->service->syncRemoteAddressBook(
103
+            '',
104
+            'system',
105
+            'system',
106
+            '1234567890',
107
+            null,
108
+            '1',
109
+            'principals/system/system',
110
+            []
111
+        );
112
+
113
+        $this->assertEquals('http://sabre.io/ns/sync/1', $token);
114
+    }
115
+
116
+    public function testSyncWithNewElement(): void {
117
+        $this->backend->expects($this->exactly(1))
118
+            ->method('createCard');
119
+        $this->backend->expects($this->exactly(0))
120
+            ->method('updateCard');
121
+        $this->backend->expects($this->exactly(0))
122
+            ->method('deleteCard');
123
+
124
+        $this->backend->method('getCard')
125
+            ->willReturn(false);
126
+
127
+
128
+        $body = '<?xml version="1.0"?>
129 129
 <d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:oc="http://owncloud.org/ns">
130 130
     <d:response>
131 131
         <d:href>/remote.php/dav/addressbooks/system/system/system/Database:alice.vcf</d:href>
@@ -140,17 +140,17 @@  discard block
 block discarded – undo
140 140
     <d:sync-token>http://sabre.io/ns/sync/2</d:sync-token>
141 141
 </d:multistatus>';
142 142
 
143
-		$reportResponse = new Response(new PsrResponse(
144
-			207,
145
-			['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
146
-			$body
147
-		));
143
+        $reportResponse = new Response(new PsrResponse(
144
+            207,
145
+            ['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
146
+            $body
147
+        ));
148 148
 
149
-		$this->client
150
-			->method('request')
151
-			->willReturn($reportResponse);
149
+        $this->client
150
+            ->method('request')
151
+            ->willReturn($reportResponse);
152 152
 
153
-		$vCard = 'BEGIN:VCARD
153
+        $vCard = 'BEGIN:VCARD
154 154
 VERSION:3.0
155 155
 PRODID:-//Sabre//Sabre VObject 4.5.4//EN
156 156
 UID:alice
@@ -160,43 +160,43 @@  discard block
 block discarded – undo
160 160
 CLOUD:[email protected]
161 161
 END:VCARD';
162 162
 
163
-		$getResponse = new Response(new PsrResponse(
164
-			200,
165
-			['Content-Type' => 'text/vcard; charset=utf-8', 'Content-Length' => strlen($vCard)],
166
-			$vCard,
167
-		));
168
-
169
-		$this->client
170
-			->method('get')
171
-			->willReturn($getResponse);
172
-
173
-		$token = $this->service->syncRemoteAddressBook(
174
-			'',
175
-			'system',
176
-			'system',
177
-			'1234567890',
178
-			null,
179
-			'1',
180
-			'principals/system/system',
181
-			[]
182
-		);
183
-
184
-		$this->assertEquals('http://sabre.io/ns/sync/2', $token);
185
-	}
186
-
187
-	public function testSyncWithUpdatedElement(): void {
188
-		$this->backend->expects($this->exactly(0))
189
-			->method('createCard');
190
-		$this->backend->expects($this->exactly(1))
191
-			->method('updateCard');
192
-		$this->backend->expects($this->exactly(0))
193
-			->method('deleteCard');
194
-
195
-		$this->backend->method('getCard')
196
-			->willReturn(true);
197
-
198
-
199
-		$body = '<?xml version="1.0"?>
163
+        $getResponse = new Response(new PsrResponse(
164
+            200,
165
+            ['Content-Type' => 'text/vcard; charset=utf-8', 'Content-Length' => strlen($vCard)],
166
+            $vCard,
167
+        ));
168
+
169
+        $this->client
170
+            ->method('get')
171
+            ->willReturn($getResponse);
172
+
173
+        $token = $this->service->syncRemoteAddressBook(
174
+            '',
175
+            'system',
176
+            'system',
177
+            '1234567890',
178
+            null,
179
+            '1',
180
+            'principals/system/system',
181
+            []
182
+        );
183
+
184
+        $this->assertEquals('http://sabre.io/ns/sync/2', $token);
185
+    }
186
+
187
+    public function testSyncWithUpdatedElement(): void {
188
+        $this->backend->expects($this->exactly(0))
189
+            ->method('createCard');
190
+        $this->backend->expects($this->exactly(1))
191
+            ->method('updateCard');
192
+        $this->backend->expects($this->exactly(0))
193
+            ->method('deleteCard');
194
+
195
+        $this->backend->method('getCard')
196
+            ->willReturn(true);
197
+
198
+
199
+        $body = '<?xml version="1.0"?>
200 200
 <d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:oc="http://owncloud.org/ns">
201 201
     <d:response>
202 202
         <d:href>/remote.php/dav/addressbooks/system/system/system/Database:alice.vcf</d:href>
@@ -211,17 +211,17 @@  discard block
 block discarded – undo
211 211
     <d:sync-token>http://sabre.io/ns/sync/3</d:sync-token>
212 212
 </d:multistatus>';
213 213
 
214
-		$reportResponse = new Response(new PsrResponse(
215
-			207,
216
-			['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
217
-			$body
218
-		));
214
+        $reportResponse = new Response(new PsrResponse(
215
+            207,
216
+            ['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
217
+            $body
218
+        ));
219 219
 
220
-		$this->client
221
-			->method('request')
222
-			->willReturn($reportResponse);
220
+        $this->client
221
+            ->method('request')
222
+            ->willReturn($reportResponse);
223 223
 
224
-		$vCard = 'BEGIN:VCARD
224
+        $vCard = 'BEGIN:VCARD
225 225
 VERSION:3.0
226 226
 PRODID:-//Sabre//Sabre VObject 4.5.4//EN
227 227
 UID:alice
@@ -231,39 +231,39 @@  discard block
 block discarded – undo
231 231
 CLOUD:[email protected]
232 232
 END:VCARD';
233 233
 
234
-		$getResponse = new Response(new PsrResponse(
235
-			200,
236
-			['Content-Type' => 'text/vcard; charset=utf-8', 'Content-Length' => strlen($vCard)],
237
-			$vCard,
238
-		));
239
-
240
-		$this->client
241
-			->method('get')
242
-			->willReturn($getResponse);
243
-
244
-		$token = $this->service->syncRemoteAddressBook(
245
-			'',
246
-			'system',
247
-			'system',
248
-			'1234567890',
249
-			null,
250
-			'1',
251
-			'principals/system/system',
252
-			[]
253
-		);
254
-
255
-		$this->assertEquals('http://sabre.io/ns/sync/3', $token);
256
-	}
257
-
258
-	public function testSyncWithDeletedElement(): void {
259
-		$this->backend->expects($this->exactly(0))
260
-			->method('createCard');
261
-		$this->backend->expects($this->exactly(0))
262
-			->method('updateCard');
263
-		$this->backend->expects($this->exactly(1))
264
-			->method('deleteCard');
265
-
266
-		$body = '<?xml version="1.0"?>
234
+        $getResponse = new Response(new PsrResponse(
235
+            200,
236
+            ['Content-Type' => 'text/vcard; charset=utf-8', 'Content-Length' => strlen($vCard)],
237
+            $vCard,
238
+        ));
239
+
240
+        $this->client
241
+            ->method('get')
242
+            ->willReturn($getResponse);
243
+
244
+        $token = $this->service->syncRemoteAddressBook(
245
+            '',
246
+            'system',
247
+            'system',
248
+            '1234567890',
249
+            null,
250
+            '1',
251
+            'principals/system/system',
252
+            []
253
+        );
254
+
255
+        $this->assertEquals('http://sabre.io/ns/sync/3', $token);
256
+    }
257
+
258
+    public function testSyncWithDeletedElement(): void {
259
+        $this->backend->expects($this->exactly(0))
260
+            ->method('createCard');
261
+        $this->backend->expects($this->exactly(0))
262
+            ->method('updateCard');
263
+        $this->backend->expects($this->exactly(1))
264
+            ->method('deleteCard');
265
+
266
+        $body = '<?xml version="1.0"?>
267 267
 <d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:oc="http://owncloud.org/ns">
268 268
 <d:response>
269 269
     <d:href>/remote.php/dav/addressbooks/system/system/system/Database:alice.vcf</d:href>
@@ -272,209 +272,209 @@  discard block
 block discarded – undo
272 272
 <d:sync-token>http://sabre.io/ns/sync/4</d:sync-token>
273 273
 </d:multistatus>';
274 274
 
275
-		$reportResponse = new Response(new PsrResponse(
276
-			207,
277
-			['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
278
-			$body
279
-		));
280
-
281
-		$this->client
282
-			->method('request')
283
-			->willReturn($reportResponse);
284
-
285
-		$token = $this->service->syncRemoteAddressBook(
286
-			'',
287
-			'system',
288
-			'system',
289
-			'1234567890',
290
-			null,
291
-			'1',
292
-			'principals/system/system',
293
-			[]
294
-		);
295
-
296
-		$this->assertEquals('http://sabre.io/ns/sync/4', $token);
297
-	}
298
-
299
-	public function testEnsureSystemAddressBookExists(): void {
300
-		/** @var CardDavBackend&MockObject $backend */
301
-		$backend = $this->createMock(CardDavBackend::class);
302
-		$backend->expects($this->exactly(1))->method('createAddressBook');
303
-		$backend->expects($this->exactly(2))
304
-			->method('getAddressBooksByUri')
305
-			->willReturnOnConsecutiveCalls(
306
-				null,
307
-				[],
308
-			);
309
-
310
-		$userManager = $this->createMock(IUserManager::class);
311
-		$dbConnection = $this->createMock(IDBConnection::class);
312
-		$logger = $this->createMock(LoggerInterface::class);
313
-		$converter = $this->createMock(Converter::class);
314
-		$clientService = $this->createMock(IClientService::class);
315
-		$config = $this->createMock(IConfig::class);
316
-
317
-		$ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService, $config);
318
-		$ss->ensureSystemAddressBookExists('principals/users/adam', 'contacts', []);
319
-	}
320
-
321
-	public static function dataActivatedUsers(): array {
322
-		return [
323
-			[true, 1, 1, 1],
324
-			[false, 0, 0, 3],
325
-		];
326
-	}
327
-
328
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataActivatedUsers')]
329
-	public function testUpdateAndDeleteUser(bool $activated, int $createCalls, int $updateCalls, int $deleteCalls): void {
330
-		/** @var CardDavBackend | MockObject $backend */
331
-		$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
332
-		$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
333
-
334
-		$backend->expects($this->exactly($createCalls))->method('createCard');
335
-		$backend->expects($this->exactly($updateCalls))->method('updateCard');
336
-		$backend->expects($this->exactly($deleteCalls))->method('deleteCard');
337
-
338
-		$backend->method('getCard')->willReturnOnConsecutiveCalls(false, [
339
-			'carddata' => "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 3.4.8//EN\r\nUID:test-user\r\nFN:test-user\r\nN:test-user;;;;\r\nEND:VCARD\r\n\r\n"
340
-		]);
341
-
342
-		$backend->method('getAddressBooksByUri')
343
-			->with('principals/system/system', 'system')
344
-			->willReturn(['id' => -1]);
345
-
346
-		$userManager = $this->createMock(IUserManager::class);
347
-		$dbConnection = $this->createMock(IDBConnection::class);
348
-		$user = $this->createMock(IUser::class);
349
-		$user->method('getBackendClassName')->willReturn('unittest');
350
-		$user->method('getUID')->willReturn('test-user');
351
-		$user->method('getCloudId')->willReturn('cloudId');
352
-		$user->method('getDisplayName')->willReturn('test-user');
353
-		$user->method('isEnabled')->willReturn($activated);
354
-		$converter = $this->createMock(Converter::class);
355
-		$converter->expects($this->any())
356
-			->method('createCardFromUser')
357
-			->willReturn($this->createMock(VCard::class));
358
-
359
-		$clientService = $this->createMock(IClientService::class);
360
-		$config = $this->createMock(IConfig::class);
361
-
362
-		$ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService, $config);
363
-		$ss->updateUser($user);
364
-
365
-		$ss->updateUser($user);
366
-
367
-		$ss->deleteUser($user);
368
-	}
369
-
370
-	public function testDeleteAddressbookWhenAccessRevoked(): void {
371
-		$this->expectException(ClientExceptionInterface::class);
372
-
373
-		$this->backend->expects($this->exactly(0))
374
-			->method('createCard');
375
-		$this->backend->expects($this->exactly(0))
376
-			->method('updateCard');
377
-		$this->backend->expects($this->exactly(0))
378
-			->method('deleteCard');
379
-		$this->backend->expects($this->exactly(1))
380
-			->method('deleteAddressBook');
381
-
382
-		$request = new PsrRequest(
383
-			'REPORT',
384
-			'https://server2.internal/remote.php/dav/addressbooks/system/system/system',
385
-			['Content-Type' => 'application/xml'],
386
-		);
387
-
388
-		$body = '<?xml version="1.0" encoding="utf-8"?>
275
+        $reportResponse = new Response(new PsrResponse(
276
+            207,
277
+            ['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
278
+            $body
279
+        ));
280
+
281
+        $this->client
282
+            ->method('request')
283
+            ->willReturn($reportResponse);
284
+
285
+        $token = $this->service->syncRemoteAddressBook(
286
+            '',
287
+            'system',
288
+            'system',
289
+            '1234567890',
290
+            null,
291
+            '1',
292
+            'principals/system/system',
293
+            []
294
+        );
295
+
296
+        $this->assertEquals('http://sabre.io/ns/sync/4', $token);
297
+    }
298
+
299
+    public function testEnsureSystemAddressBookExists(): void {
300
+        /** @var CardDavBackend&MockObject $backend */
301
+        $backend = $this->createMock(CardDavBackend::class);
302
+        $backend->expects($this->exactly(1))->method('createAddressBook');
303
+        $backend->expects($this->exactly(2))
304
+            ->method('getAddressBooksByUri')
305
+            ->willReturnOnConsecutiveCalls(
306
+                null,
307
+                [],
308
+            );
309
+
310
+        $userManager = $this->createMock(IUserManager::class);
311
+        $dbConnection = $this->createMock(IDBConnection::class);
312
+        $logger = $this->createMock(LoggerInterface::class);
313
+        $converter = $this->createMock(Converter::class);
314
+        $clientService = $this->createMock(IClientService::class);
315
+        $config = $this->createMock(IConfig::class);
316
+
317
+        $ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService, $config);
318
+        $ss->ensureSystemAddressBookExists('principals/users/adam', 'contacts', []);
319
+    }
320
+
321
+    public static function dataActivatedUsers(): array {
322
+        return [
323
+            [true, 1, 1, 1],
324
+            [false, 0, 0, 3],
325
+        ];
326
+    }
327
+
328
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataActivatedUsers')]
329
+    public function testUpdateAndDeleteUser(bool $activated, int $createCalls, int $updateCalls, int $deleteCalls): void {
330
+        /** @var CardDavBackend | MockObject $backend */
331
+        $backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
332
+        $logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
333
+
334
+        $backend->expects($this->exactly($createCalls))->method('createCard');
335
+        $backend->expects($this->exactly($updateCalls))->method('updateCard');
336
+        $backend->expects($this->exactly($deleteCalls))->method('deleteCard');
337
+
338
+        $backend->method('getCard')->willReturnOnConsecutiveCalls(false, [
339
+            'carddata' => "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 3.4.8//EN\r\nUID:test-user\r\nFN:test-user\r\nN:test-user;;;;\r\nEND:VCARD\r\n\r\n"
340
+        ]);
341
+
342
+        $backend->method('getAddressBooksByUri')
343
+            ->with('principals/system/system', 'system')
344
+            ->willReturn(['id' => -1]);
345
+
346
+        $userManager = $this->createMock(IUserManager::class);
347
+        $dbConnection = $this->createMock(IDBConnection::class);
348
+        $user = $this->createMock(IUser::class);
349
+        $user->method('getBackendClassName')->willReturn('unittest');
350
+        $user->method('getUID')->willReturn('test-user');
351
+        $user->method('getCloudId')->willReturn('cloudId');
352
+        $user->method('getDisplayName')->willReturn('test-user');
353
+        $user->method('isEnabled')->willReturn($activated);
354
+        $converter = $this->createMock(Converter::class);
355
+        $converter->expects($this->any())
356
+            ->method('createCardFromUser')
357
+            ->willReturn($this->createMock(VCard::class));
358
+
359
+        $clientService = $this->createMock(IClientService::class);
360
+        $config = $this->createMock(IConfig::class);
361
+
362
+        $ss = new SyncService($backend, $userManager, $dbConnection, $logger, $converter, $clientService, $config);
363
+        $ss->updateUser($user);
364
+
365
+        $ss->updateUser($user);
366
+
367
+        $ss->deleteUser($user);
368
+    }
369
+
370
+    public function testDeleteAddressbookWhenAccessRevoked(): void {
371
+        $this->expectException(ClientExceptionInterface::class);
372
+
373
+        $this->backend->expects($this->exactly(0))
374
+            ->method('createCard');
375
+        $this->backend->expects($this->exactly(0))
376
+            ->method('updateCard');
377
+        $this->backend->expects($this->exactly(0))
378
+            ->method('deleteCard');
379
+        $this->backend->expects($this->exactly(1))
380
+            ->method('deleteAddressBook');
381
+
382
+        $request = new PsrRequest(
383
+            'REPORT',
384
+            'https://server2.internal/remote.php/dav/addressbooks/system/system/system',
385
+            ['Content-Type' => 'application/xml'],
386
+        );
387
+
388
+        $body = '<?xml version="1.0" encoding="utf-8"?>
389 389
 <d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
390 390
   <s:exception>Sabre\DAV\Exception\NotAuthenticated</s:exception>
391 391
   <s:message>No public access to this resource., Username or password was incorrect, No \'Authorization: Bearer\' header found. Either the client didn\'t send one, or the server is mis-configured, Username or password was incorrect</s:message>
392 392
 </d:error>';
393 393
 
394
-		$response = new PsrResponse(
395
-			401,
396
-			['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
397
-			$body
398
-		);
394
+        $response = new PsrResponse(
395
+            401,
396
+            ['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
397
+            $body
398
+        );
399 399
 
400
-		$message = 'Client error: `REPORT https://server2.internal/cloud/remote.php/dav/addressbooks/system/system/system` resulted in a `401 Unauthorized` response:
400
+        $message = 'Client error: `REPORT https://server2.internal/cloud/remote.php/dav/addressbooks/system/system/system` resulted in a `401 Unauthorized` response:
401 401
 <?xml version="1.0" encoding="utf-8"?>
402 402
 <d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
403 403
   <s:exception>Sabre\DA (truncated...)
404 404
 ';
405 405
 
406
-		$reportException = new ClientException(
407
-			$message,
408
-			$request,
409
-			$response
410
-		);
411
-
412
-		$this->client
413
-			->method('request')
414
-			->willThrowException($reportException);
415
-
416
-		$this->service->syncRemoteAddressBook(
417
-			'',
418
-			'system',
419
-			'system',
420
-			'1234567890',
421
-			null,
422
-			'1',
423
-			'principals/system/system',
424
-			[]
425
-		);
426
-	}
427
-
428
-	#[\PHPUnit\Framework\Attributes\DataProvider('providerUseAbsoluteUriReport')]
429
-	public function testUseAbsoluteUriReport(string $host, string $expected): void {
430
-		$body = '<?xml version="1.0"?>
406
+        $reportException = new ClientException(
407
+            $message,
408
+            $request,
409
+            $response
410
+        );
411
+
412
+        $this->client
413
+            ->method('request')
414
+            ->willThrowException($reportException);
415
+
416
+        $this->service->syncRemoteAddressBook(
417
+            '',
418
+            'system',
419
+            'system',
420
+            '1234567890',
421
+            null,
422
+            '1',
423
+            'principals/system/system',
424
+            []
425
+        );
426
+    }
427
+
428
+    #[\PHPUnit\Framework\Attributes\DataProvider('providerUseAbsoluteUriReport')]
429
+    public function testUseAbsoluteUriReport(string $host, string $expected): void {
430
+        $body = '<?xml version="1.0"?>
431 431
 <d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:oc="http://owncloud.org/ns">
432 432
     <d:sync-token>http://sabre.io/ns/sync/1</d:sync-token>
433 433
 </d:multistatus>';
434 434
 
435
-		$requestResponse = new Response(new PsrResponse(
436
-			207,
437
-			['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
438
-			$body
439
-		));
440
-
441
-		$this->client
442
-			->method('request')
443
-			->with(
444
-				'REPORT',
445
-				$this->callback(function ($uri) use ($expected) {
446
-					$this->assertEquals($expected, $uri);
447
-					return true;
448
-				}),
449
-				$this->callback(function ($options) {
450
-					$this->assertIsArray($options);
451
-					return true;
452
-				}),
453
-			)
454
-			->willReturn($requestResponse);
455
-
456
-		$this->service->syncRemoteAddressBook(
457
-			$host,
458
-			'system',
459
-			'remote.php/dav/addressbooks/system/system/system',
460
-			'1234567890',
461
-			null,
462
-			'1',
463
-			'principals/system/system',
464
-			[]
465
-		);
466
-	}
467
-
468
-	public static function providerUseAbsoluteUriReport(): array {
469
-		return [
470
-			['https://server.internal', 'https://server.internal/remote.php/dav/addressbooks/system/system/system'],
471
-			['https://server.internal/', 'https://server.internal/remote.php/dav/addressbooks/system/system/system'],
472
-			['https://server.internal/nextcloud', 'https://server.internal/nextcloud/remote.php/dav/addressbooks/system/system/system'],
473
-			['https://server.internal/nextcloud/', 'https://server.internal/nextcloud/remote.php/dav/addressbooks/system/system/system'],
474
-			['https://server.internal:8080', 'https://server.internal:8080/remote.php/dav/addressbooks/system/system/system'],
475
-			['https://server.internal:8080/', 'https://server.internal:8080/remote.php/dav/addressbooks/system/system/system'],
476
-			['https://server.internal:8080/nextcloud', 'https://server.internal:8080/nextcloud/remote.php/dav/addressbooks/system/system/system'],
477
-			['https://server.internal:8080/nextcloud/', 'https://server.internal:8080/nextcloud/remote.php/dav/addressbooks/system/system/system'],
478
-		];
479
-	}
435
+        $requestResponse = new Response(new PsrResponse(
436
+            207,
437
+            ['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
438
+            $body
439
+        ));
440
+
441
+        $this->client
442
+            ->method('request')
443
+            ->with(
444
+                'REPORT',
445
+                $this->callback(function ($uri) use ($expected) {
446
+                    $this->assertEquals($expected, $uri);
447
+                    return true;
448
+                }),
449
+                $this->callback(function ($options) {
450
+                    $this->assertIsArray($options);
451
+                    return true;
452
+                }),
453
+            )
454
+            ->willReturn($requestResponse);
455
+
456
+        $this->service->syncRemoteAddressBook(
457
+            $host,
458
+            'system',
459
+            'remote.php/dav/addressbooks/system/system/system',
460
+            '1234567890',
461
+            null,
462
+            '1',
463
+            'principals/system/system',
464
+            []
465
+        );
466
+    }
467
+
468
+    public static function providerUseAbsoluteUriReport(): array {
469
+        return [
470
+            ['https://server.internal', 'https://server.internal/remote.php/dav/addressbooks/system/system/system'],
471
+            ['https://server.internal/', 'https://server.internal/remote.php/dav/addressbooks/system/system/system'],
472
+            ['https://server.internal/nextcloud', 'https://server.internal/nextcloud/remote.php/dav/addressbooks/system/system/system'],
473
+            ['https://server.internal/nextcloud/', 'https://server.internal/nextcloud/remote.php/dav/addressbooks/system/system/system'],
474
+            ['https://server.internal:8080', 'https://server.internal:8080/remote.php/dav/addressbooks/system/system/system'],
475
+            ['https://server.internal:8080/', 'https://server.internal:8080/remote.php/dav/addressbooks/system/system/system'],
476
+            ['https://server.internal:8080/nextcloud', 'https://server.internal:8080/nextcloud/remote.php/dav/addressbooks/system/system/system'],
477
+            ['https://server.internal:8080/nextcloud/', 'https://server.internal:8080/nextcloud/remote.php/dav/addressbooks/system/system/system'],
478
+        ];
479
+    }
480 480
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -24,151 +24,151 @@
 block discarded – undo
24 24
 use Test\TestCase;
25 25
 
26 26
 class ImageExportPluginTest extends TestCase {
27
-	private ResponseInterface&MockObject $response;
28
-	private RequestInterface&MockObject $request;
29
-	private Server&MockObject $server;
30
-	private Tree&MockObject $tree;
31
-	private PhotoCache&MockObject $cache;
32
-	private ImageExportPlugin $plugin;
33
-
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-
37
-		$this->request = $this->createMock(RequestInterface::class);
38
-		$this->response = $this->createMock(ResponseInterface::class);
39
-		$this->server = $this->createMock(Server::class);
40
-		$this->tree = $this->createMock(Tree::class);
41
-		$this->server->tree = $this->tree;
42
-		$this->cache = $this->createMock(PhotoCache::class);
43
-
44
-		$this->plugin = new ImageExportPlugin($this->cache);
45
-		$this->plugin->initialize($this->server);
46
-	}
47
-
48
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesQueryParams')]
49
-	public function testQueryParams(array $param): void {
50
-		$this->request->expects($this->once())->method('getQueryParameters')->willReturn($param);
51
-		$result = $this->plugin->httpGet($this->request, $this->response);
52
-		$this->assertTrue($result);
53
-	}
54
-
55
-	public static function providesQueryParams(): array {
56
-		return [
57
-			[[]],
58
-			[['1']],
59
-			[['foo' => 'bar']],
60
-		];
61
-	}
62
-
63
-	public function testNoCard(): void {
64
-		$this->request->method('getQueryParameters')
65
-			->willReturn([
66
-				'photo'
67
-			]);
68
-		$this->request->method('getPath')
69
-			->willReturn('user/book/card');
70
-
71
-		$node = $this->createMock(Node::class);
72
-		$this->tree->method('getNodeForPath')
73
-			->with('user/book/card')
74
-			->willReturn($node);
75
-
76
-		$result = $this->plugin->httpGet($this->request, $this->response);
77
-		$this->assertTrue($result);
78
-	}
79
-
80
-	public static function dataTestCard(): array {
81
-		return [
82
-			[null, false],
83
-			[null, true],
84
-			[32, false],
85
-			[32, true],
86
-		];
87
-	}
88
-
89
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataTestCard')]
90
-	public function testCard(?int $size, bool $photo): void {
91
-		$query = ['photo' => null];
92
-		if ($size !== null) {
93
-			$query['size'] = $size;
94
-		}
95
-
96
-		$this->request->method('getQueryParameters')
97
-			->willReturn($query);
98
-		$this->request->method('getPath')
99
-			->willReturn('user/book/card');
100
-
101
-		$card = $this->createMock(Card::class);
102
-		$card->method('getETag')
103
-			->willReturn('"myEtag"');
104
-		$card->method('getName')
105
-			->willReturn('card');
106
-		$book = $this->createMock(AddressBook::class);
107
-		$book->method('getResourceId')
108
-			->willReturn(1);
109
-
110
-		$this->tree->method('getNodeForPath')
111
-			->willReturnCallback(function ($path) use ($card, $book) {
112
-				if ($path === 'user/book/card') {
113
-					return $card;
114
-				} elseif ($path === 'user/book') {
115
-					return $book;
116
-				}
117
-				$this->fail();
118
-			});
119
-
120
-		$size = $size === null ? -1 : $size;
121
-
122
-		if ($photo) {
123
-			$file = $this->createMock(ISimpleFile::class);
124
-			$file->method('getMimeType')
125
-				->willReturn('image/jpeg');
126
-			$file->method('getContent')
127
-				->willReturn('imgdata');
128
-
129
-			$this->cache->method('get')
130
-				->with(1, 'card', $size, $card)
131
-				->willReturn($file);
132
-
133
-			$setHeaderCalls = [
134
-				['Cache-Control', 'private, max-age=3600, must-revalidate'],
135
-				['Etag', '"myEtag"'],
136
-				['Content-Type', 'image/jpeg'],
137
-				['Content-Disposition', 'attachment; filename=card.jpg'],
138
-			];
139
-			$this->response->expects($this->exactly(count($setHeaderCalls)))
140
-				->method('setHeader')
141
-				->willReturnCallback(function () use (&$setHeaderCalls): void {
142
-					$expected = array_shift($setHeaderCalls);
143
-					$this->assertEquals($expected, func_get_args());
144
-				});
145
-
146
-			$this->response->expects($this->once())
147
-				->method('setStatus')
148
-				->with(200);
149
-			$this->response->expects($this->once())
150
-				->method('setBody')
151
-				->with('imgdata');
152
-		} else {
153
-			$setHeaderCalls = [
154
-				['Cache-Control', 'private, max-age=3600, must-revalidate'],
155
-				['Etag', '"myEtag"'],
156
-			];
157
-			$this->response->expects($this->exactly(count($setHeaderCalls)))
158
-				->method('setHeader')
159
-				->willReturnCallback(function () use (&$setHeaderCalls): void {
160
-					$expected = array_shift($setHeaderCalls);
161
-					$this->assertEquals($expected, func_get_args());
162
-				});
163
-			$this->cache->method('get')
164
-				->with(1, 'card', $size, $card)
165
-				->willThrowException(new NotFoundException());
166
-			$this->response->expects($this->once())
167
-				->method('setStatus')
168
-				->with(Http::STATUS_NO_CONTENT);
169
-		}
170
-
171
-		$result = $this->plugin->httpGet($this->request, $this->response);
172
-		$this->assertFalse($result);
173
-	}
27
+    private ResponseInterface&MockObject $response;
28
+    private RequestInterface&MockObject $request;
29
+    private Server&MockObject $server;
30
+    private Tree&MockObject $tree;
31
+    private PhotoCache&MockObject $cache;
32
+    private ImageExportPlugin $plugin;
33
+
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+
37
+        $this->request = $this->createMock(RequestInterface::class);
38
+        $this->response = $this->createMock(ResponseInterface::class);
39
+        $this->server = $this->createMock(Server::class);
40
+        $this->tree = $this->createMock(Tree::class);
41
+        $this->server->tree = $this->tree;
42
+        $this->cache = $this->createMock(PhotoCache::class);
43
+
44
+        $this->plugin = new ImageExportPlugin($this->cache);
45
+        $this->plugin->initialize($this->server);
46
+    }
47
+
48
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesQueryParams')]
49
+    public function testQueryParams(array $param): void {
50
+        $this->request->expects($this->once())->method('getQueryParameters')->willReturn($param);
51
+        $result = $this->plugin->httpGet($this->request, $this->response);
52
+        $this->assertTrue($result);
53
+    }
54
+
55
+    public static function providesQueryParams(): array {
56
+        return [
57
+            [[]],
58
+            [['1']],
59
+            [['foo' => 'bar']],
60
+        ];
61
+    }
62
+
63
+    public function testNoCard(): void {
64
+        $this->request->method('getQueryParameters')
65
+            ->willReturn([
66
+                'photo'
67
+            ]);
68
+        $this->request->method('getPath')
69
+            ->willReturn('user/book/card');
70
+
71
+        $node = $this->createMock(Node::class);
72
+        $this->tree->method('getNodeForPath')
73
+            ->with('user/book/card')
74
+            ->willReturn($node);
75
+
76
+        $result = $this->plugin->httpGet($this->request, $this->response);
77
+        $this->assertTrue($result);
78
+    }
79
+
80
+    public static function dataTestCard(): array {
81
+        return [
82
+            [null, false],
83
+            [null, true],
84
+            [32, false],
85
+            [32, true],
86
+        ];
87
+    }
88
+
89
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCard')]
90
+    public function testCard(?int $size, bool $photo): void {
91
+        $query = ['photo' => null];
92
+        if ($size !== null) {
93
+            $query['size'] = $size;
94
+        }
95
+
96
+        $this->request->method('getQueryParameters')
97
+            ->willReturn($query);
98
+        $this->request->method('getPath')
99
+            ->willReturn('user/book/card');
100
+
101
+        $card = $this->createMock(Card::class);
102
+        $card->method('getETag')
103
+            ->willReturn('"myEtag"');
104
+        $card->method('getName')
105
+            ->willReturn('card');
106
+        $book = $this->createMock(AddressBook::class);
107
+        $book->method('getResourceId')
108
+            ->willReturn(1);
109
+
110
+        $this->tree->method('getNodeForPath')
111
+            ->willReturnCallback(function ($path) use ($card, $book) {
112
+                if ($path === 'user/book/card') {
113
+                    return $card;
114
+                } elseif ($path === 'user/book') {
115
+                    return $book;
116
+                }
117
+                $this->fail();
118
+            });
119
+
120
+        $size = $size === null ? -1 : $size;
121
+
122
+        if ($photo) {
123
+            $file = $this->createMock(ISimpleFile::class);
124
+            $file->method('getMimeType')
125
+                ->willReturn('image/jpeg');
126
+            $file->method('getContent')
127
+                ->willReturn('imgdata');
128
+
129
+            $this->cache->method('get')
130
+                ->with(1, 'card', $size, $card)
131
+                ->willReturn($file);
132
+
133
+            $setHeaderCalls = [
134
+                ['Cache-Control', 'private, max-age=3600, must-revalidate'],
135
+                ['Etag', '"myEtag"'],
136
+                ['Content-Type', 'image/jpeg'],
137
+                ['Content-Disposition', 'attachment; filename=card.jpg'],
138
+            ];
139
+            $this->response->expects($this->exactly(count($setHeaderCalls)))
140
+                ->method('setHeader')
141
+                ->willReturnCallback(function () use (&$setHeaderCalls): void {
142
+                    $expected = array_shift($setHeaderCalls);
143
+                    $this->assertEquals($expected, func_get_args());
144
+                });
145
+
146
+            $this->response->expects($this->once())
147
+                ->method('setStatus')
148
+                ->with(200);
149
+            $this->response->expects($this->once())
150
+                ->method('setBody')
151
+                ->with('imgdata');
152
+        } else {
153
+            $setHeaderCalls = [
154
+                ['Cache-Control', 'private, max-age=3600, must-revalidate'],
155
+                ['Etag', '"myEtag"'],
156
+            ];
157
+            $this->response->expects($this->exactly(count($setHeaderCalls)))
158
+                ->method('setHeader')
159
+                ->willReturnCallback(function () use (&$setHeaderCalls): void {
160
+                    $expected = array_shift($setHeaderCalls);
161
+                    $this->assertEquals($expected, func_get_args());
162
+                });
163
+            $this->cache->method('get')
164
+                ->with(1, 'card', $size, $card)
165
+                ->willThrowException(new NotFoundException());
166
+            $this->response->expects($this->once())
167
+                ->method('setStatus')
168
+                ->with(Http::STATUS_NO_CONTENT);
169
+        }
170
+
171
+        $result = $this->plugin->httpGet($this->request, $this->response);
172
+        $this->assertFalse($result);
173
+    }
174 174
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 			->willReturn(1);
109 109
 
110 110
 		$this->tree->method('getNodeForPath')
111
-			->willReturnCallback(function ($path) use ($card, $book) {
111
+			->willReturnCallback(function($path) use ($card, $book) {
112 112
 				if ($path === 'user/book/card') {
113 113
 					return $card;
114 114
 				} elseif ($path === 'user/book') {
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 			];
139 139
 			$this->response->expects($this->exactly(count($setHeaderCalls)))
140 140
 				->method('setHeader')
141
-				->willReturnCallback(function () use (&$setHeaderCalls): void {
141
+				->willReturnCallback(function() use (&$setHeaderCalls): void {
142 142
 					$expected = array_shift($setHeaderCalls);
143 143
 					$this->assertEquals($expected, func_get_args());
144 144
 				});
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 			];
157 157
 			$this->response->expects($this->exactly(count($setHeaderCalls)))
158 158
 				->method('setHeader')
159
-				->willReturnCallback(function () use (&$setHeaderCalls): void {
159
+				->willReturnCallback(function() use (&$setHeaderCalls): void {
160 160
 					$expected = array_shift($setHeaderCalls);
161 161
 					$this->assertEquals($expected, func_get_args());
162 162
 				});
Please login to merge, or discard this patch.
apps/dav/tests/unit/CardDAV/ConverterTest.php 2 patches
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -22,200 +22,200 @@
 block discarded – undo
22 22
 use Test\TestCase;
23 23
 
24 24
 class ConverterTest extends TestCase {
25
-	private IAccountManager&MockObject $accountManager;
26
-	private IUserManager&MockObject $userManager;
27
-	private IURLGenerator&MockObject $urlGenerator;
28
-	private LoggerInterface&MockObject $logger;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->accountManager = $this->createMock(IAccountManager::class);
34
-		$this->userManager = $this->createMock(IUserManager::class);
35
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
36
-		$this->logger = $this->createMock(LoggerInterface::class);
37
-	}
38
-
39
-	/**
40
-	 * @return IAccountProperty&MockObject
41
-	 */
42
-	protected function getAccountPropertyMock(string $name, ?string $value, string $scope) {
43
-		$property = $this->createMock(IAccountProperty::class);
44
-		$property->expects($this->any())
45
-			->method('getName')
46
-			->willReturn($name);
47
-		$property->expects($this->any())
48
-			->method('getValue')
49
-			->willReturn((string)$value);
50
-		$property->expects($this->any())
51
-			->method('getScope')
52
-			->willReturn($scope);
53
-		$property->expects($this->any())
54
-			->method('getVerified')
55
-			->willReturn(IAccountManager::NOT_VERIFIED);
56
-		return $property;
57
-	}
58
-
59
-	public function getAccountManager(IUser $user) {
60
-		$account = $this->createMock(IAccount::class);
61
-		$account->expects($this->any())
62
-			->method('getAllProperties')
63
-			->willReturnCallback(function () use ($user) {
64
-				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_DISPLAYNAME, $user->getDisplayName(), IAccountManager::SCOPE_FEDERATED);
65
-				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_ADDRESS, '', IAccountManager::SCOPE_LOCAL);
66
-				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_WEBSITE, '', IAccountManager::SCOPE_LOCAL);
67
-				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_EMAIL, $user->getEMailAddress(), IAccountManager::SCOPE_FEDERATED);
68
-				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_AVATAR, $user->getAvatarImage(-1)->data(), IAccountManager::SCOPE_FEDERATED);
69
-				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_PHONE, '', IAccountManager::SCOPE_LOCAL);
70
-				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_TWITTER, '', IAccountManager::SCOPE_LOCAL);
71
-			});
72
-
73
-		$accountManager = $this->createMock(IAccountManager::class);
74
-
75
-		$accountManager->expects($this->any())
76
-			->method('getAccount')
77
-			->willReturn($account);
78
-
79
-		return $accountManager;
80
-	}
81
-
82
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesNewUsers')]
83
-	public function testCreation($expectedVCard, $displayName = null, $eMailAddress = null, $cloudId = null): void {
84
-		$user = $this->getUserMock((string)$displayName, $eMailAddress, $cloudId);
85
-		$accountManager = $this->getAccountManager($user);
86
-
87
-		$converter = new Converter($accountManager, $this->userManager, $this->urlGenerator, $this->logger);
88
-		$vCard = $converter->createCardFromUser($user);
89
-		if ($expectedVCard !== null) {
90
-			$this->assertInstanceOf('Sabre\VObject\Component\VCard', $vCard);
91
-			$cardData = $vCard->jsonSerialize();
92
-			$this->compareData($expectedVCard, $cardData);
93
-		} else {
94
-			$this->assertSame($expectedVCard, $vCard);
95
-		}
96
-	}
97
-
98
-	public function testManagerProp(): void {
99
-		$user = $this->getUserMock('user', '[email protected]', '[email protected]');
100
-		$user->method('getManagerUids')
101
-			->willReturn(['mgr']);
102
-		$this->userManager->expects(self::once())
103
-			->method('getDisplayName')
104
-			->with('mgr')
105
-			->willReturn('Manager');
106
-		$accountManager = $this->getAccountManager($user);
107
-
108
-		$converter = new Converter($accountManager, $this->userManager, $this->urlGenerator, $this->logger);
109
-		$vCard = $converter->createCardFromUser($user);
110
-
111
-		$this->compareData(
112
-			[
113
-				'cloud' => '[email protected]',
114
-				'email' => '[email protected]',
115
-				'x-managersname' => 'Manager',
116
-			],
117
-			$vCard->jsonSerialize()
118
-		);
119
-	}
120
-
121
-	protected function compareData(array $expected, array $data): void {
122
-		foreach ($expected as $key => $value) {
123
-			$found = false;
124
-			foreach ($data[1] as $d) {
125
-				if ($d[0] === $key && $d[3] === $value) {
126
-					$found = true;
127
-					break;
128
-				}
129
-			}
130
-			if (!$found) {
131
-				$this->assertTrue(false, 'Expected data: ' . $key . ' not found.');
132
-			}
133
-		}
134
-	}
135
-
136
-	public static function providesNewUsers(): array {
137
-		return [
138
-			[
139
-				null
140
-			],
141
-			[
142
-				null,
143
-				null,
144
-				'[email protected]'
145
-			],
146
-			[
147
-				[
148
-					'cloud' => '[email protected]',
149
-					'email' => '[email protected]',
150
-					'photo' => 'MTIzNDU2Nzg5',
151
-				],
152
-				null,
153
-				'[email protected]',
154
-				'[email protected]'
155
-			],
156
-			[
157
-				[
158
-					'cloud' => '[email protected]',
159
-					'email' => '[email protected]',
160
-					'fn' => 'Dr. Foo Bar',
161
-					'photo' => 'MTIzNDU2Nzg5',
162
-				],
163
-				'Dr. Foo Bar',
164
-				'[email protected]',
165
-				'[email protected]'
166
-			],
167
-			[
168
-				[
169
-					'cloud' => '[email protected]',
170
-					'fn' => 'Dr. Foo Bar',
171
-					'photo' => 'MTIzNDU2Nzg5',
172
-				],
173
-				'Dr. Foo Bar',
174
-				null,
175
-				'[email protected]'
176
-			],
177
-			[
178
-				[
179
-					'cloud' => '[email protected]',
180
-					'fn' => 'Dr. Foo Bar',
181
-					'photo' => 'MTIzNDU2Nzg5',
182
-				],
183
-				'Dr. Foo Bar',
184
-				'',
185
-				'[email protected]'
186
-			],
187
-		];
188
-	}
189
-
190
-	#[\PHPUnit\Framework\Attributes\DataProvider('providesNames')]
191
-	public function testNameSplitter(string $expected, string $fullName): void {
192
-		$converter = new Converter($this->accountManager, $this->userManager, $this->urlGenerator, $this->logger);
193
-		$r = $converter->splitFullName($fullName);
194
-		$r = implode(';', $r);
195
-		$this->assertEquals($expected, $r);
196
-	}
197
-
198
-	public static function providesNames(): array {
199
-		return [
200
-			['Sauron;;;;', 'Sauron'],
201
-			['Baggins;Bilbo;;;', 'Bilbo Baggins'],
202
-			['Tolkien;John;Ronald Reuel;;', 'John Ronald Reuel Tolkien'],
203
-		];
204
-	}
205
-
206
-	/**
207
-	 * @return IUser&MockObject
208
-	 */
209
-	protected function getUserMock(string $displayName, ?string $eMailAddress, ?string $cloudId) {
210
-		$image0 = $this->createMock(IImage::class);
211
-		$image0->method('mimeType')->willReturn('image/jpeg');
212
-		$image0->method('data')->willReturn('123456789');
213
-		$user = $this->createMock(IUser::class);
214
-		$user->method('getUID')->willReturn('12345');
215
-		$user->method('getDisplayName')->willReturn($displayName);
216
-		$user->method('getEMailAddress')->willReturn($eMailAddress);
217
-		$user->method('getCloudId')->willReturn($cloudId);
218
-		$user->method('getAvatarImage')->willReturn($image0);
219
-		return $user;
220
-	}
25
+    private IAccountManager&MockObject $accountManager;
26
+    private IUserManager&MockObject $userManager;
27
+    private IURLGenerator&MockObject $urlGenerator;
28
+    private LoggerInterface&MockObject $logger;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->accountManager = $this->createMock(IAccountManager::class);
34
+        $this->userManager = $this->createMock(IUserManager::class);
35
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
36
+        $this->logger = $this->createMock(LoggerInterface::class);
37
+    }
38
+
39
+    /**
40
+     * @return IAccountProperty&MockObject
41
+     */
42
+    protected function getAccountPropertyMock(string $name, ?string $value, string $scope) {
43
+        $property = $this->createMock(IAccountProperty::class);
44
+        $property->expects($this->any())
45
+            ->method('getName')
46
+            ->willReturn($name);
47
+        $property->expects($this->any())
48
+            ->method('getValue')
49
+            ->willReturn((string)$value);
50
+        $property->expects($this->any())
51
+            ->method('getScope')
52
+            ->willReturn($scope);
53
+        $property->expects($this->any())
54
+            ->method('getVerified')
55
+            ->willReturn(IAccountManager::NOT_VERIFIED);
56
+        return $property;
57
+    }
58
+
59
+    public function getAccountManager(IUser $user) {
60
+        $account = $this->createMock(IAccount::class);
61
+        $account->expects($this->any())
62
+            ->method('getAllProperties')
63
+            ->willReturnCallback(function () use ($user) {
64
+                yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_DISPLAYNAME, $user->getDisplayName(), IAccountManager::SCOPE_FEDERATED);
65
+                yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_ADDRESS, '', IAccountManager::SCOPE_LOCAL);
66
+                yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_WEBSITE, '', IAccountManager::SCOPE_LOCAL);
67
+                yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_EMAIL, $user->getEMailAddress(), IAccountManager::SCOPE_FEDERATED);
68
+                yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_AVATAR, $user->getAvatarImage(-1)->data(), IAccountManager::SCOPE_FEDERATED);
69
+                yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_PHONE, '', IAccountManager::SCOPE_LOCAL);
70
+                yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_TWITTER, '', IAccountManager::SCOPE_LOCAL);
71
+            });
72
+
73
+        $accountManager = $this->createMock(IAccountManager::class);
74
+
75
+        $accountManager->expects($this->any())
76
+            ->method('getAccount')
77
+            ->willReturn($account);
78
+
79
+        return $accountManager;
80
+    }
81
+
82
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesNewUsers')]
83
+    public function testCreation($expectedVCard, $displayName = null, $eMailAddress = null, $cloudId = null): void {
84
+        $user = $this->getUserMock((string)$displayName, $eMailAddress, $cloudId);
85
+        $accountManager = $this->getAccountManager($user);
86
+
87
+        $converter = new Converter($accountManager, $this->userManager, $this->urlGenerator, $this->logger);
88
+        $vCard = $converter->createCardFromUser($user);
89
+        if ($expectedVCard !== null) {
90
+            $this->assertInstanceOf('Sabre\VObject\Component\VCard', $vCard);
91
+            $cardData = $vCard->jsonSerialize();
92
+            $this->compareData($expectedVCard, $cardData);
93
+        } else {
94
+            $this->assertSame($expectedVCard, $vCard);
95
+        }
96
+    }
97
+
98
+    public function testManagerProp(): void {
99
+        $user = $this->getUserMock('user', '[email protected]', '[email protected]');
100
+        $user->method('getManagerUids')
101
+            ->willReturn(['mgr']);
102
+        $this->userManager->expects(self::once())
103
+            ->method('getDisplayName')
104
+            ->with('mgr')
105
+            ->willReturn('Manager');
106
+        $accountManager = $this->getAccountManager($user);
107
+
108
+        $converter = new Converter($accountManager, $this->userManager, $this->urlGenerator, $this->logger);
109
+        $vCard = $converter->createCardFromUser($user);
110
+
111
+        $this->compareData(
112
+            [
113
+                'cloud' => '[email protected]',
114
+                'email' => '[email protected]',
115
+                'x-managersname' => 'Manager',
116
+            ],
117
+            $vCard->jsonSerialize()
118
+        );
119
+    }
120
+
121
+    protected function compareData(array $expected, array $data): void {
122
+        foreach ($expected as $key => $value) {
123
+            $found = false;
124
+            foreach ($data[1] as $d) {
125
+                if ($d[0] === $key && $d[3] === $value) {
126
+                    $found = true;
127
+                    break;
128
+                }
129
+            }
130
+            if (!$found) {
131
+                $this->assertTrue(false, 'Expected data: ' . $key . ' not found.');
132
+            }
133
+        }
134
+    }
135
+
136
+    public static function providesNewUsers(): array {
137
+        return [
138
+            [
139
+                null
140
+            ],
141
+            [
142
+                null,
143
+                null,
144
+                '[email protected]'
145
+            ],
146
+            [
147
+                [
148
+                    'cloud' => '[email protected]',
149
+                    'email' => '[email protected]',
150
+                    'photo' => 'MTIzNDU2Nzg5',
151
+                ],
152
+                null,
153
+                '[email protected]',
154
+                '[email protected]'
155
+            ],
156
+            [
157
+                [
158
+                    'cloud' => '[email protected]',
159
+                    'email' => '[email protected]',
160
+                    'fn' => 'Dr. Foo Bar',
161
+                    'photo' => 'MTIzNDU2Nzg5',
162
+                ],
163
+                'Dr. Foo Bar',
164
+                '[email protected]',
165
+                '[email protected]'
166
+            ],
167
+            [
168
+                [
169
+                    'cloud' => '[email protected]',
170
+                    'fn' => 'Dr. Foo Bar',
171
+                    'photo' => 'MTIzNDU2Nzg5',
172
+                ],
173
+                'Dr. Foo Bar',
174
+                null,
175
+                '[email protected]'
176
+            ],
177
+            [
178
+                [
179
+                    'cloud' => '[email protected]',
180
+                    'fn' => 'Dr. Foo Bar',
181
+                    'photo' => 'MTIzNDU2Nzg5',
182
+                ],
183
+                'Dr. Foo Bar',
184
+                '',
185
+                '[email protected]'
186
+            ],
187
+        ];
188
+    }
189
+
190
+    #[\PHPUnit\Framework\Attributes\DataProvider('providesNames')]
191
+    public function testNameSplitter(string $expected, string $fullName): void {
192
+        $converter = new Converter($this->accountManager, $this->userManager, $this->urlGenerator, $this->logger);
193
+        $r = $converter->splitFullName($fullName);
194
+        $r = implode(';', $r);
195
+        $this->assertEquals($expected, $r);
196
+    }
197
+
198
+    public static function providesNames(): array {
199
+        return [
200
+            ['Sauron;;;;', 'Sauron'],
201
+            ['Baggins;Bilbo;;;', 'Bilbo Baggins'],
202
+            ['Tolkien;John;Ronald Reuel;;', 'John Ronald Reuel Tolkien'],
203
+        ];
204
+    }
205
+
206
+    /**
207
+     * @return IUser&MockObject
208
+     */
209
+    protected function getUserMock(string $displayName, ?string $eMailAddress, ?string $cloudId) {
210
+        $image0 = $this->createMock(IImage::class);
211
+        $image0->method('mimeType')->willReturn('image/jpeg');
212
+        $image0->method('data')->willReturn('123456789');
213
+        $user = $this->createMock(IUser::class);
214
+        $user->method('getUID')->willReturn('12345');
215
+        $user->method('getDisplayName')->willReturn($displayName);
216
+        $user->method('getEMailAddress')->willReturn($eMailAddress);
217
+        $user->method('getCloudId')->willReturn($cloudId);
218
+        $user->method('getAvatarImage')->willReturn($image0);
219
+        return $user;
220
+    }
221 221
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 			->willReturn($name);
47 47
 		$property->expects($this->any())
48 48
 			->method('getValue')
49
-			->willReturn((string)$value);
49
+			->willReturn((string) $value);
50 50
 		$property->expects($this->any())
51 51
 			->method('getScope')
52 52
 			->willReturn($scope);
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 		$account = $this->createMock(IAccount::class);
61 61
 		$account->expects($this->any())
62 62
 			->method('getAllProperties')
63
-			->willReturnCallback(function () use ($user) {
63
+			->willReturnCallback(function() use ($user) {
64 64
 				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_DISPLAYNAME, $user->getDisplayName(), IAccountManager::SCOPE_FEDERATED);
65 65
 				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_ADDRESS, '', IAccountManager::SCOPE_LOCAL);
66 66
 				yield $this->getAccountPropertyMock(IAccountManager::PROPERTY_WEBSITE, '', IAccountManager::SCOPE_LOCAL);
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
 	#[\PHPUnit\Framework\Attributes\DataProvider('providesNewUsers')]
83 83
 	public function testCreation($expectedVCard, $displayName = null, $eMailAddress = null, $cloudId = null): void {
84
-		$user = $this->getUserMock((string)$displayName, $eMailAddress, $cloudId);
84
+		$user = $this->getUserMock((string) $displayName, $eMailAddress, $cloudId);
85 85
 		$accountManager = $this->getAccountManager($user);
86 86
 
87 87
 		$converter = new Converter($accountManager, $this->userManager, $this->urlGenerator, $this->logger);
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 				}
129 129
 			}
130 130
 			if (!$found) {
131
-				$this->assertTrue(false, 'Expected data: ' . $key . ' not found.');
131
+				$this->assertTrue(false, 'Expected data: '.$key.' not found.');
132 132
 			}
133 133
 		}
134 134
 	}
Please login to merge, or discard this patch.
apps/dav/tests/unit/CardDAV/Activity/BackendTest.php 1 patch
Indentation   +458 added lines, -458 removed lines patch added patch discarded remove patch
@@ -22,462 +22,462 @@
 block discarded – undo
22 22
 use Test\TestCase;
23 23
 
24 24
 class BackendTest extends TestCase {
25
-	protected IManager&MockObject $activityManager;
26
-	protected IGroupManager&MockObject $groupManager;
27
-	protected IUserSession&MockObject $userSession;
28
-	protected IAppManager&MockObject $appManager;
29
-	protected IUserManager&MockObject $userManager;
30
-
31
-	protected function setUp(): void {
32
-		parent::setUp();
33
-		$this->activityManager = $this->createMock(IManager::class);
34
-		$this->groupManager = $this->createMock(IGroupManager::class);
35
-		$this->userSession = $this->createMock(IUserSession::class);
36
-		$this->appManager = $this->createMock(IAppManager::class);
37
-		$this->userManager = $this->createMock(IUserManager::class);
38
-	}
39
-
40
-	/**
41
-	 * @return Backend|MockObject
42
-	 */
43
-	protected function getBackend(array $methods = []): Backend {
44
-		if (empty($methods)) {
45
-			return new Backend(
46
-				$this->activityManager,
47
-				$this->groupManager,
48
-				$this->userSession,
49
-				$this->appManager,
50
-				$this->userManager
51
-			);
52
-		} else {
53
-			return $this->getMockBuilder(Backend::class)
54
-				->setConstructorArgs([
55
-					$this->activityManager,
56
-					$this->groupManager,
57
-					$this->userSession,
58
-					$this->appManager,
59
-					$this->userManager
60
-				])
61
-				->onlyMethods($methods)
62
-				->getMock();
63
-		}
64
-	}
65
-
66
-	public static function dataCallTriggerAddressBookActivity(): array {
67
-		return [
68
-			['onAddressbookCreate', [['data']], Addressbook::SUBJECT_ADD, [['data'], [], []]],
69
-			['onAddressbookUpdate', [['data'], ['shares'], ['changed-properties']], Addressbook::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
70
-			['onAddressbookDelete', [['data'], ['shares']], Addressbook::SUBJECT_DELETE, [['data'], ['shares'], []]],
71
-		];
72
-	}
73
-
74
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataCallTriggerAddressBookActivity')]
75
-	public function testCallTriggerAddressBookActivity(string $method, array $payload, string $expectedSubject, array $expectedPayload): void {
76
-		$backend = $this->getBackend(['triggerAddressbookActivity']);
77
-		$backend->expects($this->once())
78
-			->method('triggerAddressbookActivity')
79
-			->willReturnCallback(function () use ($expectedPayload, $expectedSubject): void {
80
-				$arguments = func_get_args();
81
-				$this->assertSame($expectedSubject, array_shift($arguments));
82
-				$this->assertEquals($expectedPayload, $arguments);
83
-			});
84
-
85
-		call_user_func_array([$backend, $method], $payload);
86
-	}
87
-
88
-	public static function dataTriggerAddressBookActivity(): array {
89
-		return [
90
-			// Add addressbook
91
-			[Addressbook::SUBJECT_ADD, [], [], [], '', '', null, []],
92
-			[Addressbook::SUBJECT_ADD, [
93
-				'principaluri' => 'principal/user/admin',
94
-				'id' => 42,
95
-				'uri' => 'this-uri',
96
-				'{DAV:}displayname' => 'Name of addressbook',
97
-			], [], [], '', 'admin', null, ['admin']],
98
-			[Addressbook::SUBJECT_ADD, [
99
-				'principaluri' => 'principal/user/admin',
100
-				'id' => 42,
101
-				'uri' => 'this-uri',
102
-				'{DAV:}displayname' => 'Name of addressbook',
103
-			], [], [], 'test2', 'test2', null, ['admin']],
104
-
105
-			// Update addressbook
106
-			[Addressbook::SUBJECT_UPDATE, [], [], [], '', '', null, []],
107
-			// No visible change - owner only
108
-			[Addressbook::SUBJECT_UPDATE, [
109
-				'principaluri' => 'principal/user/admin',
110
-				'id' => 42,
111
-				'uri' => 'this-uri',
112
-				'{DAV:}displayname' => 'Name of addressbook',
113
-			], ['shares'], [], '', 'admin', null, ['admin']],
114
-			// Visible change
115
-			[Addressbook::SUBJECT_UPDATE, [
116
-				'principaluri' => 'principal/user/admin',
117
-				'id' => 42,
118
-				'uri' => 'this-uri',
119
-				'{DAV:}displayname' => 'Name of addressbook',
120
-			], ['shares'], ['{DAV:}displayname' => 'Name'], '', 'admin', ['user1'], ['user1', 'admin']],
121
-			[Addressbook::SUBJECT_UPDATE, [
122
-				'principaluri' => 'principal/user/admin',
123
-				'id' => 42,
124
-				'uri' => 'this-uri',
125
-				'{DAV:}displayname' => 'Name of addressbook',
126
-			], ['shares'], ['{DAV:}displayname' => 'Name'], 'test2', 'test2', ['user1'], ['user1', 'admin']],
127
-
128
-			// Delete addressbook
129
-			[Addressbook::SUBJECT_DELETE, [], [], [], '', '', null, []],
130
-			[Addressbook::SUBJECT_DELETE, [
131
-				'principaluri' => 'principal/user/admin',
132
-				'id' => 42,
133
-				'uri' => 'this-uri',
134
-				'{DAV:}displayname' => 'Name of addressbook',
135
-			], ['shares'], [], '', 'admin', [], ['admin']],
136
-			[Addressbook::SUBJECT_DELETE, [
137
-				'principaluri' => 'principal/user/admin',
138
-				'id' => 42,
139
-				'uri' => 'this-uri',
140
-				'{DAV:}displayname' => 'Name of addressbook',
141
-			], ['shares'], [], '', 'admin', ['user1'], ['user1', 'admin']],
142
-			[Addressbook::SUBJECT_DELETE, [
143
-				'principaluri' => 'principal/user/admin',
144
-				'id' => 42,
145
-				'uri' => 'this-uri',
146
-				'{DAV:}displayname' => 'Name of addressbook',
147
-			], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']],
148
-		];
149
-	}
150
-
151
-	/**
152
-	 * @param string[]|null $shareUsers
153
-	 * @param string[] $users
154
-	 */
155
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataTriggerAddressBookActivity')]
156
-	public function testTriggerAddressBookActivity(string $action, array $data, array $shares, array $changedProperties, string $currentUser, string $author, ?array $shareUsers, array $users): void {
157
-		$backend = $this->getBackend(['getUsersForShares']);
158
-
159
-		if ($shareUsers === null) {
160
-			$backend->expects($this->never())
161
-				->method('getUsersForShares');
162
-		} else {
163
-			$backend->expects($this->once())
164
-				->method('getUsersForShares')
165
-				->with($shares)
166
-				->willReturn($shareUsers);
167
-		}
168
-
169
-		if ($author !== '') {
170
-			if ($currentUser !== '') {
171
-				$this->userSession->expects($this->once())
172
-					->method('getUser')
173
-					->willReturn($this->getUserMock($currentUser));
174
-			} else {
175
-				$this->userSession->expects($this->once())
176
-					->method('getUser')
177
-					->willReturn(null);
178
-			}
179
-
180
-			$event = $this->createMock(IEvent::class);
181
-			$this->activityManager->expects($this->once())
182
-				->method('generateEvent')
183
-				->willReturn($event);
184
-
185
-			$event->expects($this->once())
186
-				->method('setApp')
187
-				->with('dav')
188
-				->willReturnSelf();
189
-			$event->expects($this->once())
190
-				->method('setObject')
191
-				->with('addressbook', $data['id'])
192
-				->willReturnSelf();
193
-			$event->expects($this->once())
194
-				->method('setType')
195
-				->with('contacts')
196
-				->willReturnSelf();
197
-			$event->expects($this->once())
198
-				->method('setAuthor')
199
-				->with($author)
200
-				->willReturnSelf();
201
-
202
-			$this->userManager->expects($action === Addressbook::SUBJECT_DELETE ? $this->exactly(sizeof($users)) : $this->never())
203
-				->method('userExists')
204
-				->willReturn(true);
205
-
206
-			$event->expects($this->exactly(count($users)))
207
-				->method('setAffectedUser')
208
-				->willReturnSelf();
209
-			$event->expects($this->exactly(count($users)))
210
-				->method('setSubject')
211
-				->willReturnSelf();
212
-			$this->activityManager->expects($this->exactly(count($users)))
213
-				->method('publish')
214
-				->with($event);
215
-		} else {
216
-			$this->activityManager->expects($this->never())
217
-				->method('generateEvent');
218
-		}
219
-
220
-		$this->invokePrivate($backend, 'triggerAddressbookActivity', [$action, $data, $shares, $changedProperties]);
221
-	}
222
-
223
-	public function testNoAddressbookActivityCreatedForSystemAddressbook(): void {
224
-		$backend = $this->getBackend();
225
-		$this->activityManager->expects($this->never())
226
-			->method('generateEvent');
227
-		$this->assertEmpty($this->invokePrivate($backend, 'triggerAddressbookActivity', [Addressbook::SUBJECT_ADD, ['principaluri' => 'principals/system/system'], [], [], '', '', null, []]));
228
-	}
229
-
230
-	public function testUserDeletionDoesNotCreateActivity(): void {
231
-		$backend = $this->getBackend();
232
-
233
-		$this->userManager->expects($this->once())
234
-			->method('userExists')
235
-			->willReturn(false);
236
-
237
-		$this->activityManager->expects($this->never())
238
-			->method('publish');
239
-
240
-		$this->invokePrivate($backend, 'triggerAddressbookActivity', [Addressbook::SUBJECT_DELETE, [
241
-			'principaluri' => 'principal/user/admin',
242
-			'id' => 42,
243
-			'uri' => 'this-uri',
244
-			'{DAV:}displayname' => 'Name of addressbook',
245
-		], [], []]);
246
-	}
247
-
248
-	public static function dataTriggerCardActivity(): array {
249
-		$cardData = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 3.4.8//EN\r\nUID:test-user\r\nFN:test-user\r\nN:test-user;;;;\r\nEND:VCARD\r\n\r\n";
250
-
251
-		return [
252
-			// Add card
253
-			[Card::SUBJECT_ADD, [], [], [], '', '', null, []],
254
-			[Card::SUBJECT_ADD, [
255
-				'principaluri' => 'principal/user/admin',
256
-				'id' => 42,
257
-				'uri' => 'this-uri',
258
-				'{DAV:}displayname' => 'Name of addressbook',
259
-			], [], [
260
-				'carddata' => $cardData
261
-			], '', 'admin', [], ['admin']],
262
-			[Card::SUBJECT_ADD, [
263
-				'principaluri' => 'principal/user/admin',
264
-				'id' => 42,
265
-				'uri' => 'this-uri',
266
-				'{DAV:}displayname' => 'Name of addressbook',
267
-			], [], ['carddata' => $cardData], 'test2', 'test2', [], ['admin']],
268
-
269
-			// Update card
270
-			[Card::SUBJECT_UPDATE, [], [], [], '', '', null, []],
271
-			// No visible change - owner only
272
-			[Card::SUBJECT_UPDATE, [
273
-				'principaluri' => 'principal/user/admin',
274
-				'id' => 42,
275
-				'uri' => 'this-uri',
276
-				'{DAV:}displayname' => 'Name of addressbook',
277
-			], ['shares'], ['carddata' => $cardData], '', 'admin', [], ['admin']],
278
-			// Visible change
279
-			[Card::SUBJECT_UPDATE, [
280
-				'principaluri' => 'principal/user/admin',
281
-				'id' => 42,
282
-				'uri' => 'this-uri',
283
-				'{DAV:}displayname' => 'Name of addressbook',
284
-			], ['shares'], ['carddata' => $cardData], '', 'admin', ['user1'], ['user1', 'admin']],
285
-			[Card::SUBJECT_UPDATE, [
286
-				'principaluri' => 'principal/user/admin',
287
-				'id' => 42,
288
-				'uri' => 'this-uri',
289
-				'{DAV:}displayname' => 'Name of addressbook',
290
-			], ['shares'], ['carddata' => $cardData], 'test2', 'test2', ['user1'], ['user1', 'admin']],
291
-
292
-			// Delete card
293
-			[Card::SUBJECT_DELETE, [], [], ['carddata' => $cardData], '', '', null, []],
294
-			[Card::SUBJECT_DELETE, [
295
-				'principaluri' => 'principal/user/admin',
296
-				'id' => 42,
297
-				'uri' => 'this-uri',
298
-				'{DAV:}displayname' => 'Name of addressbook',
299
-			], ['shares'], ['carddata' => $cardData], '', 'admin', [], ['admin']],
300
-			[Card::SUBJECT_DELETE, [
301
-				'principaluri' => 'principal/user/admin',
302
-				'id' => 42,
303
-				'uri' => 'this-uri',
304
-				'{DAV:}displayname' => 'Name of addressbook',
305
-			], ['shares'], ['carddata' => $cardData], '', 'admin', ['user1'], ['user1', 'admin']],
306
-			[Card::SUBJECT_DELETE, [
307
-				'principaluri' => 'principal/user/admin',
308
-				'id' => 42,
309
-				'uri' => 'this-uri',
310
-				'{DAV:}displayname' => 'Name of addressbook',
311
-			], ['shares'], ['carddata' => $cardData], 'test2', 'test2', ['user1'], ['user1', 'admin']],
312
-		];
313
-	}
314
-
315
-	/**
316
-	 * @param string[]|null $shareUsers
317
-	 * @param string[] $users
318
-	 */
319
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataTriggerCardActivity')]
320
-	public function testTriggerCardActivity(string $action, array $addressBookData, array $shares, array $cardData, string $currentUser, string $author, ?array $shareUsers, array $users): void {
321
-		$backend = $this->getBackend(['getUsersForShares']);
322
-
323
-		if ($shareUsers === null) {
324
-			$backend->expects($this->never())
325
-				->method('getUsersForShares');
326
-		} else {
327
-			$backend->expects($this->once())
328
-				->method('getUsersForShares')
329
-				->with($shares)
330
-				->willReturn($shareUsers);
331
-		}
332
-
333
-		if ($author !== '') {
334
-			if ($currentUser !== '') {
335
-				$this->userSession->expects($this->once())
336
-					->method('getUser')
337
-					->willReturn($this->getUserMock($currentUser));
338
-			} else {
339
-				$this->userSession->expects($this->once())
340
-					->method('getUser')
341
-					->willReturn(null);
342
-			}
343
-
344
-			$event = $this->createMock(IEvent::class);
345
-			$this->activityManager->expects($this->once())
346
-				->method('generateEvent')
347
-				->willReturn($event);
348
-
349
-			$event->expects($this->once())
350
-				->method('setApp')
351
-				->with('dav')
352
-				->willReturnSelf();
353
-			$event->expects($this->once())
354
-				->method('setObject')
355
-				->with('addressbook', $addressBookData['id'])
356
-				->willReturnSelf();
357
-			$event->expects($this->once())
358
-				->method('setType')
359
-				->with('contacts')
360
-				->willReturnSelf();
361
-			$event->expects($this->once())
362
-				->method('setAuthor')
363
-				->with($author)
364
-				->willReturnSelf();
365
-
366
-			$event->expects($this->exactly(count($users)))
367
-				->method('setAffectedUser')
368
-				->willReturnSelf();
369
-			$event->expects($this->exactly(count($users)))
370
-				->method('setSubject')
371
-				->willReturnSelf();
372
-			$this->activityManager->expects($this->exactly(count($users)))
373
-				->method('publish')
374
-				->with($event);
375
-		} else {
376
-			$this->activityManager->expects($this->never())
377
-				->method('generateEvent');
378
-		}
379
-
380
-		$this->invokePrivate($backend, 'triggerCardActivity', [$action, $addressBookData, $shares, $cardData]);
381
-	}
382
-
383
-	public function testNoCardActivityCreatedForSystemAddressbook(): void {
384
-		$backend = $this->getBackend();
385
-		$this->activityManager->expects($this->never())
386
-			->method('generateEvent');
387
-		$this->assertEmpty($this->invokePrivate($backend, 'triggerCardActivity', [Card::SUBJECT_UPDATE, ['principaluri' => 'principals/system/system'], [], []]));
388
-	}
389
-
390
-	public static function dataGetUsersForShares(): array {
391
-		return [
392
-			[
393
-				[],
394
-				[],
395
-				[],
396
-			],
397
-			[
398
-				[
399
-					['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
400
-					['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
401
-					['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
402
-					['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
403
-					['{http://owncloud.org/ns}principal' => 'principal/users/user3'],
404
-				],
405
-				[],
406
-				['user1', 'user2', 'user3'],
407
-			],
408
-			[
409
-				[
410
-					['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
411
-					['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
412
-					['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
413
-					['{http://owncloud.org/ns}principal' => 'principal/groups/group2'],
414
-					['{http://owncloud.org/ns}principal' => 'principal/groups/group3'],
415
-				],
416
-				['group2' => null, 'group3' => null],
417
-				['user1', 'user2'],
418
-			],
419
-			[
420
-				[
421
-					['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
422
-					['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
423
-					['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
424
-					['{http://owncloud.org/ns}principal' => 'principal/groups/group2'],
425
-					['{http://owncloud.org/ns}principal' => 'principal/groups/group3'],
426
-				],
427
-				['group2' => ['user1', 'user2', 'user3'], 'group3' => ['user2', 'user3', 'user4']],
428
-				['user1', 'user2', 'user3', 'user4'],
429
-			],
430
-		];
431
-	}
432
-
433
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataGetUsersForShares')]
434
-	public function testGetUsersForShares(array $shares, array $groups, array $expected): void {
435
-		$backend = $this->getBackend();
436
-
437
-		$getGroups = [];
438
-		foreach ($groups as $gid => $members) {
439
-			if ($members === null) {
440
-				$getGroups[] = [$gid, null];
441
-				continue;
442
-			}
443
-
444
-			$group = $this->createMock(IGroup::class);
445
-			$group->expects($this->once())
446
-				->method('getUsers')
447
-				->willReturn($this->getUsers($members));
448
-
449
-			$getGroups[] = [$gid, $group];
450
-		}
451
-
452
-		$this->groupManager->expects($this->exactly(sizeof($getGroups)))
453
-			->method('get')
454
-			->willReturnMap($getGroups);
455
-
456
-		$users = $this->invokePrivate($backend, 'getUsersForShares', [$shares]);
457
-		sort($users);
458
-		$this->assertEquals($expected, $users);
459
-	}
460
-
461
-	/**
462
-	 * @param string[] $users
463
-	 * @return IUser[]|MockObject[]
464
-	 */
465
-	protected function getUsers(array $users): array {
466
-		$list = [];
467
-		foreach ($users as $user) {
468
-			$list[] = $this->getUserMock($user);
469
-		}
470
-		return $list;
471
-	}
472
-
473
-	/**
474
-	 * @return IUser|MockObject
475
-	 */
476
-	protected function getUserMock(string $uid): IUser {
477
-		$user = $this->createMock(IUser::class);
478
-		$user->expects($this->once())
479
-			->method('getUID')
480
-			->willReturn($uid);
481
-		return $user;
482
-	}
25
+    protected IManager&MockObject $activityManager;
26
+    protected IGroupManager&MockObject $groupManager;
27
+    protected IUserSession&MockObject $userSession;
28
+    protected IAppManager&MockObject $appManager;
29
+    protected IUserManager&MockObject $userManager;
30
+
31
+    protected function setUp(): void {
32
+        parent::setUp();
33
+        $this->activityManager = $this->createMock(IManager::class);
34
+        $this->groupManager = $this->createMock(IGroupManager::class);
35
+        $this->userSession = $this->createMock(IUserSession::class);
36
+        $this->appManager = $this->createMock(IAppManager::class);
37
+        $this->userManager = $this->createMock(IUserManager::class);
38
+    }
39
+
40
+    /**
41
+     * @return Backend|MockObject
42
+     */
43
+    protected function getBackend(array $methods = []): Backend {
44
+        if (empty($methods)) {
45
+            return new Backend(
46
+                $this->activityManager,
47
+                $this->groupManager,
48
+                $this->userSession,
49
+                $this->appManager,
50
+                $this->userManager
51
+            );
52
+        } else {
53
+            return $this->getMockBuilder(Backend::class)
54
+                ->setConstructorArgs([
55
+                    $this->activityManager,
56
+                    $this->groupManager,
57
+                    $this->userSession,
58
+                    $this->appManager,
59
+                    $this->userManager
60
+                ])
61
+                ->onlyMethods($methods)
62
+                ->getMock();
63
+        }
64
+    }
65
+
66
+    public static function dataCallTriggerAddressBookActivity(): array {
67
+        return [
68
+            ['onAddressbookCreate', [['data']], Addressbook::SUBJECT_ADD, [['data'], [], []]],
69
+            ['onAddressbookUpdate', [['data'], ['shares'], ['changed-properties']], Addressbook::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
70
+            ['onAddressbookDelete', [['data'], ['shares']], Addressbook::SUBJECT_DELETE, [['data'], ['shares'], []]],
71
+        ];
72
+    }
73
+
74
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataCallTriggerAddressBookActivity')]
75
+    public function testCallTriggerAddressBookActivity(string $method, array $payload, string $expectedSubject, array $expectedPayload): void {
76
+        $backend = $this->getBackend(['triggerAddressbookActivity']);
77
+        $backend->expects($this->once())
78
+            ->method('triggerAddressbookActivity')
79
+            ->willReturnCallback(function () use ($expectedPayload, $expectedSubject): void {
80
+                $arguments = func_get_args();
81
+                $this->assertSame($expectedSubject, array_shift($arguments));
82
+                $this->assertEquals($expectedPayload, $arguments);
83
+            });
84
+
85
+        call_user_func_array([$backend, $method], $payload);
86
+    }
87
+
88
+    public static function dataTriggerAddressBookActivity(): array {
89
+        return [
90
+            // Add addressbook
91
+            [Addressbook::SUBJECT_ADD, [], [], [], '', '', null, []],
92
+            [Addressbook::SUBJECT_ADD, [
93
+                'principaluri' => 'principal/user/admin',
94
+                'id' => 42,
95
+                'uri' => 'this-uri',
96
+                '{DAV:}displayname' => 'Name of addressbook',
97
+            ], [], [], '', 'admin', null, ['admin']],
98
+            [Addressbook::SUBJECT_ADD, [
99
+                'principaluri' => 'principal/user/admin',
100
+                'id' => 42,
101
+                'uri' => 'this-uri',
102
+                '{DAV:}displayname' => 'Name of addressbook',
103
+            ], [], [], 'test2', 'test2', null, ['admin']],
104
+
105
+            // Update addressbook
106
+            [Addressbook::SUBJECT_UPDATE, [], [], [], '', '', null, []],
107
+            // No visible change - owner only
108
+            [Addressbook::SUBJECT_UPDATE, [
109
+                'principaluri' => 'principal/user/admin',
110
+                'id' => 42,
111
+                'uri' => 'this-uri',
112
+                '{DAV:}displayname' => 'Name of addressbook',
113
+            ], ['shares'], [], '', 'admin', null, ['admin']],
114
+            // Visible change
115
+            [Addressbook::SUBJECT_UPDATE, [
116
+                'principaluri' => 'principal/user/admin',
117
+                'id' => 42,
118
+                'uri' => 'this-uri',
119
+                '{DAV:}displayname' => 'Name of addressbook',
120
+            ], ['shares'], ['{DAV:}displayname' => 'Name'], '', 'admin', ['user1'], ['user1', 'admin']],
121
+            [Addressbook::SUBJECT_UPDATE, [
122
+                'principaluri' => 'principal/user/admin',
123
+                'id' => 42,
124
+                'uri' => 'this-uri',
125
+                '{DAV:}displayname' => 'Name of addressbook',
126
+            ], ['shares'], ['{DAV:}displayname' => 'Name'], 'test2', 'test2', ['user1'], ['user1', 'admin']],
127
+
128
+            // Delete addressbook
129
+            [Addressbook::SUBJECT_DELETE, [], [], [], '', '', null, []],
130
+            [Addressbook::SUBJECT_DELETE, [
131
+                'principaluri' => 'principal/user/admin',
132
+                'id' => 42,
133
+                'uri' => 'this-uri',
134
+                '{DAV:}displayname' => 'Name of addressbook',
135
+            ], ['shares'], [], '', 'admin', [], ['admin']],
136
+            [Addressbook::SUBJECT_DELETE, [
137
+                'principaluri' => 'principal/user/admin',
138
+                'id' => 42,
139
+                'uri' => 'this-uri',
140
+                '{DAV:}displayname' => 'Name of addressbook',
141
+            ], ['shares'], [], '', 'admin', ['user1'], ['user1', 'admin']],
142
+            [Addressbook::SUBJECT_DELETE, [
143
+                'principaluri' => 'principal/user/admin',
144
+                'id' => 42,
145
+                'uri' => 'this-uri',
146
+                '{DAV:}displayname' => 'Name of addressbook',
147
+            ], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']],
148
+        ];
149
+    }
150
+
151
+    /**
152
+     * @param string[]|null $shareUsers
153
+     * @param string[] $users
154
+     */
155
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataTriggerAddressBookActivity')]
156
+    public function testTriggerAddressBookActivity(string $action, array $data, array $shares, array $changedProperties, string $currentUser, string $author, ?array $shareUsers, array $users): void {
157
+        $backend = $this->getBackend(['getUsersForShares']);
158
+
159
+        if ($shareUsers === null) {
160
+            $backend->expects($this->never())
161
+                ->method('getUsersForShares');
162
+        } else {
163
+            $backend->expects($this->once())
164
+                ->method('getUsersForShares')
165
+                ->with($shares)
166
+                ->willReturn($shareUsers);
167
+        }
168
+
169
+        if ($author !== '') {
170
+            if ($currentUser !== '') {
171
+                $this->userSession->expects($this->once())
172
+                    ->method('getUser')
173
+                    ->willReturn($this->getUserMock($currentUser));
174
+            } else {
175
+                $this->userSession->expects($this->once())
176
+                    ->method('getUser')
177
+                    ->willReturn(null);
178
+            }
179
+
180
+            $event = $this->createMock(IEvent::class);
181
+            $this->activityManager->expects($this->once())
182
+                ->method('generateEvent')
183
+                ->willReturn($event);
184
+
185
+            $event->expects($this->once())
186
+                ->method('setApp')
187
+                ->with('dav')
188
+                ->willReturnSelf();
189
+            $event->expects($this->once())
190
+                ->method('setObject')
191
+                ->with('addressbook', $data['id'])
192
+                ->willReturnSelf();
193
+            $event->expects($this->once())
194
+                ->method('setType')
195
+                ->with('contacts')
196
+                ->willReturnSelf();
197
+            $event->expects($this->once())
198
+                ->method('setAuthor')
199
+                ->with($author)
200
+                ->willReturnSelf();
201
+
202
+            $this->userManager->expects($action === Addressbook::SUBJECT_DELETE ? $this->exactly(sizeof($users)) : $this->never())
203
+                ->method('userExists')
204
+                ->willReturn(true);
205
+
206
+            $event->expects($this->exactly(count($users)))
207
+                ->method('setAffectedUser')
208
+                ->willReturnSelf();
209
+            $event->expects($this->exactly(count($users)))
210
+                ->method('setSubject')
211
+                ->willReturnSelf();
212
+            $this->activityManager->expects($this->exactly(count($users)))
213
+                ->method('publish')
214
+                ->with($event);
215
+        } else {
216
+            $this->activityManager->expects($this->never())
217
+                ->method('generateEvent');
218
+        }
219
+
220
+        $this->invokePrivate($backend, 'triggerAddressbookActivity', [$action, $data, $shares, $changedProperties]);
221
+    }
222
+
223
+    public function testNoAddressbookActivityCreatedForSystemAddressbook(): void {
224
+        $backend = $this->getBackend();
225
+        $this->activityManager->expects($this->never())
226
+            ->method('generateEvent');
227
+        $this->assertEmpty($this->invokePrivate($backend, 'triggerAddressbookActivity', [Addressbook::SUBJECT_ADD, ['principaluri' => 'principals/system/system'], [], [], '', '', null, []]));
228
+    }
229
+
230
+    public function testUserDeletionDoesNotCreateActivity(): void {
231
+        $backend = $this->getBackend();
232
+
233
+        $this->userManager->expects($this->once())
234
+            ->method('userExists')
235
+            ->willReturn(false);
236
+
237
+        $this->activityManager->expects($this->never())
238
+            ->method('publish');
239
+
240
+        $this->invokePrivate($backend, 'triggerAddressbookActivity', [Addressbook::SUBJECT_DELETE, [
241
+            'principaluri' => 'principal/user/admin',
242
+            'id' => 42,
243
+            'uri' => 'this-uri',
244
+            '{DAV:}displayname' => 'Name of addressbook',
245
+        ], [], []]);
246
+    }
247
+
248
+    public static function dataTriggerCardActivity(): array {
249
+        $cardData = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 3.4.8//EN\r\nUID:test-user\r\nFN:test-user\r\nN:test-user;;;;\r\nEND:VCARD\r\n\r\n";
250
+
251
+        return [
252
+            // Add card
253
+            [Card::SUBJECT_ADD, [], [], [], '', '', null, []],
254
+            [Card::SUBJECT_ADD, [
255
+                'principaluri' => 'principal/user/admin',
256
+                'id' => 42,
257
+                'uri' => 'this-uri',
258
+                '{DAV:}displayname' => 'Name of addressbook',
259
+            ], [], [
260
+                'carddata' => $cardData
261
+            ], '', 'admin', [], ['admin']],
262
+            [Card::SUBJECT_ADD, [
263
+                'principaluri' => 'principal/user/admin',
264
+                'id' => 42,
265
+                'uri' => 'this-uri',
266
+                '{DAV:}displayname' => 'Name of addressbook',
267
+            ], [], ['carddata' => $cardData], 'test2', 'test2', [], ['admin']],
268
+
269
+            // Update card
270
+            [Card::SUBJECT_UPDATE, [], [], [], '', '', null, []],
271
+            // No visible change - owner only
272
+            [Card::SUBJECT_UPDATE, [
273
+                'principaluri' => 'principal/user/admin',
274
+                'id' => 42,
275
+                'uri' => 'this-uri',
276
+                '{DAV:}displayname' => 'Name of addressbook',
277
+            ], ['shares'], ['carddata' => $cardData], '', 'admin', [], ['admin']],
278
+            // Visible change
279
+            [Card::SUBJECT_UPDATE, [
280
+                'principaluri' => 'principal/user/admin',
281
+                'id' => 42,
282
+                'uri' => 'this-uri',
283
+                '{DAV:}displayname' => 'Name of addressbook',
284
+            ], ['shares'], ['carddata' => $cardData], '', 'admin', ['user1'], ['user1', 'admin']],
285
+            [Card::SUBJECT_UPDATE, [
286
+                'principaluri' => 'principal/user/admin',
287
+                'id' => 42,
288
+                'uri' => 'this-uri',
289
+                '{DAV:}displayname' => 'Name of addressbook',
290
+            ], ['shares'], ['carddata' => $cardData], 'test2', 'test2', ['user1'], ['user1', 'admin']],
291
+
292
+            // Delete card
293
+            [Card::SUBJECT_DELETE, [], [], ['carddata' => $cardData], '', '', null, []],
294
+            [Card::SUBJECT_DELETE, [
295
+                'principaluri' => 'principal/user/admin',
296
+                'id' => 42,
297
+                'uri' => 'this-uri',
298
+                '{DAV:}displayname' => 'Name of addressbook',
299
+            ], ['shares'], ['carddata' => $cardData], '', 'admin', [], ['admin']],
300
+            [Card::SUBJECT_DELETE, [
301
+                'principaluri' => 'principal/user/admin',
302
+                'id' => 42,
303
+                'uri' => 'this-uri',
304
+                '{DAV:}displayname' => 'Name of addressbook',
305
+            ], ['shares'], ['carddata' => $cardData], '', 'admin', ['user1'], ['user1', 'admin']],
306
+            [Card::SUBJECT_DELETE, [
307
+                'principaluri' => 'principal/user/admin',
308
+                'id' => 42,
309
+                'uri' => 'this-uri',
310
+                '{DAV:}displayname' => 'Name of addressbook',
311
+            ], ['shares'], ['carddata' => $cardData], 'test2', 'test2', ['user1'], ['user1', 'admin']],
312
+        ];
313
+    }
314
+
315
+    /**
316
+     * @param string[]|null $shareUsers
317
+     * @param string[] $users
318
+     */
319
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataTriggerCardActivity')]
320
+    public function testTriggerCardActivity(string $action, array $addressBookData, array $shares, array $cardData, string $currentUser, string $author, ?array $shareUsers, array $users): void {
321
+        $backend = $this->getBackend(['getUsersForShares']);
322
+
323
+        if ($shareUsers === null) {
324
+            $backend->expects($this->never())
325
+                ->method('getUsersForShares');
326
+        } else {
327
+            $backend->expects($this->once())
328
+                ->method('getUsersForShares')
329
+                ->with($shares)
330
+                ->willReturn($shareUsers);
331
+        }
332
+
333
+        if ($author !== '') {
334
+            if ($currentUser !== '') {
335
+                $this->userSession->expects($this->once())
336
+                    ->method('getUser')
337
+                    ->willReturn($this->getUserMock($currentUser));
338
+            } else {
339
+                $this->userSession->expects($this->once())
340
+                    ->method('getUser')
341
+                    ->willReturn(null);
342
+            }
343
+
344
+            $event = $this->createMock(IEvent::class);
345
+            $this->activityManager->expects($this->once())
346
+                ->method('generateEvent')
347
+                ->willReturn($event);
348
+
349
+            $event->expects($this->once())
350
+                ->method('setApp')
351
+                ->with('dav')
352
+                ->willReturnSelf();
353
+            $event->expects($this->once())
354
+                ->method('setObject')
355
+                ->with('addressbook', $addressBookData['id'])
356
+                ->willReturnSelf();
357
+            $event->expects($this->once())
358
+                ->method('setType')
359
+                ->with('contacts')
360
+                ->willReturnSelf();
361
+            $event->expects($this->once())
362
+                ->method('setAuthor')
363
+                ->with($author)
364
+                ->willReturnSelf();
365
+
366
+            $event->expects($this->exactly(count($users)))
367
+                ->method('setAffectedUser')
368
+                ->willReturnSelf();
369
+            $event->expects($this->exactly(count($users)))
370
+                ->method('setSubject')
371
+                ->willReturnSelf();
372
+            $this->activityManager->expects($this->exactly(count($users)))
373
+                ->method('publish')
374
+                ->with($event);
375
+        } else {
376
+            $this->activityManager->expects($this->never())
377
+                ->method('generateEvent');
378
+        }
379
+
380
+        $this->invokePrivate($backend, 'triggerCardActivity', [$action, $addressBookData, $shares, $cardData]);
381
+    }
382
+
383
+    public function testNoCardActivityCreatedForSystemAddressbook(): void {
384
+        $backend = $this->getBackend();
385
+        $this->activityManager->expects($this->never())
386
+            ->method('generateEvent');
387
+        $this->assertEmpty($this->invokePrivate($backend, 'triggerCardActivity', [Card::SUBJECT_UPDATE, ['principaluri' => 'principals/system/system'], [], []]));
388
+    }
389
+
390
+    public static function dataGetUsersForShares(): array {
391
+        return [
392
+            [
393
+                [],
394
+                [],
395
+                [],
396
+            ],
397
+            [
398
+                [
399
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
400
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
401
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
402
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
403
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user3'],
404
+                ],
405
+                [],
406
+                ['user1', 'user2', 'user3'],
407
+            ],
408
+            [
409
+                [
410
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
411
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
412
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
413
+                    ['{http://owncloud.org/ns}principal' => 'principal/groups/group2'],
414
+                    ['{http://owncloud.org/ns}principal' => 'principal/groups/group3'],
415
+                ],
416
+                ['group2' => null, 'group3' => null],
417
+                ['user1', 'user2'],
418
+            ],
419
+            [
420
+                [
421
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
422
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
423
+                    ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
424
+                    ['{http://owncloud.org/ns}principal' => 'principal/groups/group2'],
425
+                    ['{http://owncloud.org/ns}principal' => 'principal/groups/group3'],
426
+                ],
427
+                ['group2' => ['user1', 'user2', 'user3'], 'group3' => ['user2', 'user3', 'user4']],
428
+                ['user1', 'user2', 'user3', 'user4'],
429
+            ],
430
+        ];
431
+    }
432
+
433
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataGetUsersForShares')]
434
+    public function testGetUsersForShares(array $shares, array $groups, array $expected): void {
435
+        $backend = $this->getBackend();
436
+
437
+        $getGroups = [];
438
+        foreach ($groups as $gid => $members) {
439
+            if ($members === null) {
440
+                $getGroups[] = [$gid, null];
441
+                continue;
442
+            }
443
+
444
+            $group = $this->createMock(IGroup::class);
445
+            $group->expects($this->once())
446
+                ->method('getUsers')
447
+                ->willReturn($this->getUsers($members));
448
+
449
+            $getGroups[] = [$gid, $group];
450
+        }
451
+
452
+        $this->groupManager->expects($this->exactly(sizeof($getGroups)))
453
+            ->method('get')
454
+            ->willReturnMap($getGroups);
455
+
456
+        $users = $this->invokePrivate($backend, 'getUsersForShares', [$shares]);
457
+        sort($users);
458
+        $this->assertEquals($expected, $users);
459
+    }
460
+
461
+    /**
462
+     * @param string[] $users
463
+     * @return IUser[]|MockObject[]
464
+     */
465
+    protected function getUsers(array $users): array {
466
+        $list = [];
467
+        foreach ($users as $user) {
468
+            $list[] = $this->getUserMock($user);
469
+        }
470
+        return $list;
471
+    }
472
+
473
+    /**
474
+     * @return IUser|MockObject
475
+     */
476
+    protected function getUserMock(string $uid): IUser {
477
+        $user = $this->createMock(IUser::class);
478
+        $user->expects($this->once())
479
+            ->method('getUID')
480
+            ->willReturn($uid);
481
+        return $user;
482
+    }
483 483
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Command/ListAddressbooksTest.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -20,88 +20,88 @@
 block discarded – undo
20 20
  * @package OCA\DAV\Tests\Command
21 21
  */
22 22
 class ListAddressbooksTest extends TestCase {
23
-	private IUserManager&MockObject $userManager;
24
-	private CardDavBackend&MockObject $cardDavBackend;
25
-	private ListAddressbooks $command;
26
-
27
-	public const USERNAME = 'username';
28
-
29
-	protected function setUp(): void {
30
-		parent::setUp();
31
-
32
-		$this->userManager = $this->createMock(IUserManager::class);
33
-		$this->cardDavBackend = $this->createMock(CardDavBackend::class);
34
-
35
-		$this->command = new ListAddressbooks(
36
-			$this->userManager,
37
-			$this->cardDavBackend
38
-		);
39
-	}
40
-
41
-	public function testWithBadUser(): void {
42
-		$this->expectException(\InvalidArgumentException::class);
43
-
44
-		$this->userManager->expects($this->once())
45
-			->method('userExists')
46
-			->with(self::USERNAME)
47
-			->willReturn(false);
48
-
49
-		$commandTester = new CommandTester($this->command);
50
-		$commandTester->execute([
51
-			'uid' => self::USERNAME,
52
-		]);
53
-		$this->assertStringContainsString('User <' . self::USERNAME . '> in unknown', $commandTester->getDisplay());
54
-	}
55
-
56
-	public function testWithCorrectUserWithNoCalendars(): void {
57
-		$this->userManager->expects($this->once())
58
-			->method('userExists')
59
-			->with(self::USERNAME)
60
-			->willReturn(true);
61
-
62
-		$this->cardDavBackend->expects($this->once())
63
-			->method('getAddressBooksForUser')
64
-			->with('principals/users/' . self::USERNAME)
65
-			->willReturn([]);
66
-
67
-		$commandTester = new CommandTester($this->command);
68
-		$commandTester->execute([
69
-			'uid' => self::USERNAME,
70
-		]);
71
-		$this->assertStringContainsString('User <' . self::USERNAME . "> has no addressbooks\n", $commandTester->getDisplay());
72
-	}
73
-
74
-	public static function dataExecute(): array {
75
-		return [
76
-			[false, '✓'],
77
-			[true, 'x']
78
-		];
79
-	}
80
-
81
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
82
-	public function testWithCorrectUser(bool $readOnly, string $output): void {
83
-		$this->userManager->expects($this->once())
84
-			->method('userExists')
85
-			->with(self::USERNAME)
86
-			->willReturn(true);
87
-
88
-		$this->cardDavBackend->expects($this->once())
89
-			->method('getAddressBooksForUser')
90
-			->with('principals/users/' . self::USERNAME)
91
-			->willReturn([
92
-				[
93
-					'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $readOnly,
94
-					'uri' => 'test',
95
-					'{DAV:}displayname' => 'dp',
96
-					'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => 'owner-principal',
97
-					'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname' => 'owner-dp',
98
-				]
99
-			]);
100
-
101
-		$commandTester = new CommandTester($this->command);
102
-		$commandTester->execute([
103
-			'uid' => self::USERNAME,
104
-		]);
105
-		$this->assertStringContainsString($output, $commandTester->getDisplay());
106
-	}
23
+    private IUserManager&MockObject $userManager;
24
+    private CardDavBackend&MockObject $cardDavBackend;
25
+    private ListAddressbooks $command;
26
+
27
+    public const USERNAME = 'username';
28
+
29
+    protected function setUp(): void {
30
+        parent::setUp();
31
+
32
+        $this->userManager = $this->createMock(IUserManager::class);
33
+        $this->cardDavBackend = $this->createMock(CardDavBackend::class);
34
+
35
+        $this->command = new ListAddressbooks(
36
+            $this->userManager,
37
+            $this->cardDavBackend
38
+        );
39
+    }
40
+
41
+    public function testWithBadUser(): void {
42
+        $this->expectException(\InvalidArgumentException::class);
43
+
44
+        $this->userManager->expects($this->once())
45
+            ->method('userExists')
46
+            ->with(self::USERNAME)
47
+            ->willReturn(false);
48
+
49
+        $commandTester = new CommandTester($this->command);
50
+        $commandTester->execute([
51
+            'uid' => self::USERNAME,
52
+        ]);
53
+        $this->assertStringContainsString('User <' . self::USERNAME . '> in unknown', $commandTester->getDisplay());
54
+    }
55
+
56
+    public function testWithCorrectUserWithNoCalendars(): void {
57
+        $this->userManager->expects($this->once())
58
+            ->method('userExists')
59
+            ->with(self::USERNAME)
60
+            ->willReturn(true);
61
+
62
+        $this->cardDavBackend->expects($this->once())
63
+            ->method('getAddressBooksForUser')
64
+            ->with('principals/users/' . self::USERNAME)
65
+            ->willReturn([]);
66
+
67
+        $commandTester = new CommandTester($this->command);
68
+        $commandTester->execute([
69
+            'uid' => self::USERNAME,
70
+        ]);
71
+        $this->assertStringContainsString('User <' . self::USERNAME . "> has no addressbooks\n", $commandTester->getDisplay());
72
+    }
73
+
74
+    public static function dataExecute(): array {
75
+        return [
76
+            [false, '✓'],
77
+            [true, 'x']
78
+        ];
79
+    }
80
+
81
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
82
+    public function testWithCorrectUser(bool $readOnly, string $output): void {
83
+        $this->userManager->expects($this->once())
84
+            ->method('userExists')
85
+            ->with(self::USERNAME)
86
+            ->willReturn(true);
87
+
88
+        $this->cardDavBackend->expects($this->once())
89
+            ->method('getAddressBooksForUser')
90
+            ->with('principals/users/' . self::USERNAME)
91
+            ->willReturn([
92
+                [
93
+                    '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $readOnly,
94
+                    'uri' => 'test',
95
+                    '{DAV:}displayname' => 'dp',
96
+                    '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => 'owner-principal',
97
+                    '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname' => 'owner-dp',
98
+                ]
99
+            ]);
100
+
101
+        $commandTester = new CommandTester($this->command);
102
+        $commandTester->execute([
103
+            'uid' => self::USERNAME,
104
+        ]);
105
+        $this->assertStringContainsString($output, $commandTester->getDisplay());
106
+    }
107 107
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Command/ListCalendarsTest.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -21,92 +21,92 @@
 block discarded – undo
21 21
  * @package OCA\DAV\Tests\Command
22 22
  */
23 23
 class ListCalendarsTest extends TestCase {
24
-	private IUserManager&MockObject $userManager;
25
-	private CalDavBackend&MockObject $calDav;
26
-	private ListCalendars $command;
27
-
28
-	public const USERNAME = 'username';
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->userManager = $this->createMock(IUserManager::class);
34
-		$this->calDav = $this->createMock(CalDavBackend::class);
35
-
36
-		$this->command = new ListCalendars(
37
-			$this->userManager,
38
-			$this->calDav
39
-		);
40
-	}
41
-
42
-	public function testWithBadUser(): void {
43
-		$this->expectException(\InvalidArgumentException::class);
44
-
45
-		$this->userManager->expects($this->once())
46
-			->method('userExists')
47
-			->with(self::USERNAME)
48
-			->willReturn(false);
49
-
50
-		$commandTester = new CommandTester($this->command);
51
-		$commandTester->execute([
52
-			'uid' => self::USERNAME,
53
-		]);
54
-		$this->assertStringContainsString('User <' . self::USERNAME . '> in unknown', $commandTester->getDisplay());
55
-	}
56
-
57
-	public function testWithCorrectUserWithNoCalendars(): void {
58
-		$this->userManager->expects($this->once())
59
-			->method('userExists')
60
-			->with(self::USERNAME)
61
-			->willReturn(true);
62
-
63
-		$this->calDav->expects($this->once())
64
-			->method('getCalendarsForUser')
65
-			->with('principals/users/' . self::USERNAME)
66
-			->willReturn([]);
67
-
68
-		$commandTester = new CommandTester($this->command);
69
-		$commandTester->execute([
70
-			'uid' => self::USERNAME,
71
-		]);
72
-		$this->assertStringContainsString('User <' . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay());
73
-	}
74
-
75
-	public static function dataExecute(): array {
76
-		return [
77
-			[false, '✓'],
78
-			[true, 'x']
79
-		];
80
-	}
81
-
82
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
83
-	public function testWithCorrectUser(bool $readOnly, string $output): void {
84
-		$this->userManager->expects($this->once())
85
-			->method('userExists')
86
-			->with(self::USERNAME)
87
-			->willReturn(true);
88
-
89
-		$this->calDav->expects($this->once())
90
-			->method('getCalendarsForUser')
91
-			->with('principals/users/' . self::USERNAME)
92
-			->willReturn([
93
-				[
94
-					'uri' => BirthdayService::BIRTHDAY_CALENDAR_URI,
95
-				],
96
-				[
97
-					'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $readOnly,
98
-					'uri' => 'test',
99
-					'{DAV:}displayname' => 'dp',
100
-					'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => 'owner-principal',
101
-					'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname' => 'owner-dp',
102
-				]
103
-			]);
104
-
105
-		$commandTester = new CommandTester($this->command);
106
-		$commandTester->execute([
107
-			'uid' => self::USERNAME,
108
-		]);
109
-		$this->assertStringContainsString($output, $commandTester->getDisplay());
110
-		$this->assertStringNotContainsString(BirthdayService::BIRTHDAY_CALENDAR_URI, $commandTester->getDisplay());
111
-	}
24
+    private IUserManager&MockObject $userManager;
25
+    private CalDavBackend&MockObject $calDav;
26
+    private ListCalendars $command;
27
+
28
+    public const USERNAME = 'username';
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->userManager = $this->createMock(IUserManager::class);
34
+        $this->calDav = $this->createMock(CalDavBackend::class);
35
+
36
+        $this->command = new ListCalendars(
37
+            $this->userManager,
38
+            $this->calDav
39
+        );
40
+    }
41
+
42
+    public function testWithBadUser(): void {
43
+        $this->expectException(\InvalidArgumentException::class);
44
+
45
+        $this->userManager->expects($this->once())
46
+            ->method('userExists')
47
+            ->with(self::USERNAME)
48
+            ->willReturn(false);
49
+
50
+        $commandTester = new CommandTester($this->command);
51
+        $commandTester->execute([
52
+            'uid' => self::USERNAME,
53
+        ]);
54
+        $this->assertStringContainsString('User <' . self::USERNAME . '> in unknown', $commandTester->getDisplay());
55
+    }
56
+
57
+    public function testWithCorrectUserWithNoCalendars(): void {
58
+        $this->userManager->expects($this->once())
59
+            ->method('userExists')
60
+            ->with(self::USERNAME)
61
+            ->willReturn(true);
62
+
63
+        $this->calDav->expects($this->once())
64
+            ->method('getCalendarsForUser')
65
+            ->with('principals/users/' . self::USERNAME)
66
+            ->willReturn([]);
67
+
68
+        $commandTester = new CommandTester($this->command);
69
+        $commandTester->execute([
70
+            'uid' => self::USERNAME,
71
+        ]);
72
+        $this->assertStringContainsString('User <' . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay());
73
+    }
74
+
75
+    public static function dataExecute(): array {
76
+        return [
77
+            [false, '✓'],
78
+            [true, 'x']
79
+        ];
80
+    }
81
+
82
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
83
+    public function testWithCorrectUser(bool $readOnly, string $output): void {
84
+        $this->userManager->expects($this->once())
85
+            ->method('userExists')
86
+            ->with(self::USERNAME)
87
+            ->willReturn(true);
88
+
89
+        $this->calDav->expects($this->once())
90
+            ->method('getCalendarsForUser')
91
+            ->with('principals/users/' . self::USERNAME)
92
+            ->willReturn([
93
+                [
94
+                    'uri' => BirthdayService::BIRTHDAY_CALENDAR_URI,
95
+                ],
96
+                [
97
+                    '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $readOnly,
98
+                    'uri' => 'test',
99
+                    '{DAV:}displayname' => 'dp',
100
+                    '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => 'owner-principal',
101
+                    '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname' => 'owner-dp',
102
+                ]
103
+            ]);
104
+
105
+        $commandTester = new CommandTester($this->command);
106
+        $commandTester->execute([
107
+            'uid' => self::USERNAME,
108
+        ]);
109
+        $this->assertStringContainsString($output, $commandTester->getDisplay());
110
+        $this->assertStringNotContainsString(BirthdayService::BIRTHDAY_CALENDAR_URI, $commandTester->getDisplay());
111
+    }
112 112
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Command/MoveCalendarTest.php 1 patch
Indentation   +325 added lines, -325 removed lines patch added patch discarded remove patch
@@ -26,329 +26,329 @@
 block discarded – undo
26 26
  * @package OCA\DAV\Tests\Command
27 27
  */
28 28
 class MoveCalendarTest extends TestCase {
29
-	private IUserManager&MockObject $userManager;
30
-	private IGroupManager&MockObject $groupManager;
31
-	private \OCP\Share\IManager&MockObject $shareManager;
32
-	private IConfig&MockObject $config;
33
-	private IL10N&MockObject $l10n;
34
-	private CalDavBackend&MockObject $calDav;
35
-	private LoggerInterface&MockObject $logger;
36
-	private MoveCalendar $command;
37
-
38
-	protected function setUp(): void {
39
-		parent::setUp();
40
-
41
-		$this->userManager = $this->createMock(IUserManager::class);
42
-		$this->groupManager = $this->createMock(IGroupManager::class);
43
-		$this->shareManager = $this->createMock(IManager::class);
44
-		$this->config = $this->createMock(IConfig::class);
45
-		$this->l10n = $this->createMock(IL10N::class);
46
-		$this->calDav = $this->createMock(CalDavBackend::class);
47
-		$this->logger = $this->createMock(LoggerInterface::class);
48
-
49
-		$this->command = new MoveCalendar(
50
-			$this->userManager,
51
-			$this->groupManager,
52
-			$this->shareManager,
53
-			$this->config,
54
-			$this->l10n,
55
-			$this->calDav,
56
-			$this->logger
57
-		);
58
-	}
59
-
60
-	public static function dataExecute(): array {
61
-		return [
62
-			[false, true],
63
-			[true, false]
64
-		];
65
-	}
66
-
67
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
68
-	public function testWithBadUserOrigin(bool $userOriginExists, bool $userDestinationExists): void {
69
-		$this->expectException(\InvalidArgumentException::class);
70
-
71
-		$this->userManager->expects($this->exactly($userOriginExists ? 2 : 1))
72
-			->method('userExists')
73
-			->willReturnMap([
74
-				['user', $userOriginExists],
75
-				['user2', $userDestinationExists],
76
-			]);
77
-
78
-		$commandTester = new CommandTester($this->command);
79
-		$commandTester->execute([
80
-			'name' => $this->command->getName(),
81
-			'sourceuid' => 'user',
82
-			'destinationuid' => 'user2',
83
-		]);
84
-	}
85
-
86
-
87
-	public function testMoveWithInexistantCalendar(): void {
88
-		$this->expectException(\InvalidArgumentException::class);
89
-		$this->expectExceptionMessage('User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user.');
90
-
91
-		$this->userManager->expects($this->exactly(2))
92
-			->method('userExists')
93
-			->willReturnMap([
94
-				['user', true],
95
-				['user2', true],
96
-			]);
97
-
98
-		$this->calDav->expects($this->once())->method('getCalendarByUri')
99
-			->with('principals/users/user', 'personal')
100
-			->willReturn(null);
101
-
102
-		$commandTester = new CommandTester($this->command);
103
-		$commandTester->execute([
104
-			'name' => 'personal',
105
-			'sourceuid' => 'user',
106
-			'destinationuid' => 'user2',
107
-		]);
108
-	}
109
-
110
-
111
-	public function testMoveWithExistingDestinationCalendar(): void {
112
-		$this->expectException(\InvalidArgumentException::class);
113
-		$this->expectExceptionMessage('User <user2> already has a calendar named <personal>.');
114
-
115
-		$this->userManager->expects($this->exactly(2))
116
-			->method('userExists')
117
-			->willReturnMap([
118
-				['user', true],
119
-				['user2', true],
120
-			]);
121
-
122
-		$this->calDav->expects($this->exactly(2))
123
-			->method('getCalendarByUri')
124
-			->willReturnMap([
125
-				['principals/users/user', 'personal', [
126
-					'id' => 1234,
127
-				]],
128
-				['principals/users/user2', 'personal', [
129
-					'id' => 1234,
130
-				]],
131
-			]);
132
-
133
-		$commandTester = new CommandTester($this->command);
134
-		$commandTester->execute([
135
-			'name' => 'personal',
136
-			'sourceuid' => 'user',
137
-			'destinationuid' => 'user2',
138
-		]);
139
-	}
140
-
141
-	public function testMove(): void {
142
-		$this->userManager->expects($this->exactly(2))
143
-			->method('userExists')
144
-			->willReturnMap([
145
-				['user', true],
146
-				['user2', true],
147
-			]);
148
-
149
-		$this->calDav->expects($this->exactly(2))
150
-			->method('getCalendarByUri')
151
-			->willReturnMap([
152
-				['principals/users/user', 'personal', [
153
-					'id' => 1234,
154
-				]],
155
-				['principals/users/user2', 'personal', null],
156
-			]);
157
-
158
-		$this->calDav->expects($this->once())->method('getShares')
159
-			->with(1234)
160
-			->willReturn([]);
161
-
162
-		$commandTester = new CommandTester($this->command);
163
-		$commandTester->execute([
164
-			'name' => 'personal',
165
-			'sourceuid' => 'user',
166
-			'destinationuid' => 'user2',
167
-		]);
168
-
169
-		$this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
170
-	}
171
-
172
-	public static function dataTestMoveWithDestinationNotPartOfGroup(): array {
173
-		return [
174
-			[true],
175
-			[false]
176
-		];
177
-	}
178
-
179
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataTestMoveWithDestinationNotPartOfGroup')]
180
-	public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly): void {
181
-		$this->userManager->expects($this->exactly(2))
182
-			->method('userExists')
183
-			->willReturnMap([
184
-				['user', true],
185
-				['user2', true],
186
-			]);
187
-
188
-		$this->calDav->expects($this->exactly(2))
189
-			->method('getCalendarByUri')
190
-			->willReturnMap([
191
-				['principals/users/user', 'personal', [
192
-					'id' => 1234,
193
-					'uri' => 'personal',
194
-				]],
195
-				['principals/users/user2', 'personal', null],
196
-			]);
197
-
198
-		$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
199
-			->willReturn($shareWithGroupMembersOnly);
200
-
201
-		$this->calDav->expects($this->once())->method('getShares')
202
-			->with(1234)
203
-			->willReturn([
204
-				['href' => 'principal:principals/groups/nextclouders']
205
-			]);
206
-		if ($shareWithGroupMembersOnly === true) {
207
-			$this->expectException(InvalidArgumentException::class);
208
-			$this->expectExceptionMessage('User <user2> is not part of the group <nextclouders> with whom the calendar <personal> was shared. You may use -f to move the calendar while deleting this share.');
209
-		}
210
-
211
-		$commandTester = new CommandTester($this->command);
212
-		$commandTester->execute([
213
-			'name' => 'personal',
214
-			'sourceuid' => 'user',
215
-			'destinationuid' => 'user2',
216
-		]);
217
-	}
218
-
219
-	public function testMoveWithDestinationPartOfGroup(): void {
220
-		$this->userManager->expects($this->exactly(2))
221
-			->method('userExists')
222
-			->willReturnMap([
223
-				['user', true],
224
-				['user2', true],
225
-			]);
226
-
227
-		$this->calDav->expects($this->exactly(2))
228
-			->method('getCalendarByUri')
229
-			->willReturnMap([
230
-				['principals/users/user', 'personal', [
231
-					'id' => 1234,
232
-					'uri' => 'personal',
233
-				]],
234
-				['principals/users/user2', 'personal', null],
235
-			]);
236
-
237
-		$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
238
-			->willReturn(true);
239
-
240
-		$this->calDav->expects($this->once())->method('getShares')
241
-			->with(1234)
242
-			->willReturn([
243
-				['href' => 'principal:principals/groups/nextclouders']
244
-			]);
245
-
246
-		$this->groupManager->expects($this->once())->method('isInGroup')
247
-			->with('user2', 'nextclouders')
248
-			->willReturn(true);
249
-
250
-		$commandTester = new CommandTester($this->command);
251
-		$commandTester->execute([
252
-			'name' => 'personal',
253
-			'sourceuid' => 'user',
254
-			'destinationuid' => 'user2',
255
-		]);
256
-
257
-		$this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
258
-	}
259
-
260
-	public function testMoveWithDestinationNotPartOfGroupAndForce(): void {
261
-		$this->userManager->expects($this->exactly(2))
262
-			->method('userExists')
263
-			->willReturnMap([
264
-				['user', true],
265
-				['user2', true],
266
-			]);
267
-
268
-		$this->calDav->expects($this->exactly(2))
269
-			->method('getCalendarByUri')
270
-			->willReturnMap([
271
-				['principals/users/user', 'personal', [
272
-					'id' => 1234,
273
-					'uri' => 'personal',
274
-					'{DAV:}displayname' => 'Personal'
275
-				]],
276
-				['principals/users/user2', 'personal', null],
277
-			]);
278
-
279
-		$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
280
-			->willReturn(true);
281
-
282
-		$this->calDav->expects($this->once())->method('getShares')
283
-			->with(1234)
284
-			->willReturn([
285
-				[
286
-					'href' => 'principal:principals/groups/nextclouders',
287
-					'{DAV:}displayname' => 'Personal'
288
-				]
289
-			]);
290
-		$this->calDav->expects($this->once())->method('updateShares');
291
-
292
-		$commandTester = new CommandTester($this->command);
293
-		$commandTester->execute([
294
-			'name' => 'personal',
295
-			'sourceuid' => 'user',
296
-			'destinationuid' => 'user2',
297
-			'--force' => true
298
-		]);
299
-
300
-		$this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
301
-	}
302
-
303
-	public static function dataTestMoveWithCalendarAlreadySharedToDestination(): array {
304
-		return [
305
-			[true],
306
-			[false]
307
-		];
308
-	}
309
-
310
-	#[\PHPUnit\Framework\Attributes\DataProvider('dataTestMoveWithCalendarAlreadySharedToDestination')]
311
-	public function testMoveWithCalendarAlreadySharedToDestination(bool $force): void {
312
-		$this->userManager->expects($this->exactly(2))
313
-			->method('userExists')
314
-			->willReturnMap([
315
-				['user', true],
316
-				['user2', true],
317
-			]);
318
-
319
-		$this->calDav->expects($this->exactly(2))
320
-			->method('getCalendarByUri')
321
-			->willReturnMap([
322
-				['principals/users/user', 'personal', [
323
-					'id' => 1234,
324
-					'uri' => 'personal',
325
-					'{DAV:}displayname' => 'Personal'
326
-				]],
327
-				['principals/users/user2', 'personal', null],
328
-			]);
329
-
330
-		$this->calDav->expects($this->once())->method('getShares')
331
-			->with(1234)
332
-			->willReturn([
333
-				[
334
-					'href' => 'principal:principals/users/user2',
335
-					'{DAV:}displayname' => 'Personal'
336
-				]
337
-			]);
338
-
339
-		if ($force === false) {
340
-			$this->expectException(InvalidArgumentException::class);
341
-			$this->expectExceptionMessage('The calendar <personal> is already shared to user <user2>.You may use -f to move the calendar while deleting this share.');
342
-		} else {
343
-			$this->calDav->expects($this->once())->method('updateShares');
344
-		}
345
-
346
-		$commandTester = new CommandTester($this->command);
347
-		$commandTester->execute([
348
-			'name' => 'personal',
349
-			'sourceuid' => 'user',
350
-			'destinationuid' => 'user2',
351
-			'--force' => $force,
352
-		]);
353
-	}
29
+    private IUserManager&MockObject $userManager;
30
+    private IGroupManager&MockObject $groupManager;
31
+    private \OCP\Share\IManager&MockObject $shareManager;
32
+    private IConfig&MockObject $config;
33
+    private IL10N&MockObject $l10n;
34
+    private CalDavBackend&MockObject $calDav;
35
+    private LoggerInterface&MockObject $logger;
36
+    private MoveCalendar $command;
37
+
38
+    protected function setUp(): void {
39
+        parent::setUp();
40
+
41
+        $this->userManager = $this->createMock(IUserManager::class);
42
+        $this->groupManager = $this->createMock(IGroupManager::class);
43
+        $this->shareManager = $this->createMock(IManager::class);
44
+        $this->config = $this->createMock(IConfig::class);
45
+        $this->l10n = $this->createMock(IL10N::class);
46
+        $this->calDav = $this->createMock(CalDavBackend::class);
47
+        $this->logger = $this->createMock(LoggerInterface::class);
48
+
49
+        $this->command = new MoveCalendar(
50
+            $this->userManager,
51
+            $this->groupManager,
52
+            $this->shareManager,
53
+            $this->config,
54
+            $this->l10n,
55
+            $this->calDav,
56
+            $this->logger
57
+        );
58
+    }
59
+
60
+    public static function dataExecute(): array {
61
+        return [
62
+            [false, true],
63
+            [true, false]
64
+        ];
65
+    }
66
+
67
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
68
+    public function testWithBadUserOrigin(bool $userOriginExists, bool $userDestinationExists): void {
69
+        $this->expectException(\InvalidArgumentException::class);
70
+
71
+        $this->userManager->expects($this->exactly($userOriginExists ? 2 : 1))
72
+            ->method('userExists')
73
+            ->willReturnMap([
74
+                ['user', $userOriginExists],
75
+                ['user2', $userDestinationExists],
76
+            ]);
77
+
78
+        $commandTester = new CommandTester($this->command);
79
+        $commandTester->execute([
80
+            'name' => $this->command->getName(),
81
+            'sourceuid' => 'user',
82
+            'destinationuid' => 'user2',
83
+        ]);
84
+    }
85
+
86
+
87
+    public function testMoveWithInexistantCalendar(): void {
88
+        $this->expectException(\InvalidArgumentException::class);
89
+        $this->expectExceptionMessage('User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user.');
90
+
91
+        $this->userManager->expects($this->exactly(2))
92
+            ->method('userExists')
93
+            ->willReturnMap([
94
+                ['user', true],
95
+                ['user2', true],
96
+            ]);
97
+
98
+        $this->calDav->expects($this->once())->method('getCalendarByUri')
99
+            ->with('principals/users/user', 'personal')
100
+            ->willReturn(null);
101
+
102
+        $commandTester = new CommandTester($this->command);
103
+        $commandTester->execute([
104
+            'name' => 'personal',
105
+            'sourceuid' => 'user',
106
+            'destinationuid' => 'user2',
107
+        ]);
108
+    }
109
+
110
+
111
+    public function testMoveWithExistingDestinationCalendar(): void {
112
+        $this->expectException(\InvalidArgumentException::class);
113
+        $this->expectExceptionMessage('User <user2> already has a calendar named <personal>.');
114
+
115
+        $this->userManager->expects($this->exactly(2))
116
+            ->method('userExists')
117
+            ->willReturnMap([
118
+                ['user', true],
119
+                ['user2', true],
120
+            ]);
121
+
122
+        $this->calDav->expects($this->exactly(2))
123
+            ->method('getCalendarByUri')
124
+            ->willReturnMap([
125
+                ['principals/users/user', 'personal', [
126
+                    'id' => 1234,
127
+                ]],
128
+                ['principals/users/user2', 'personal', [
129
+                    'id' => 1234,
130
+                ]],
131
+            ]);
132
+
133
+        $commandTester = new CommandTester($this->command);
134
+        $commandTester->execute([
135
+            'name' => 'personal',
136
+            'sourceuid' => 'user',
137
+            'destinationuid' => 'user2',
138
+        ]);
139
+    }
140
+
141
+    public function testMove(): void {
142
+        $this->userManager->expects($this->exactly(2))
143
+            ->method('userExists')
144
+            ->willReturnMap([
145
+                ['user', true],
146
+                ['user2', true],
147
+            ]);
148
+
149
+        $this->calDav->expects($this->exactly(2))
150
+            ->method('getCalendarByUri')
151
+            ->willReturnMap([
152
+                ['principals/users/user', 'personal', [
153
+                    'id' => 1234,
154
+                ]],
155
+                ['principals/users/user2', 'personal', null],
156
+            ]);
157
+
158
+        $this->calDav->expects($this->once())->method('getShares')
159
+            ->with(1234)
160
+            ->willReturn([]);
161
+
162
+        $commandTester = new CommandTester($this->command);
163
+        $commandTester->execute([
164
+            'name' => 'personal',
165
+            'sourceuid' => 'user',
166
+            'destinationuid' => 'user2',
167
+        ]);
168
+
169
+        $this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
170
+    }
171
+
172
+    public static function dataTestMoveWithDestinationNotPartOfGroup(): array {
173
+        return [
174
+            [true],
175
+            [false]
176
+        ];
177
+    }
178
+
179
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataTestMoveWithDestinationNotPartOfGroup')]
180
+    public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly): void {
181
+        $this->userManager->expects($this->exactly(2))
182
+            ->method('userExists')
183
+            ->willReturnMap([
184
+                ['user', true],
185
+                ['user2', true],
186
+            ]);
187
+
188
+        $this->calDav->expects($this->exactly(2))
189
+            ->method('getCalendarByUri')
190
+            ->willReturnMap([
191
+                ['principals/users/user', 'personal', [
192
+                    'id' => 1234,
193
+                    'uri' => 'personal',
194
+                ]],
195
+                ['principals/users/user2', 'personal', null],
196
+            ]);
197
+
198
+        $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
199
+            ->willReturn($shareWithGroupMembersOnly);
200
+
201
+        $this->calDav->expects($this->once())->method('getShares')
202
+            ->with(1234)
203
+            ->willReturn([
204
+                ['href' => 'principal:principals/groups/nextclouders']
205
+            ]);
206
+        if ($shareWithGroupMembersOnly === true) {
207
+            $this->expectException(InvalidArgumentException::class);
208
+            $this->expectExceptionMessage('User <user2> is not part of the group <nextclouders> with whom the calendar <personal> was shared. You may use -f to move the calendar while deleting this share.');
209
+        }
210
+
211
+        $commandTester = new CommandTester($this->command);
212
+        $commandTester->execute([
213
+            'name' => 'personal',
214
+            'sourceuid' => 'user',
215
+            'destinationuid' => 'user2',
216
+        ]);
217
+    }
218
+
219
+    public function testMoveWithDestinationPartOfGroup(): void {
220
+        $this->userManager->expects($this->exactly(2))
221
+            ->method('userExists')
222
+            ->willReturnMap([
223
+                ['user', true],
224
+                ['user2', true],
225
+            ]);
226
+
227
+        $this->calDav->expects($this->exactly(2))
228
+            ->method('getCalendarByUri')
229
+            ->willReturnMap([
230
+                ['principals/users/user', 'personal', [
231
+                    'id' => 1234,
232
+                    'uri' => 'personal',
233
+                ]],
234
+                ['principals/users/user2', 'personal', null],
235
+            ]);
236
+
237
+        $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
238
+            ->willReturn(true);
239
+
240
+        $this->calDav->expects($this->once())->method('getShares')
241
+            ->with(1234)
242
+            ->willReturn([
243
+                ['href' => 'principal:principals/groups/nextclouders']
244
+            ]);
245
+
246
+        $this->groupManager->expects($this->once())->method('isInGroup')
247
+            ->with('user2', 'nextclouders')
248
+            ->willReturn(true);
249
+
250
+        $commandTester = new CommandTester($this->command);
251
+        $commandTester->execute([
252
+            'name' => 'personal',
253
+            'sourceuid' => 'user',
254
+            'destinationuid' => 'user2',
255
+        ]);
256
+
257
+        $this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
258
+    }
259
+
260
+    public function testMoveWithDestinationNotPartOfGroupAndForce(): void {
261
+        $this->userManager->expects($this->exactly(2))
262
+            ->method('userExists')
263
+            ->willReturnMap([
264
+                ['user', true],
265
+                ['user2', true],
266
+            ]);
267
+
268
+        $this->calDav->expects($this->exactly(2))
269
+            ->method('getCalendarByUri')
270
+            ->willReturnMap([
271
+                ['principals/users/user', 'personal', [
272
+                    'id' => 1234,
273
+                    'uri' => 'personal',
274
+                    '{DAV:}displayname' => 'Personal'
275
+                ]],
276
+                ['principals/users/user2', 'personal', null],
277
+            ]);
278
+
279
+        $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
280
+            ->willReturn(true);
281
+
282
+        $this->calDav->expects($this->once())->method('getShares')
283
+            ->with(1234)
284
+            ->willReturn([
285
+                [
286
+                    'href' => 'principal:principals/groups/nextclouders',
287
+                    '{DAV:}displayname' => 'Personal'
288
+                ]
289
+            ]);
290
+        $this->calDav->expects($this->once())->method('updateShares');
291
+
292
+        $commandTester = new CommandTester($this->command);
293
+        $commandTester->execute([
294
+            'name' => 'personal',
295
+            'sourceuid' => 'user',
296
+            'destinationuid' => 'user2',
297
+            '--force' => true
298
+        ]);
299
+
300
+        $this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
301
+    }
302
+
303
+    public static function dataTestMoveWithCalendarAlreadySharedToDestination(): array {
304
+        return [
305
+            [true],
306
+            [false]
307
+        ];
308
+    }
309
+
310
+    #[\PHPUnit\Framework\Attributes\DataProvider('dataTestMoveWithCalendarAlreadySharedToDestination')]
311
+    public function testMoveWithCalendarAlreadySharedToDestination(bool $force): void {
312
+        $this->userManager->expects($this->exactly(2))
313
+            ->method('userExists')
314
+            ->willReturnMap([
315
+                ['user', true],
316
+                ['user2', true],
317
+            ]);
318
+
319
+        $this->calDav->expects($this->exactly(2))
320
+            ->method('getCalendarByUri')
321
+            ->willReturnMap([
322
+                ['principals/users/user', 'personal', [
323
+                    'id' => 1234,
324
+                    'uri' => 'personal',
325
+                    '{DAV:}displayname' => 'Personal'
326
+                ]],
327
+                ['principals/users/user2', 'personal', null],
328
+            ]);
329
+
330
+        $this->calDav->expects($this->once())->method('getShares')
331
+            ->with(1234)
332
+            ->willReturn([
333
+                [
334
+                    'href' => 'principal:principals/users/user2',
335
+                    '{DAV:}displayname' => 'Personal'
336
+                ]
337
+            ]);
338
+
339
+        if ($force === false) {
340
+            $this->expectException(InvalidArgumentException::class);
341
+            $this->expectExceptionMessage('The calendar <personal> is already shared to user <user2>.You may use -f to move the calendar while deleting this share.');
342
+        } else {
343
+            $this->calDav->expects($this->once())->method('updateShares');
344
+        }
345
+
346
+        $commandTester = new CommandTester($this->command);
347
+        $commandTester->execute([
348
+            'name' => 'personal',
349
+            'sourceuid' => 'user',
350
+            'destinationuid' => 'user2',
351
+            '--force' => $force,
352
+        ]);
353
+    }
354 354
 }
Please login to merge, or discard this patch.
apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningPluginTest.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -21,145 +21,145 @@  discard block
 block discarded – undo
21 21
 use Test\TestCase;
22 22
 
23 23
 class AppleProvisioningPluginTest extends TestCase {
24
-	protected Server&MockObject $server;
25
-	protected IUserSession&MockObject $userSession;
26
-	protected IURLGenerator&MockObject $urlGenerator;
27
-	protected ThemingDefaults&MockObject $themingDefaults;
28
-	protected IRequest&MockObject $request;
29
-	protected IL10N&MockObject $l10n;
30
-	protected RequestInterface&MockObject $sabreRequest;
31
-	protected ResponseInterface&MockObject $sabreResponse;
32
-	protected AppleProvisioningPlugin $plugin;
33
-
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-
37
-		$this->server = $this->createMock(Server::class);
38
-		$this->userSession = $this->createMock(IUserSession::class);
39
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
40
-		$this->themingDefaults = $this->createMock(ThemingDefaults::class);
41
-		$this->request = $this->createMock(IRequest::class);
42
-		$this->l10n = $this->createMock(IL10N::class);
43
-
44
-		$this->plugin = new AppleProvisioningPlugin($this->userSession,
45
-			$this->urlGenerator,
46
-			$this->themingDefaults,
47
-			$this->request,
48
-			$this->l10n,
49
-			function () {
50
-				return 'generated-uuid';
51
-			}
52
-		);
53
-
54
-		$this->sabreRequest = $this->createMock(RequestInterface::class);
55
-		$this->sabreResponse = $this->createMock(ResponseInterface::class);
56
-	}
57
-
58
-	public function testInitialize(): void {
59
-		$server = $this->createMock(Server::class);
60
-
61
-		$plugin = new AppleProvisioningPlugin($this->userSession,
62
-			$this->urlGenerator, $this->themingDefaults, $this->request, $this->l10n,
63
-			function (): void {
64
-			});
65
-
66
-		$server->expects($this->once())
67
-			->method('on')
68
-			->with('method:GET', [$plugin, 'httpGet'], 90);
69
-
70
-		$plugin->initialize($server);
71
-	}
72
-
73
-	public function testHttpGetOnHttp(): void {
74
-		$this->sabreRequest->expects($this->once())
75
-			->method('getPath')
76
-			->with()
77
-			->willReturn('provisioning/apple-provisioning.mobileconfig');
78
-
79
-		$user = $this->createMock(IUser::class);
80
-		$this->userSession->expects($this->once())
81
-			->method('getUser')
82
-			->willReturn($user);
83
-
84
-		$this->request->expects($this->once())
85
-			->method('getServerProtocol')
86
-			->wilLReturn('http');
87
-
88
-		$this->themingDefaults->expects($this->once())
89
-			->method('getName')
90
-			->willReturn('InstanceName');
91
-
92
-		$this->l10n->expects($this->once())
93
-			->method('t')
94
-			->with('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', ['InstanceName'])
95
-			->willReturn('LocalizedErrorMessage');
96
-
97
-		$this->sabreResponse->expects($this->once())
98
-			->method('setStatus')
99
-			->with(200);
100
-		$this->sabreResponse->expects($this->once())
101
-			->method('setHeader')
102
-			->with('Content-Type', 'text/plain; charset=utf-8');
103
-		$this->sabreResponse->expects($this->once())
104
-			->method('setBody')
105
-			->with('LocalizedErrorMessage');
106
-
107
-		$returnValue = $this->plugin->httpGet($this->sabreRequest, $this->sabreResponse);
108
-
109
-		$this->assertFalse($returnValue);
110
-	}
111
-
112
-	public function testHttpGetOnHttps(): void {
113
-		$this->sabreRequest->expects($this->once())
114
-			->method('getPath')
115
-			->with()
116
-			->willReturn('provisioning/apple-provisioning.mobileconfig');
117
-
118
-		$user = $this->createMock(IUser::class);
119
-		$user->expects($this->once())
120
-			->method('getUID')
121
-			->willReturn('userName');
122
-
123
-		$this->userSession->expects($this->once())
124
-			->method('getUser')
125
-			->willReturn($user);
126
-
127
-		$this->request->expects($this->once())
128
-			->method('getServerProtocol')
129
-			->wilLReturn('https');
130
-
131
-		$this->urlGenerator->expects($this->once())
132
-			->method('getBaseUrl')
133
-			->willReturn('https://nextcloud.tld/nextcloud');
134
-
135
-		$this->themingDefaults->expects($this->once())
136
-			->method('getName')
137
-			->willReturn('InstanceName');
138
-
139
-		$this->l10n->expects($this->exactly(2))
140
-			->method('t')
141
-			->willReturnMap([
142
-				['Configures a CalDAV account', [], 'LocalizedConfiguresCalDAV'],
143
-				['Configures a CardDAV account', [], 'LocalizedConfiguresCardDAV'],
144
-			]);
145
-
146
-		$this->sabreResponse->expects($this->once())
147
-			->method('setStatus')
148
-			->with(200);
149
-
150
-		$calls = [
151
-			['Content-Disposition', 'attachment; filename="userName-apple-provisioning.mobileconfig"'],
152
-			['Content-Type', 'application/xml; charset=utf-8'],
153
-		];
154
-		$this->sabreResponse->expects($this->exactly(2))
155
-			->method('setHeader')
156
-			->willReturnCallback(function () use (&$calls): void {
157
-				$expected = array_shift($calls);
158
-				$this->assertEquals($expected, func_get_args());
159
-			});
160
-		$this->sabreResponse->expects($this->once())
161
-			->method('setBody')
162
-			->with(<<<EOF
24
+    protected Server&MockObject $server;
25
+    protected IUserSession&MockObject $userSession;
26
+    protected IURLGenerator&MockObject $urlGenerator;
27
+    protected ThemingDefaults&MockObject $themingDefaults;
28
+    protected IRequest&MockObject $request;
29
+    protected IL10N&MockObject $l10n;
30
+    protected RequestInterface&MockObject $sabreRequest;
31
+    protected ResponseInterface&MockObject $sabreResponse;
32
+    protected AppleProvisioningPlugin $plugin;
33
+
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+
37
+        $this->server = $this->createMock(Server::class);
38
+        $this->userSession = $this->createMock(IUserSession::class);
39
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
40
+        $this->themingDefaults = $this->createMock(ThemingDefaults::class);
41
+        $this->request = $this->createMock(IRequest::class);
42
+        $this->l10n = $this->createMock(IL10N::class);
43
+
44
+        $this->plugin = new AppleProvisioningPlugin($this->userSession,
45
+            $this->urlGenerator,
46
+            $this->themingDefaults,
47
+            $this->request,
48
+            $this->l10n,
49
+            function () {
50
+                return 'generated-uuid';
51
+            }
52
+        );
53
+
54
+        $this->sabreRequest = $this->createMock(RequestInterface::class);
55
+        $this->sabreResponse = $this->createMock(ResponseInterface::class);
56
+    }
57
+
58
+    public function testInitialize(): void {
59
+        $server = $this->createMock(Server::class);
60
+
61
+        $plugin = new AppleProvisioningPlugin($this->userSession,
62
+            $this->urlGenerator, $this->themingDefaults, $this->request, $this->l10n,
63
+            function (): void {
64
+            });
65
+
66
+        $server->expects($this->once())
67
+            ->method('on')
68
+            ->with('method:GET', [$plugin, 'httpGet'], 90);
69
+
70
+        $plugin->initialize($server);
71
+    }
72
+
73
+    public function testHttpGetOnHttp(): void {
74
+        $this->sabreRequest->expects($this->once())
75
+            ->method('getPath')
76
+            ->with()
77
+            ->willReturn('provisioning/apple-provisioning.mobileconfig');
78
+
79
+        $user = $this->createMock(IUser::class);
80
+        $this->userSession->expects($this->once())
81
+            ->method('getUser')
82
+            ->willReturn($user);
83
+
84
+        $this->request->expects($this->once())
85
+            ->method('getServerProtocol')
86
+            ->wilLReturn('http');
87
+
88
+        $this->themingDefaults->expects($this->once())
89
+            ->method('getName')
90
+            ->willReturn('InstanceName');
91
+
92
+        $this->l10n->expects($this->once())
93
+            ->method('t')
94
+            ->with('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', ['InstanceName'])
95
+            ->willReturn('LocalizedErrorMessage');
96
+
97
+        $this->sabreResponse->expects($this->once())
98
+            ->method('setStatus')
99
+            ->with(200);
100
+        $this->sabreResponse->expects($this->once())
101
+            ->method('setHeader')
102
+            ->with('Content-Type', 'text/plain; charset=utf-8');
103
+        $this->sabreResponse->expects($this->once())
104
+            ->method('setBody')
105
+            ->with('LocalizedErrorMessage');
106
+
107
+        $returnValue = $this->plugin->httpGet($this->sabreRequest, $this->sabreResponse);
108
+
109
+        $this->assertFalse($returnValue);
110
+    }
111
+
112
+    public function testHttpGetOnHttps(): void {
113
+        $this->sabreRequest->expects($this->once())
114
+            ->method('getPath')
115
+            ->with()
116
+            ->willReturn('provisioning/apple-provisioning.mobileconfig');
117
+
118
+        $user = $this->createMock(IUser::class);
119
+        $user->expects($this->once())
120
+            ->method('getUID')
121
+            ->willReturn('userName');
122
+
123
+        $this->userSession->expects($this->once())
124
+            ->method('getUser')
125
+            ->willReturn($user);
126
+
127
+        $this->request->expects($this->once())
128
+            ->method('getServerProtocol')
129
+            ->wilLReturn('https');
130
+
131
+        $this->urlGenerator->expects($this->once())
132
+            ->method('getBaseUrl')
133
+            ->willReturn('https://nextcloud.tld/nextcloud');
134
+
135
+        $this->themingDefaults->expects($this->once())
136
+            ->method('getName')
137
+            ->willReturn('InstanceName');
138
+
139
+        $this->l10n->expects($this->exactly(2))
140
+            ->method('t')
141
+            ->willReturnMap([
142
+                ['Configures a CalDAV account', [], 'LocalizedConfiguresCalDAV'],
143
+                ['Configures a CardDAV account', [], 'LocalizedConfiguresCardDAV'],
144
+            ]);
145
+
146
+        $this->sabreResponse->expects($this->once())
147
+            ->method('setStatus')
148
+            ->with(200);
149
+
150
+        $calls = [
151
+            ['Content-Disposition', 'attachment; filename="userName-apple-provisioning.mobileconfig"'],
152
+            ['Content-Type', 'application/xml; charset=utf-8'],
153
+        ];
154
+        $this->sabreResponse->expects($this->exactly(2))
155
+            ->method('setHeader')
156
+            ->willReturnCallback(function () use (&$calls): void {
157
+                $expected = array_shift($calls);
158
+                $this->assertEquals($expected, func_get_args());
159
+            });
160
+        $this->sabreResponse->expects($this->once())
161
+            ->method('setBody')
162
+            ->with(<<<EOF
163 163
 <?xml version="1.0" encoding="UTF-8"?>
164 164
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
165 165
 <plist version="1.0">
@@ -231,10 +231,10 @@  discard block
 block discarded – undo
231 231
 </plist>
232 232
 
233 233
 EOF
234
-			);
234
+            );
235 235
 
236
-		$returnValue = $this->plugin->httpGet($this->sabreRequest, $this->sabreResponse);
236
+        $returnValue = $this->plugin->httpGet($this->sabreRequest, $this->sabreResponse);
237 237
 
238
-		$this->assertFalse($returnValue);
239
-	}
238
+        $this->assertFalse($returnValue);
239
+    }
240 240
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 			$this->themingDefaults,
47 47
 			$this->request,
48 48
 			$this->l10n,
49
-			function () {
49
+			function() {
50 50
 				return 'generated-uuid';
51 51
 			}
52 52
 		);
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
 		$plugin = new AppleProvisioningPlugin($this->userSession,
62 62
 			$this->urlGenerator, $this->themingDefaults, $this->request, $this->l10n,
63
-			function (): void {
63
+			function(): void {
64 64
 			});
65 65
 
66 66
 		$server->expects($this->once())
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 		];
154 154
 		$this->sabreResponse->expects($this->exactly(2))
155 155
 			->method('setHeader')
156
-			->willReturnCallback(function () use (&$calls): void {
156
+			->willReturnCallback(function() use (&$calls): void {
157 157
 				$expected = array_shift($calls);
158 158
 				$this->assertEquals($expected, func_get_args());
159 159
 			});
Please login to merge, or discard this patch.