mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-69756 nextcloud: copy-overwrite handling
This commit is contained in:
parent
ac39bac81b
commit
129d445908
2 changed files with 25 additions and 1 deletions
|
@ -207,7 +207,7 @@ class access_controlled_link_manager{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->systemwebdavclient->close();
|
$this->systemwebdavclient->close();
|
||||||
if (!($result == 201 || $result == 412)) {
|
if (!($result == 201 || $result == 204 || $result == 412)) {
|
||||||
$details = get_string('contactadminwith', 'repository_nextcloud',
|
$details = get_string('contactadminwith', 'repository_nextcloud',
|
||||||
'A webdav request to ' . $operation . ' a file failed.');
|
'A webdav request to ' . $operation . ' a file failed.');
|
||||||
throw new request_exception(array('instance' => $this->repositoryname, 'errormessage' => $details));
|
throw new request_exception(array('instance' => $this->repositoryname, 'errormessage' => $details));
|
||||||
|
|
|
@ -306,6 +306,30 @@ XML;
|
||||||
|
|
||||||
$this->assertEquals(201, $result);
|
$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
|
* 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.
|
* It tests whether the webdav_client gets the right parameter and whether function distinguishes between move and copy.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue