Skip to content

Commit ca191d0

Browse files
committed
update tests
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 9e53dc7 commit ca191d0

File tree

4 files changed

+80
-47
lines changed

4 files changed

+80
-47
lines changed

apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
namespace OCA\DAV\Tests\Unit\Connector\Sabre;
3030

3131
use OC\Files\FileInfo;
32+
use OC\Files\Node\Node;
3233
use OC\Files\Storage\Wrapper\Quota;
3334
use OCA\DAV\Connector\Sabre\Directory;
3435
use OCP\Files\ForbiddenException;
@@ -82,9 +83,12 @@ protected function setUp(): void {
8283

8384
$this->view = $this->createMock('OC\Files\View');
8485
$this->info = $this->createMock('OC\Files\FileInfo');
85-
$this->info->expects($this->any())
86-
->method('isReadable')
86+
$this->info->method('isReadable')
8787
->willReturn(true);
88+
$this->info->method('getType')
89+
->willReturn(Node::TYPE_FOLDER);
90+
$this->info->method('getName')
91+
->willReturn("folder");
8892
}
8993

9094
private function getDir($path = '/') {
@@ -186,17 +190,17 @@ public function testGetChildren() {
186190
$info2 = $this->getMockBuilder(FileInfo::class)
187191
->disableOriginalConstructor()
188192
->getMock();
189-
$info1->expects($this->any())
190-
->method('getName')
193+
$info1->method('getName')
191194
->willReturn('first');
192-
$info1->expects($this->any())
193-
->method('getEtag')
195+
$info1->method('getPath')
196+
->willReturn('folder/first');
197+
$info1->method('getEtag')
194198
->willReturn('abc');
195-
$info2->expects($this->any())
196-
->method('getName')
199+
$info2->method('getName')
197200
->willReturn('second');
198-
$info2->expects($this->any())
199-
->method('getEtag')
201+
$info2->method('getPath')
202+
->willReturn('folder/second');
203+
$info2->method('getEtag')
200204
->willReturn('def');
201205

202206
$this->view->expects($this->once())
@@ -403,8 +407,12 @@ public function moveSuccessProvider() {
403407
private function moveTest($source, $destination, $updatables, $deletables) {
404408
$view = new TestViewDirectory($updatables, $deletables);
405409

406-
$sourceInfo = new FileInfo($source, null, null, [], null);
407-
$targetInfo = new FileInfo(dirname($destination), null, null, [], null);
410+
$sourceInfo = new FileInfo($source, null, null, [
411+
'type' => FileInfo::TYPE_FOLDER,
412+
], null);
413+
$targetInfo = new FileInfo(dirname($destination), null, null, [
414+
'type' => FileInfo::TYPE_FOLDER,
415+
], null);
408416

409417
$sourceNode = new Directory($view, $sourceInfo);
410418
$targetNode = $this->getMockBuilder(Directory::class)
@@ -429,8 +437,8 @@ public function testFailingMove() {
429437

430438
$view = new TestViewDirectory($updatables, $deletables);
431439

432-
$sourceInfo = new FileInfo($source, null, null, [], null);
433-
$targetInfo = new FileInfo(dirname($destination), null, null, [], null);
440+
$sourceInfo = new FileInfo($source, null, null, ['type' => FileInfo::TYPE_FOLDER], null);
441+
$targetInfo = new FileInfo(dirname($destination), null, null, ['type' => FileInfo::TYPE_FOLDER], null);
434442

435443
$sourceNode = new Directory($view, $sourceInfo);
436444
$targetNode = $this->getMockBuilder(Directory::class)

apps/dav/tests/unit/Connector/Sabre/FileTest.php

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OC\Files\View;
3838
use OCA\DAV\Connector\Sabre\File;
3939
use OCP\Constants;
40+
use OCP\Files\FileInfo;
4041
use OCP\Files\ForbiddenException;
4142
use OCP\Files\Storage;
4243
use OCP\IConfig;
@@ -211,7 +212,8 @@ function ($path) use ($storage) {
211212
->willReturnArgument(0);
212213

213214
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
214-
'permissions' => \OCP\Constants::PERMISSION_ALL
215+
'permissions' => \OCP\Constants::PERMISSION_ALL,
216+
'type' => FileInfo::TYPE_FOLDER,
215217
], null);
216218

217219
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -272,7 +274,8 @@ function ($path) use ($storage) {
272274
$_SERVER['HTTP_OC_CHUNKED'] = true;
273275

274276
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [
275-
'permissions' => \OCP\Constants::PERMISSION_ALL
277+
'permissions' => \OCP\Constants::PERMISSION_ALL,
278+
'type' => FileInfo::TYPE_FOLDER,
276279
], null);
277280
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
278281

@@ -282,7 +285,8 @@ function ($path) use ($storage) {
282285
$file->releaseLock(ILockingProvider::LOCK_SHARED);
283286

284287
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [
285-
'permissions' => \OCP\Constants::PERMISSION_ALL
288+
'permissions' => \OCP\Constants::PERMISSION_ALL,
289+
'type' => FileInfo::TYPE_FOLDER,
286290
], null);
287291
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
288292

@@ -326,7 +330,10 @@ private function doPut($path, $viewRoot = null, Request $request = null) {
326330
$viewRoot . '/' . ltrim($path, '/'),
327331
$this->getMockStorage(),
328332
null,
329-
['permissions' => \OCP\Constants::PERMISSION_ALL],
333+
[
334+
'permissions' => \OCP\Constants::PERMISSION_ALL,
335+
'type' => FileInfo::TYPE_FOLDER,
336+
],
330337
null
331338
);
332339

@@ -690,7 +697,8 @@ public function testSimplePutFailsSizeCheck() {
690697
$_SERVER['REQUEST_METHOD'] = 'PUT';
691698

692699
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
693-
'permissions' => \OCP\Constants::PERMISSION_ALL
700+
'permissions' => \OCP\Constants::PERMISSION_ALL,
701+
'type' => FileInfo::TYPE_FOLDER,
694702
], null);
695703

696704
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -723,7 +731,8 @@ public function testSimplePutFailsMoveFromStorage() {
723731
$view->lockFile('/test.txt', ILockingProvider::LOCK_EXCLUSIVE);
724732

725733
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt', $this->getMockStorage(), null, [
726-
'permissions' => \OCP\Constants::PERMISSION_ALL
734+
'permissions' => \OCP\Constants::PERMISSION_ALL,
735+
'type' => FileInfo::TYPE_FOLDER,
727736
], null);
728737

729738
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -758,15 +767,17 @@ public function testChunkedPutFailsFinalRename() {
758767
$_SERVER['HTTP_OC_CHUNKED'] = true;
759768

760769
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [
761-
'permissions' => \OCP\Constants::PERMISSION_ALL
770+
'permissions' => \OCP\Constants::PERMISSION_ALL,
771+
'type' => FileInfo::TYPE_FOLDER,
762772
], null);
763773
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
764774
$file->acquireLock(ILockingProvider::LOCK_SHARED);
765775
$this->assertNull($file->put('test data one'));
766776
$file->releaseLock(ILockingProvider::LOCK_SHARED);
767777

768778
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [
769-
'permissions' => \OCP\Constants::PERMISSION_ALL
779+
'permissions' => \OCP\Constants::PERMISSION_ALL,
780+
'type' => FileInfo::TYPE_FOLDER,
770781
], null);
771782
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
772783

@@ -797,7 +808,8 @@ public function testSimplePutInvalidChars() {
797808
->willReturnArgument(0);
798809

799810
$info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, [
800-
'permissions' => \OCP\Constants::PERMISSION_ALL
811+
'permissions' => \OCP\Constants::PERMISSION_ALL,
812+
'type' => FileInfo::TYPE_FOLDER,
801813
], null);
802814
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
803815

@@ -836,7 +848,8 @@ public function testSetNameInvalidChars() {
836848
->willReturnArgument(0);
837849

838850
$info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, [
839-
'permissions' => \OCP\Constants::PERMISSION_ALL
851+
'permissions' => \OCP\Constants::PERMISSION_ALL,
852+
'type' => FileInfo::TYPE_FOLDER,
840853
], null);
841854
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
842855
$file->setName('/super*star.txt');
@@ -863,7 +876,8 @@ public function testUploadAbort() {
863876
$_SERVER['REQUEST_METHOD'] = 'PUT';
864877

865878
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
866-
'permissions' => \OCP\Constants::PERMISSION_ALL
879+
'permissions' => \OCP\Constants::PERMISSION_ALL,
880+
'type' => FileInfo::TYPE_FOLDER,
867881
], null);
868882

869883
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -897,7 +911,8 @@ public function testDeleteWhenAllowed() {
897911
->willReturn(true);
898912

899913
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
900-
'permissions' => \OCP\Constants::PERMISSION_ALL
914+
'permissions' => \OCP\Constants::PERMISSION_ALL,
915+
'type' => FileInfo::TYPE_FOLDER,
901916
], null);
902917

903918
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -915,7 +930,8 @@ public function testDeleteThrowsWhenDeletionNotAllowed() {
915930
->getMock();
916931

917932
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
918-
'permissions' => 0
933+
'permissions' => 0,
934+
'type' => FileInfo::TYPE_FOLDER,
919935
], null);
920936

921937
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -938,7 +954,8 @@ public function testDeleteThrowsWhenDeletionFailed() {
938954
->willReturn(false);
939955

940956
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
941-
'permissions' => \OCP\Constants::PERMISSION_ALL
957+
'permissions' => \OCP\Constants::PERMISSION_ALL,
958+
'type' => FileInfo::TYPE_FOLDER,
942959
], null);
943960

944961
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -961,7 +978,8 @@ public function testDeleteThrowsWhenDeletionThrows() {
961978
->willThrowException(new ForbiddenException('', true));
962979

963980
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
964-
'permissions' => \OCP\Constants::PERMISSION_ALL
981+
'permissions' => \OCP\Constants::PERMISSION_ALL,
982+
'type' => FileInfo::TYPE_FOLDER,
965983
], null);
966984

967985
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -997,7 +1015,10 @@ public function testPutLocking() {
9971015
'/' . $this->user . '/files/' . $path,
9981016
$this->getMockStorage(),
9991017
null,
1000-
['permissions' => \OCP\Constants::PERMISSION_ALL],
1018+
[
1019+
'permissions' => \OCP\Constants::PERMISSION_ALL,
1020+
'type' => FileInfo::TYPE_FOLDER,
1021+
],
10011022
null
10021023
);
10031024

@@ -1129,7 +1150,8 @@ public function testGetFopenFails() {
11291150
->willReturn(false);
11301151

11311152
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
1132-
'permissions' => \OCP\Constants::PERMISSION_ALL
1153+
'permissions' => \OCP\Constants::PERMISSION_ALL,
1154+
'type' => FileInfo::TYPE_FOLDER,
11331155
], null);
11341156

11351157
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -1149,7 +1171,8 @@ public function testGetFopenThrows() {
11491171
->willThrowException(new ForbiddenException('', true));
11501172

11511173
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
1152-
'permissions' => \OCP\Constants::PERMISSION_ALL
1174+
'permissions' => \OCP\Constants::PERMISSION_ALL,
1175+
'type' => FileInfo::TYPE_FOLDER,
11531176
], null);
11541177

11551178
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -1168,7 +1191,8 @@ public function testGetThrowsIfNoPermission() {
11681191
->method('fopen');
11691192

11701193
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
1171-
'permissions' => \OCP\Constants::PERMISSION_CREATE // no read perm
1194+
'permissions' => \OCP\Constants::PERMISSION_CREATE, // no read perm
1195+
'type' => FileInfo::TYPE_FOLDER,
11721196
], null);
11731197

11741198
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -1215,7 +1239,10 @@ public function testPutLockExpired() {
12151239
'/' . $this->user . '/files/' . $path,
12161240
$this->getMockStorage(),
12171241
null,
1218-
['permissions' => \OCP\Constants::PERMISSION_ALL],
1242+
[
1243+
'permissions' => \OCP\Constants::PERMISSION_ALL,
1244+
'type' => FileInfo::TYPE_FOLDER,
1245+
],
12191246
null
12201247
);
12211248

apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,14 @@ public function testGetNodeForPath(
167167
$fileInfo = $this->getMockBuilder(FileInfo::class)
168168
->disableOriginalConstructor()
169169
->getMock();
170-
$fileInfo->expects($this->once())
171-
->method('getType')
170+
$fileInfo->method('getType')
172171
->willReturn($type);
173-
$fileInfo->expects($this->once())
174-
->method('getName')
172+
$fileInfo->method('getName')
175173
->willReturn($outputFileName);
176174
$fileInfo->method('getStorage')
177175
->willReturn($this->createMock(\OC\Files\Storage\Common::class));
178176

179-
$view->expects($this->once())
180-
->method('getFileInfo')
177+
$view->method('getFileInfo')
181178
->with($fileInfoQueryPath)
182179
->willReturn($fileInfo);
183180

apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ public function testGetProperties($shareTypes) {
111111
->disableOriginalConstructor()
112112
->getMock();
113113

114-
$this->userFolder->expects($this->once())
115-
->method('get')
116-
->with('/subdir')
114+
$sabreNode->method('getNode')
117115
->willReturn($node);
118116

119117
$this->shareManager->expects($this->any())
@@ -180,16 +178,19 @@ public function testPreloadThenGetProperties($shareTypes) {
180178
$node = $this->createMock(Folder::class);
181179
$node->method('getId')
182180
->willReturn(123);
183-
$node1 = $this->createMock(File::class);
181+
$node1 = $this->createMock(\OC\Files\Node\File::class);
184182
$node1->method('getId')
185183
->willReturn(111);
186-
$node2 = $this->createMock(File::class);
184+
$node2 = $this->createMock(\OC\Files\Node\File::class);
187185
$node2->method('getId')
188186
->willReturn(222);
189187

190-
$this->userFolder->method('get')
191-
->with('/subdir')
188+
$sabreNode->method('getNode')
192189
->willReturn($node);
190+
$sabreNode1->method('getNode')
191+
->willReturn($node1);
192+
$sabreNode2->method('getNode')
193+
->willReturn($node2);
193194

194195
$dummyShares = array_map(function ($type) {
195196
$share = $this->getMockBuilder(IShare::class)->getMock();

0 commit comments

Comments
 (0)