Skip to content

Commit

Permalink
Merge branch 'MDL69756_master' of https://github.com/Amrita1991/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Jun 13, 2022
2 parents b76dbf7 + 33e5db9 commit ce69101
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -207,7 +207,7 @@ public function transfer_file_to_path($srcpath, $dstpath, $operation, $webdavcli
}
}
$this->systemwebdavclient->close();
if (!($result == 201 || $result == 412)) {
if (!($result == 201 || $result == 204 || $result == 412)) {
$details = get_string('contactadminwith', 'repository_nextcloud',
'A webdav request to ' . $operation . ' a file failed.');
throw new request_exception(array('instance' => $this->repositoryname, 'errormessage' => $details));
Expand Down
24 changes: 24 additions & 0 deletions repository/nextcloud/tests/access_controlled_link_manager_test.php
Expand Up @@ -306,6 +306,30 @@ public function test_transfer_file_to_path_copyfile() {

$this->assertEquals(201, $result);
}
/**
* Test whether the webdav client gets the right params and whether function handles overwrite.
*
* @covers \repository_nextcloud\access_controlled_link_manager::transfer_file_to_path
*/
public function test_transfer_file_to_path_overwritefile() {
// Initialize params.
$parsedwebdavurl = parse_url($this->issuer->get_endpoint_url('webdav'));
$webdavprefix = $parsedwebdavurl['path'];
$srcpath = 'sourcepath';
$dstpath = "destinationpath/another/path";

// Mock the Webdavclient and set expected methods.
$systemwebdavclientmock = $this->createMock(\webdav_client::class);
$systemwebdavclientmock->expects($this->once())->method('open')->willReturn(true);
$systemwebdavclientmock->expects($this->once())->method('copy_file')->with($webdavprefix . $srcpath,
$webdavprefix . $dstpath . '/' . $srcpath, true)->willReturn(204);
$this->set_private_property($systemwebdavclientmock, 'systemwebdavclient', $this->linkmanager);

// Call of function.
$result = $this->linkmanager->transfer_file_to_path($srcpath, $dstpath, 'copy');

$this->assertEquals(204, $result);
}
/**
* This function tests whether the function transfer_file_to_path() moves or copies a given file to a given path
* It tests whether the webdav_client gets the right parameter and whether function distinguishes between move and copy.
Expand Down

0 comments on commit ce69101

Please sign in to comment.