diff --git a/repository/nextcloud/classes/access_controlled_link_manager.php b/repository/nextcloud/classes/access_controlled_link_manager.php index f9abc6f722b..87c9db178e9 100644 --- a/repository/nextcloud/classes/access_controlled_link_manager.php +++ b/repository/nextcloud/classes/access_controlled_link_manager.php @@ -207,7 +207,7 @@ class access_controlled_link_manager{ } } $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)); diff --git a/repository/nextcloud/tests/access_controlled_link_manager_test.php b/repository/nextcloud/tests/access_controlled_link_manager_test.php index 6be9edc1f19..3f15c521d80 100644 --- a/repository/nextcloud/tests/access_controlled_link_manager_test.php +++ b/repository/nextcloud/tests/access_controlled_link_manager_test.php @@ -306,6 +306,30 @@ XML; $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.