|
11 | 11 | use OCA\Files_Sharing\ExpireSharesJob; |
12 | 12 | use OCP\AppFramework\Utility\ITimeFactory; |
13 | 13 | use OCP\Constants; |
| 14 | +use OCP\Files\IRootFolder; |
14 | 15 | use OCP\IDBConnection; |
| 16 | +use OCP\IUser; |
15 | 17 | use OCP\IUserManager; |
16 | 18 | use OCP\Server; |
17 | 19 | use OCP\Share\IManager; |
18 | 20 | use OCP\Share\IShare; |
| 21 | +use PHPUnit\Framework\Attributes\DataProvider; |
19 | 22 |
|
20 | 23 | /** |
21 | 24 | * Class ExpireSharesJobTest |
|
26 | 29 | */ |
27 | 30 | class ExpireSharesJobTest extends \Test\TestCase { |
28 | 31 |
|
29 | | - /** @var ExpireSharesJob */ |
30 | | - private $job; |
| 32 | + private ExpireSharesJob $job; |
31 | 33 |
|
32 | | - /** @var IDBConnection */ |
33 | | - private $connection; |
| 34 | + private IDBConnection $connection; |
| 35 | + private IRootFolder $rootFolder; |
34 | 36 |
|
35 | | - /** @var string */ |
36 | | - private $user1; |
| 37 | + private IUser $user1; |
37 | 38 |
|
38 | | - /** @var string */ |
39 | | - private $user2; |
| 39 | + private IUser $user2; |
40 | 40 |
|
41 | 41 | protected function setUp(): void { |
42 | 42 | parent::setUp(); |
43 | 43 |
|
44 | 44 | $this->connection = Server::get(IDBConnection::class); |
| 45 | + $this->rootFolder = Server::get(IRootFolder::class); |
45 | 46 | // clear occasional leftover shares from other tests |
46 | | - $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`'); |
| 47 | + $this->connection->getQueryBuilder()->delete('share')->executeStatement(); |
47 | 48 |
|
48 | | - $this->user1 = $this->getUniqueID('user1_'); |
49 | | - $this->user2 = $this->getUniqueID('user2_'); |
| 49 | + $user1 = $this->getUniqueID('user1_'); |
| 50 | + $user2 = $this->getUniqueID('user2_'); |
50 | 51 |
|
51 | 52 | $userManager = Server::get(IUserManager::class); |
52 | | - $userManager->createUser($this->user1, 'longrandompassword'); |
53 | | - $userManager->createUser($this->user2, 'longrandompassword'); |
| 53 | + $this->user1 = $userManager->createUser($user1, 'longrandompassword'); |
| 54 | + $this->user2 = $userManager->createUser($user2, 'longrandompassword'); |
54 | 55 |
|
55 | 56 | \OC::registerShareHooks(Server::get(SystemConfig::class)); |
56 | 57 |
|
57 | 58 | $this->job = new ExpireSharesJob(Server::get(ITimeFactory::class), Server::get(IManager::class), $this->connection); |
58 | 59 | } |
59 | 60 |
|
60 | 61 | protected function tearDown(): void { |
61 | | - $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`'); |
| 62 | + $this->connection->getQueryBuilder()->delete('share')->executeStatement(); |
62 | 63 |
|
63 | | - $userManager = Server::get(IUserManager::class); |
64 | | - $user1 = $userManager->get($this->user1); |
65 | | - if ($user1) { |
66 | | - $user1->delete(); |
67 | | - } |
68 | | - $user2 = $userManager->get($this->user2); |
69 | | - if ($user2) { |
70 | | - $user2->delete(); |
71 | | - } |
| 64 | + $this->user1->delete(); |
| 65 | + $this->user2->delete(); |
72 | 66 |
|
73 | 67 | $this->logout(); |
74 | 68 |
|
75 | 69 | parent::tearDown(); |
76 | 70 | } |
77 | 71 |
|
78 | | - private function getShares() { |
| 72 | + private function getShares(): array { |
79 | 73 | $shares = []; |
80 | 74 | $qb = $this->connection->getQueryBuilder(); |
81 | 75 |
|
@@ -106,26 +100,25 @@ public static function dataExpireLinkShare() { |
106 | 100 | } |
107 | 101 |
|
108 | 102 | /** |
109 | | - * |
110 | 103 | * @param bool addExpiration Should we add an expire date |
111 | 104 | * @param string $interval The dateInterval |
112 | 105 | * @param bool $addInterval If true add to the current time if false subtract |
113 | 106 | * @param bool $shouldExpire Should this share be expired |
114 | 107 | */ |
115 | | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExpireLinkShare')] |
116 | | - public function testExpireLinkShare($addExpiration, $interval, $addInterval, $shouldExpire): void { |
117 | | - $this->loginAsUser($this->user1); |
| 108 | + #[DataProvider('dataExpireLinkShare')] |
| 109 | + public function testExpireLinkShare(bool $addExpiration, string $interval, bool $addInterval, bool $shouldExpire): void { |
| 110 | + $this->loginAsUser($this->user1->getUID()); |
118 | 111 |
|
119 | | - $user1Folder = \OC::$server->getUserFolder($this->user1); |
| 112 | + $user1Folder = $this->rootFolder->getUserFolder($this->user1->getUID()); |
120 | 113 | $testFolder = $user1Folder->newFolder('test'); |
121 | 114 |
|
122 | | - $shareManager = Server::get(\OCP\Share\IManager::class); |
| 115 | + $shareManager = Server::get(IManager::class); |
123 | 116 | $share = $shareManager->newShare(); |
124 | 117 |
|
125 | 118 | $share->setNode($testFolder) |
126 | 119 | ->setShareType(IShare::TYPE_LINK) |
127 | 120 | ->setPermissions(Constants::PERMISSION_READ) |
128 | | - ->setSharedBy($this->user1); |
| 121 | + ->setSharedBy($this->user1->getUID()); |
129 | 122 |
|
130 | 123 | $shareManager->createShare($share); |
131 | 124 |
|
@@ -171,19 +164,19 @@ public function testExpireLinkShare($addExpiration, $interval, $addInterval, $sh |
171 | 164 | } |
172 | 165 |
|
173 | 166 | public function testDoNotExpireOtherShares(): void { |
174 | | - $this->loginAsUser($this->user1); |
| 167 | + $this->loginAsUser($this->user1->getUID()); |
175 | 168 |
|
176 | | - $user1Folder = \OC::$server->getUserFolder($this->user1); |
| 169 | + $user1Folder = $this->rootFolder->getUserFolder($this->user1->getUID()); |
177 | 170 | $testFolder = $user1Folder->newFolder('test'); |
178 | 171 |
|
179 | | - $shareManager = Server::get(\OCP\Share\IManager::class); |
| 172 | + $shareManager = Server::get(IManager::class); |
180 | 173 | $share = $shareManager->newShare(); |
181 | 174 |
|
182 | 175 | $share->setNode($testFolder) |
183 | 176 | ->setShareType(IShare::TYPE_USER) |
184 | 177 | ->setPermissions(Constants::PERMISSION_READ) |
185 | | - ->setSharedBy($this->user1) |
186 | | - ->setSharedWith($this->user2); |
| 178 | + ->setSharedBy($this->user1->getUID()) |
| 179 | + ->setSharedWith($this->user2->getUID()); |
187 | 180 |
|
188 | 181 | $shareManager->createShare($share); |
189 | 182 |
|
|
0 commit comments