|
6 | 6 | * SPDX-FileCopyrightText: 2016 ownCloud, Inc. |
7 | 7 | * SPDX-License-Identifier: AGPL-3.0-only |
8 | 8 | */ |
| 9 | + |
9 | 10 | namespace OCA\Files_Trashbin\Tests; |
10 | 11 |
|
| 12 | +use OC\Files\Cache\Updater; |
11 | 13 | use OC\Files\Filesystem; |
12 | 14 | use OC\Files\Storage\Common; |
| 15 | +use OC\Files\Storage\Local; |
13 | 16 | use OC\Files\Storage\Temporary; |
14 | 17 | use OC\Files\View; |
15 | 18 | use OCA\Files_Trashbin\AppInfo\Application; |
16 | 19 | use OCA\Files_Trashbin\Events\MoveToTrashEvent; |
17 | 20 | use OCA\Files_Trashbin\Storage; |
18 | 21 | use OCA\Files_Trashbin\Trash\ITrashManager; |
| 22 | +use OCA\Files_Trashbin\Trashbin; |
19 | 23 | use OCP\AppFramework\Bootstrap\IBootContext; |
20 | 24 | use OCP\AppFramework\Utility\ITimeFactory; |
21 | 25 | use OCP\Constants; |
@@ -137,6 +141,62 @@ public function testTrashEntryCreatedWhenSourceNotInCache(): void { |
137 | 141 | $this->assertTrue($trashStorage->getCache()->inCache($trashInternalPath)); |
138 | 142 | } |
139 | 143 |
|
| 144 | + public function testTrashEntryNotCreatedWhenDeleteFailed(): void { |
| 145 | + $storage2 = $this->getMockBuilder(Temporary::class) |
| 146 | + ->setConstructorArgs([]) |
| 147 | + ->onlyMethods(['unlink', 'instanceOfStorage']) |
| 148 | + ->getMock(); |
| 149 | + $storage2->method('unlink') |
| 150 | + ->willReturn(false); |
| 151 | + |
| 152 | + // disable same-storage move optimization |
| 153 | + $storage2->method('instanceOfStorage') |
| 154 | + ->willReturnCallback(fn (string $class) => ($class !== Local::class) && (new Temporary([]))->instanceOfStorage($class)); |
| 155 | + |
| 156 | + |
| 157 | + Filesystem::mount($storage2, [], $this->user . '/files/substorage'); |
| 158 | + $this->userView->file_put_contents('substorage/test.txt', 'foo'); |
| 159 | + |
| 160 | + $this->assertFalse($this->userView->unlink('substorage/test.txt')); |
| 161 | + |
| 162 | + $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/'); |
| 163 | + $this->assertEmpty($results); |
| 164 | + |
| 165 | + $trashData = Trashbin::getExtraData($this->user); |
| 166 | + $this->assertEmpty($trashData); |
| 167 | + } |
| 168 | + |
| 169 | + public function testTrashEntryNotCreatedWhenCacheRowFailed(): void { |
| 170 | + $trashStorage = $this->getMockBuilder(Temporary::class) |
| 171 | + ->setConstructorArgs([]) |
| 172 | + ->onlyMethods(['getUpdater']) |
| 173 | + ->getMock(); |
| 174 | + $updater = $this->getMockBuilder(Updater::class) |
| 175 | + ->setConstructorArgs([$trashStorage]) |
| 176 | + ->onlyMethods(['renameFromStorage']) |
| 177 | + ->getMock(); |
| 178 | + $trashStorage->method('getUpdater') |
| 179 | + ->willReturn($updater); |
| 180 | + $updater->method('renameFromStorage') |
| 181 | + ->willThrowException(new \Exception()); |
| 182 | + |
| 183 | + Filesystem::mount($trashStorage, [], $this->user . '/files_trashbin'); |
| 184 | + $this->userView->file_put_contents('test.txt', 'foo'); |
| 185 | + |
| 186 | + try { |
| 187 | + $this->assertFalse($this->userView->unlink('test.txt')); |
| 188 | + $this->fail(); |
| 189 | + } catch (\Exception) { |
| 190 | + // expected |
| 191 | + } |
| 192 | + |
| 193 | + $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/'); |
| 194 | + $this->assertEmpty($results); |
| 195 | + |
| 196 | + $trashData = Trashbin::getExtraData($this->user); |
| 197 | + $this->assertEmpty($trashData); |
| 198 | + } |
| 199 | + |
140 | 200 | /** |
141 | 201 | * Test that deleting a folder puts it into the trashbin. |
142 | 202 | */ |
|
0 commit comments