test(refactor): refactor some scenarios to the original and step definition

This commit is contained in:
pradip
2024-12-09 11:57:09 +05:45
parent 4515240a67
commit e4a836503f
3 changed files with 53 additions and 163 deletions

View File

@@ -46,6 +46,7 @@ class UploadHelper extends Assert {
* @param string|null $xRequestId
* @param array|null $headers
* @param int|null $davPathVersionToUse (1|2)
* @param bool $doChunkUpload
* @param int|null $noOfChunks how many chunks to upload
* @param bool|null $isGivenStep
*
@@ -61,10 +62,11 @@ class UploadHelper extends Assert {
?string $xRequestId = '',
?array $headers = [],
?int $davPathVersionToUse = 1,
bool $doChunkUpload = false,
?int $noOfChunks = 1,
?bool $isGivenStep = false
?bool $isGivenStep = false,
): ResponseInterface {
if ($noOfChunks === 1) {
if (!$doChunkUpload) {
$data = \file_get_contents($source);
return WebDavHelper::makeDavRequest(
$baseUrl,
@@ -127,55 +129,6 @@ class UploadHelper extends Assert {
return $result;
}
/**
* Upload the same file multiple times with different mechanisms.
*
* @param string|null $baseUrl URL of owncloud
* @param string|null $user user who uploads
* @param string|null $password
* @param string|null $source source file path
* @param string|null $destination destination path on the server
* @param string|null $xRequestId
* @param bool $overwriteMode when false creates separate files to test uploading brand-new files,
* when true it just overwrites the same file over and over again with the same name
*
* @return array of ResponseInterface
* @throws GuzzleException
*/
public static function uploadWithAllMechanisms(
?string $baseUrl,
?string $user,
?string $password,
?string $source,
?string $destination,
?string $xRequestId = '',
?bool $overwriteMode = false,
):array {
$responses = [];
foreach ([WebDavHelper::DAV_VERSION_OLD, WebDavHelper::DAV_VERSION_NEW, WebDavHelper::DAV_VERSION_SPACES] as $davPathVersion) {
foreach ([false, true] as $chunkingUse) {
$finalDestination = $destination;
if (!$overwriteMode && $chunkingUse) {
$finalDestination .= "-{$davPathVersion}dav-{$davPathVersion}chunking";
} elseif (!$overwriteMode && !$chunkingUse) {
$finalDestination .= "-{$davPathVersion}dav-regular";
}
$responses[] = self::upload(
$baseUrl,
$user,
$password,
$source,
$finalDestination,
$xRequestId,
[],
$davPathVersion,
2
);
}
}
return $responses;
}
/**
* cut the file in multiple chunks
* returns an array of chunks with the content of the file

View File

@@ -1624,7 +1624,7 @@ trait WebDav {
* @param array|null $headers
* @param int|null $noOfChunks Only use for chunked upload when $this->chunkingToUse is not null
*
* @return void
* @return ResponseInterface
* @throws Exception
*/
public function uploadFileWithHeaders(
@@ -1633,25 +1633,27 @@ trait WebDav {
string $destination,
?array $headers = [],
?int $noOfChunks = 0
):void {
try {
$this->pauseUploadDelete();
$this->response = UploadHelper::upload(
$this->getBaseUrl(),
$this->getActualUsername($user),
$this->getUserPassword($user),
$source,
$destination,
$this->getStepLineRef(),
$headers,
$this->getDavPathVersion(),
$noOfChunks
);
$this->lastUploadDeleteTime = \time();
} catch (BadResponseException $e) {
// 4xx and 5xx responses cause an exception
$this->response = $e->getResponse();
): ResponseInterface {
$doChunkUpload = true;
if ($noOfChunks <= 0) {
$doChunkUpload = false;
}
$this->pauseUploadDelete();
$response = UploadHelper::upload(
$this->getBaseUrl(),
$this->getActualUsername($user),
$this->getUserPassword($user),
$source,
$destination,
$this->getStepLineRef(),
$headers,
$this->getDavPathVersion(),
$doChunkUpload,
$noOfChunks,
);
$this->lastUploadDeleteTime = \time();
return $response;
}
/**
@@ -1662,7 +1664,7 @@ trait WebDav {
* @param boolean $async
* @param array|null $headers
*
* @return void
* @return ResponseInterface
*/
public function userUploadsAFileInChunk(
string $user,
@@ -1671,7 +1673,7 @@ trait WebDav {
int $noOfChunks = 2,
bool $async = false,
?array $headers = []
):void {
): ResponseInterface {
$user = $this->getActualUsername($user);
Assert::assertGreaterThan(
0,
@@ -1682,46 +1684,13 @@ trait WebDav {
if ($async === true) {
$headers['OC-LazyOps'] = 'true';
}
$this->uploadFileWithHeaders(
return $this->uploadFileWithHeaders(
$user,
$this->acceptanceTestsDirLocation() . $source,
$destination,
$headers,
$noOfChunks
);
$this->pushToLastStatusCodesArrays();
}
/**
* Uploading with old/new DAV and chunked/non-chunked.
* Except do not do the new-DAV-new-chunking combination. That is not being
* supported on all implementations.
*
* @When user :user uploads file :source to filenames based on :destination with all mechanisms using the WebDAV API
*
* @param string $user
* @param string $source
* @param string $destination
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userUploadsAFileToWithAllMechanismsExceptNewChunking(
string $user,
string $source,
string $destination
):void {
$user = $this->getActualUsername($user);
$this->uploadResponses = UploadHelper::uploadWithAllMechanisms(
$this->getBaseUrl(),
$this->getActualUsername($user),
$this->getUserPassword($user),
$this->acceptanceTestsDirLocation() . $source,
$destination,
$this->getStepLineRef(),
false,
);
}
/**
@@ -1741,24 +1710,9 @@ trait WebDav {
string $destination,
int $noOfChunks = 2
):void {
$this->userUploadsAFileInChunk($user, $source, $destination, $noOfChunks);
}
/**
* @Then /^the HTTP status code of all upload responses should be "([^"]*)"$/
*
* @param int $statusCode
*
* @return void
*/
public function theHTTPStatusCodeOfAllUploadResponsesShouldBe(int $statusCode):void {
foreach ($this->uploadResponses as $response) {
Assert::assertEquals(
$statusCode,
$response->getStatusCode(),
'Response did not return expected status code'
);
}
$response = $this->userUploadsAFileInChunk($user, $source, $destination, $noOfChunks);
$this->setResponse($response);
$this->pushToLastStatusCodesArrays();
}
/**
@@ -1950,32 +1904,6 @@ trait WebDav {
}
}
/**
* @Then /^the HTTP status code of all upload responses should be between "(\d+)" and "(\d+)"$/
*
* @param int $minStatusCode
* @param int $maxStatusCode
*
* @return void
*/
public function theHTTPStatusCodeOfAllUploadResponsesShouldBeBetween(
int $minStatusCode,
int $maxStatusCode
):void {
foreach ($this->uploadResponses as $response) {
Assert::assertGreaterThanOrEqual(
$minStatusCode,
$response->getStatusCode(),
'Response did not return expected status code'
);
Assert::assertLessThanOrEqual(
$maxStatusCode,
$response->getStatusCode(),
'Response did not return expected status code'
);
}
}
/**
* @param string $user
* @param string $destination
@@ -2193,6 +2121,7 @@ trait WebDav {
$this->getStepLineRef(),
["X-OC-Mtime" => $mtime],
$this->getDavPathVersion(),
false,
1,
$isGivenStep
);
@@ -2227,6 +2156,7 @@ trait WebDav {
$this->getStepLineRef(),
["X-OC-Mtime" => $mtime],
$this->getDavPathVersion(),
false,
1,
true
);

View File

@@ -20,12 +20,15 @@ Feature: dav-versions
| spaces |
Scenario: upload file and no version is available using various chunking methods
When user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms using the WebDAV API
Then the HTTP status code of all upload responses should be "201"
And the version folder of file "/davtest.txt-1dav-regular" for user "Alice" should contain "0" elements
And the version folder of file "/davtest.txt-2dav-regular" for user "Alice" should contain "0" elements
And the version folder of file "/davtest.txt-3dav-3chunking" for user "Alice" should contain "0" elements
Scenario Outline: no version is available while uploading a file with multiple chunks
Given using <dav-path-version> DAV path
When user "Alice" uploads file "filesForUpload/davtest.txt" to "lorem.txt" in 2 chunks using the WebDAV API
Then the version folder of file "lorem.txt" for user "Alice" should contain "0" elements
Examples:
| dav-path-version |
| old |
| new |
| spaces |
@smokeTest
Scenario Outline: upload a file twice and versions are available
@@ -42,13 +45,17 @@ Feature: dav-versions
| spaces |
Scenario: upload a file twice and versions are available using various chunking methods
When user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms using the WebDAV API
And user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms using the WebDAV API
Then the HTTP status code of all upload responses should be between "201" and "204"
And the version folder of file "/davtest.txt-1dav-regular" for user "Alice" should contain "1" element
And the version folder of file "/davtest.txt-2dav-regular" for user "Alice" should contain "1" element
And the version folder of file "/davtest.txt-3dav-3chunking" for user "Alice" should contain "1" element
Scenario Outline: versions are available while uploading a file twice with multiple chunks
Given using <dav-path-version> DAV path
When user "Alice" uploads file "filesForUpload/davtest.txt" to "lorem.txt" in 2 chunks using the WebDAV API
And user "Alice" uploads file "filesForUpload/davtest.txt" to "lorem.txt" in 3 chunks using the WebDAV API
Then the HTTP status code of responses on all endpoints should be "201"
And the version folder of file "lorem.txt" for user "Alice" should contain "1" element
Examples:
| dav-path-version |
| old |
| new |
| spaces |
@smokeTest
Scenario Outline: remove a file