mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-22 01:12:04 -04:00
refactor given when then steps in fileversions context (#7269)
migrating set response from helper function to when step in preview feature separate single when/then steps by converting to helper function use of httpstatuscode check function in given step and rebased change function name remove use of setresponse in then step set the returned response
This commit is contained in:
@@ -134,17 +134,14 @@ class FilesVersionsContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user restores version index :versionIndex of file :path using the WebDAV API
|
||||
* @Given user :user has restored version index :versionIndex of file :path
|
||||
*
|
||||
* @param string $user
|
||||
* @param int $versionIndex
|
||||
* @param string $path
|
||||
*
|
||||
* @return void
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userRestoresVersionIndexOfFile(string $user, int $versionIndex, string $path):void {
|
||||
public function restoreVersionIndexOfFile(string $user, int $versionIndex, string $path):ResponseInterface {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$fileId = $this->featureContext->getFileIdForPath($user, $path);
|
||||
Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $path user $user not found (the file may not exist)");
|
||||
@@ -155,7 +152,7 @@ class FilesVersionsContext implements Context {
|
||||
WebDavHelper::getDavPath($user, 2) . \trim($path, "/");
|
||||
$fullUrl = $this->featureContext->getBaseUrlWithoutPath() .
|
||||
$xmlPart[$versionIndex];
|
||||
$response = HttpRequestHelper::sendRequest(
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$fullUrl,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
'COPY',
|
||||
@@ -163,6 +160,35 @@ class FilesVersionsContext implements Context {
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
['Destination' => $destinationUrl]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given user :user has restored version index :versionIndex of file :path
|
||||
*
|
||||
* @param string $user
|
||||
* @param int $versionIndex
|
||||
* @param string $path
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userHasRestoredVersionIndexOfFile(string $user, int $versionIndex, string $path):void {
|
||||
$response = $this->restoreVersionIndexOfFile($user, $versionIndex, $path);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user restores version index :versionIndex of file :path using the WebDAV API
|
||||
*
|
||||
* @param string $user
|
||||
* @param int $versionIndex
|
||||
* @param string $path
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userRestoresVersionIndexOfFile(string $user, int $versionIndex, string $path):void {
|
||||
$response = $this->restoreVersionIndexOfFile($user, $versionIndex, $path);
|
||||
$this->featureContext->setResponse($response, $user);
|
||||
}
|
||||
|
||||
@@ -280,16 +306,14 @@ class FilesVersionsContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user downloads the version of file :path with the index :index
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $path
|
||||
* @param string $index
|
||||
*
|
||||
* @return void
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function downloadVersion(string $user, string $path, string $index):void {
|
||||
public function downloadVersion(string $user, string $path, string $index):ResponseInterface {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$fileId = $this->featureContext->getFileIdForPath($user, $path);
|
||||
Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $path user $user not found (the file may not exist)");
|
||||
@@ -305,13 +329,26 @@ class FilesVersionsContext implements Context {
|
||||
$url = WebDavHelper::sanitizeUrl(
|
||||
$this->featureContext->getBaseUrlWithoutPath() . $xmlPart[$index]
|
||||
);
|
||||
$response = HttpRequestHelper::get(
|
||||
return HttpRequestHelper::get(
|
||||
$url,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user)
|
||||
);
|
||||
$this->featureContext->setResponse($response, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user downloads the version of file :path with the index :index
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $path
|
||||
* @param string $index
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userDownloadsVersion(string $user, string $path, string $index):void {
|
||||
$this->featureContext->setResponse($this->downloadVersion($user, $path, $index), $user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,9 +368,9 @@ class FilesVersionsContext implements Context {
|
||||
string $user,
|
||||
string $content
|
||||
): void {
|
||||
$this->downloadVersion($user, $path, $index);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe("200");
|
||||
$this->featureContext->downloadedContentShouldBe($content);
|
||||
$response = $this->downloadVersion($user, $path, $index);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe("200", '', $response);
|
||||
$this->featureContext->checkDownloadedContentMatches($content, '', $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2673,7 +2673,7 @@ class SpacesContext implements Context {
|
||||
string $spaceName
|
||||
): void {
|
||||
$this->setSpaceIDByName($user, $spaceName);
|
||||
$this->filesVersionsContext->downloadVersion($user, $fileName, $index);
|
||||
$this->featureContext->setResponse($this->filesVersionsContext->downloadVersion($user, $fileName, $index));
|
||||
WebDavHelper::$SPACE_ID_FROM_OCIS = '';
|
||||
}
|
||||
|
||||
|
||||
@@ -455,10 +455,9 @@ trait WebDav {
|
||||
* @param string|null $width
|
||||
* @param string|null $height
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function downloadPreviews(string $user, ?string $path, ?string $doDavRequestAsUser, ?string $width, ?string $height):void {
|
||||
public function downloadPreviews(string $user, ?string $path, ?string $doDavRequestAsUser, ?string $width, ?string $height):ResponseInterface {
|
||||
$user = $this->getActualUsername($user);
|
||||
$doDavRequestAsUser = $this->getActualUsername($doDavRequestAsUser);
|
||||
$urlParameter = [
|
||||
@@ -467,14 +466,14 @@ trait WebDav {
|
||||
'forceIcon' => '0',
|
||||
'preview' => '1'
|
||||
];
|
||||
$this->response = $this->makeDavRequest(
|
||||
return $this->makeDavRequest(
|
||||
$user,
|
||||
"GET",
|
||||
$path,
|
||||
[],
|
||||
null,
|
||||
"files",
|
||||
null,
|
||||
'2',
|
||||
false,
|
||||
null,
|
||||
$urlParameter,
|
||||
@@ -1054,14 +1053,17 @@ trait WebDav {
|
||||
/**
|
||||
* @param string $expectedContent
|
||||
* @param string $extraErrorText
|
||||
* @param ResponseInterface|null $response
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function checkDownloadedContentMatches(
|
||||
string $expectedContent,
|
||||
string $extraErrorText = ""
|
||||
string $extraErrorText = "",
|
||||
?ResponseInterface $response = null
|
||||
):void {
|
||||
$actualContent = (string) $this->response->getBody();
|
||||
$response = $response ?? $this->response;
|
||||
$actualContent = (string) $response->getBody();
|
||||
// For this test we really care about the content.
|
||||
// A separate "Then" step can specifically check the HTTP status.
|
||||
// But if the content is wrong (e.g. empty) then it is useful to
|
||||
@@ -4639,13 +4641,14 @@ trait WebDav {
|
||||
* @return void
|
||||
*/
|
||||
public function downloadPreviewOfFiles(string $user, string $path, string $width, string $height):void {
|
||||
$this->downloadPreviews(
|
||||
$response = $this->downloadPreviews(
|
||||
$user,
|
||||
$path,
|
||||
null,
|
||||
$width,
|
||||
$height
|
||||
);
|
||||
$this->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4660,13 +4663,14 @@ trait WebDav {
|
||||
* @return void
|
||||
*/
|
||||
public function downloadPreviewOfOtherUser(string $user1, string $path, string $doDavRequestAsUser, string $width, string $height):void {
|
||||
$this->downloadPreviews(
|
||||
$response = $this->downloadPreviews(
|
||||
$user1,
|
||||
$path,
|
||||
$doDavRequestAsUser,
|
||||
$width,
|
||||
$height
|
||||
);
|
||||
$this->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user