-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathRemoveInvalidSharesTest.php
More file actions
144 lines (124 loc) · 4.01 KB
/
Copy pathRemoveInvalidSharesTest.php
File metadata and controls
144 lines (124 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2018 ownCloud GmbH
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\DAV\Tests\unit\Command;
use OCA\DAV\Command\RemoveInvalidShares;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\DAV\RemoteUserPrincipalBackend;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
/**
* Class RemoveInvalidSharesTest
*
* @package OCA\DAV\Tests\Unit\Repair
*/
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
class RemoveInvalidSharesTest extends TestCase {
private RemoveInvalidShares $command;
private IDBConnection $db;
private Principal&MockObject $principalBackend;
private RemoteUserPrincipalBackend&MockObject $remoteUserPrincipalBackend;
protected function setUp(): void {
parent::setUp();
$this->db = Server::get(IDBConnection::class);
$this->principalBackend = $this->createMock(Principal::class);
$this->remoteUserPrincipalBackend = $this->createMock(RemoteUserPrincipalBackend::class);
$this->db->insertIfNotExist('*PREFIX*dav_shares', [
'principaluri' => 'principal:unknown',
'type' => 'calendar',
'access' => 2,
'resourceid' => 666,
]);
$this->db->insertIfNotExist('*PREFIX*dav_shares', [
'principaluri' => 'principals/remote-users/foobar',
'type' => 'calendar',
'access' => 2,
'resourceid' => 666,
]);
$this->command = new RemoveInvalidShares(
$this->db,
$this->principalBackend,
$this->remoteUserPrincipalBackend,
);
}
private function selectShares(): array {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('dav_shares')
->where($query->expr()->in(
'principaluri',
$query->createNamedParameter(
['principal:unknown', 'principals/remote-users/foobar'],
IQueryBuilder::PARAM_STR_ARRAY,
),
));
$result = $query->executeQuery();
$data = $result->fetchAllAssociative();
$result->closeCursor();
return $data;
}
public function testWithoutPrincipals(): void {
$this->principalBackend->method('getPrincipalByPath')
->willReturnMap([
['principal:unknown', null],
['principals/remote-users/foobar', null],
]);
$this->remoteUserPrincipalBackend->method('getPrincipalByPath')
->willReturnMap([
['principal:unknown', null],
['principals/remote-users/foobar', null],
]);
$this->command->run(
$this->createMock(InputInterface::class),
$this->createMock(OutputInterface::class),
);
$data = $this->selectShares();
$this->assertCount(0, $data);
}
public function testWithLocalPrincipal(): void {
$this->principalBackend->method('getPrincipalByPath')
->willReturnMap([
['principal:unknown', ['uri' => 'principal:unknown']],
['principals/remote-users/foobar', null],
]);
$this->remoteUserPrincipalBackend->method('getPrincipalByPath')
->willReturnMap([
['principals/remote-users/foobar', null],
]);
$this->command->run(
$this->createMock(InputInterface::class),
$this->createMock(OutputInterface::class),
);
$data = $this->selectShares();
$this->assertCount(1, $data);
$this->assertEquals('principal:unknown', $data[0]['principaluri']);
}
public function testWithRemotePrincipal() {
$this->principalBackend->method('getPrincipalByPath')
->willReturnMap([
['principal:unknown', null],
['principals/remote-users/foobar', null],
]);
$this->remoteUserPrincipalBackend->method('getPrincipalByPath')
->willReturnMap([
['principal:unknown', null],
['principals/remote-users/foobar', ['uri' => 'principals/remote-users/foobar']],
]);
$this->command->run(
$this->createMock(InputInterface::class),
$this->createMock(OutputInterface::class),
);
$data = $this->selectShares();
$this->assertCount(1, $data);
$this->assertEquals('principals/remote-users/foobar', $data[0]['principaluri']);
}
}