Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Sep 29, 2020
1 parent dd1dbc2 commit a52f852
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);

Expand All @@ -111,7 +112,7 @@ public function testDeleteRootFolderFails() {
$dir->delete();
}


public function testDeleteForbidden() {
$this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class);

Expand All @@ -130,7 +131,7 @@ public function testDeleteForbidden() {
$dir->delete();
}


public function testDeleteFolderWhenAllowed() {
// deletion allowed
$this->info->expects($this->once())
Expand All @@ -147,7 +148,7 @@ public function testDeleteFolderWhenAllowed() {
$dir->delete();
}


public function testDeleteFolderFailsWhenNotAllowed() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

Expand All @@ -159,7 +160,7 @@ public function testDeleteFolderFailsWhenNotAllowed() {
$dir->delete();
}


public function testDeleteFolderThrowsWhenDeletionFailed() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

Expand Down Expand Up @@ -217,7 +218,7 @@ public function testGetChildren() {
$dir->getChildren();
}


public function testGetChildrenNoPermission() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);

Expand All @@ -230,7 +231,7 @@ public function testGetChildrenNoPermission() {
$dir->getChildren();
}


public function testGetChildNoPermission() {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);

Expand All @@ -242,7 +243,7 @@ public function testGetChildNoPermission() {
$dir->getChild('test');
}


public function testGetChildThrowStorageNotAvailableException() {
$this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class);

Expand All @@ -254,7 +255,7 @@ public function testGetChildThrowStorageNotAvailableException() {
$dir->getChild('.');
}


public function testGetChildThrowInvalidPath() {
$this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class);

Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit a52f852

Please sign in to comment.