From a52f852e0bb7f9d99d8b8165b43852beb86862a3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 26 Aug 2020 15:46:24 +0200 Subject: [PATCH] fix tests Signed-off-by: Robin Appelman --- .../unit/Connector/Sabre/DirectoryTest.php | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php index 528327a681afc..dbcd363de5723 100644 --- a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php @@ -31,6 +31,7 @@ use OC\Files\Storage\Wrapper\Quota; use OCA\DAV\Connector\Sabre\Directory; use OCP\Files\ForbiddenException; +use OCP\Files\Mount\IMountPoint; class TestViewDirectory extends \OC\Files\View { @@ -98,7 +99,7 @@ private function getDir($path = '/') { return new Directory($this->view, $this->info); } - + public function testDeleteRootFolderFails() { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); @@ -111,7 +112,7 @@ public function testDeleteRootFolderFails() { $dir->delete(); } - + public function testDeleteForbidden() { $this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class); @@ -130,7 +131,7 @@ public function testDeleteForbidden() { $dir->delete(); } - + public function testDeleteFolderWhenAllowed() { // deletion allowed $this->info->expects($this->once()) @@ -147,7 +148,7 @@ public function testDeleteFolderWhenAllowed() { $dir->delete(); } - + public function testDeleteFolderFailsWhenNotAllowed() { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); @@ -159,7 +160,7 @@ public function testDeleteFolderFailsWhenNotAllowed() { $dir->delete(); } - + public function testDeleteFolderThrowsWhenDeletionFailed() { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); @@ -217,7 +218,7 @@ public function testGetChildren() { $dir->getChildren(); } - + public function testGetChildrenNoPermission() { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); @@ -230,7 +231,7 @@ public function testGetChildrenNoPermission() { $dir->getChildren(); } - + public function testGetChildNoPermission() { $this->expectException(\Sabre\DAV\Exception\NotFound::class); @@ -242,7 +243,7 @@ public function testGetChildNoPermission() { $dir->getChild('test'); } - + public function testGetChildThrowStorageNotAvailableException() { $this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class); @@ -254,7 +255,7 @@ public function testGetChildThrowStorageNotAvailableException() { $dir->getChild('.'); } - + public function testGetChildThrowInvalidPath() { $this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class); @@ -269,9 +270,12 @@ public function testGetChildThrowInvalidPath() { } public function testGetQuotaInfoUnlimited() { + $mountPoint = $this->createMock(IMountPoint::class); $storage = $this->getMockBuilder(Quota::class) ->disableOriginalConstructor() ->getMock(); + $mountPoint->method('getStorage') + ->willReturn($storage); $storage->expects($this->any()) ->method('instanceOfStorage') @@ -292,17 +296,24 @@ public function testGetQuotaInfoUnlimited() { ->will($this->returnValue(200)); $this->info->expects($this->once()) - ->method('getStorage') - ->will($this->returnValue($storage)); + ->method('getMountPoint') + ->willReturn($mountPoint); + + $this->view->expects($this->once()) + ->method('getFileInfo') + ->willReturn($this->info); $dir = new Directory($this->view, $this->info); $this->assertEquals([200, -3], $dir->getQuotaInfo()); //200 used, unlimited } public function testGetQuotaInfoSpecific() { + $mountPoint = $this->createMock(IMountPoint::class); $storage = $this->getMockBuilder(Quota::class) ->disableOriginalConstructor() ->getMock(); + $mountPoint->method('getStorage') + ->willReturn($storage); $storage->expects($this->any()) ->method('instanceOfStorage') @@ -324,8 +335,12 @@ public function testGetQuotaInfoSpecific() { ->will($this->returnValue(200)); $this->info->expects($this->once()) - ->method('getStorage') - ->will($this->returnValue($storage)); + ->method('getMountPoint') + ->willReturn($mountPoint); + + $this->view->expects($this->once()) + ->method('getFileInfo') + ->willReturn($this->info); $dir = new Directory($this->view, $this->info); $this->assertEquals([200, 800], $dir->getQuotaInfo()); //200 used, 800 free @@ -404,7 +419,7 @@ private function moveTest($source, $destination, $updatables, $deletables) { $this->assertTrue($targetNode->moveInto(basename($destination), $source, $sourceNode)); } - + public function testFailingMove() { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); $this->expectExceptionMessage('Could not copy directory b, target exists');