Skip to content

Commit e4a8365

Browse files
committed
test(refactor): refactor some scenarios to the original and step definition
1 parent 4515240 commit e4a8365

File tree

3 files changed

+53
-163
lines changed

3 files changed

+53
-163
lines changed

tests/acceptance/TestHelpers/UploadHelper.php

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class UploadHelper extends Assert {
4646
* @param string|null $xRequestId
4747
* @param array|null $headers
4848
* @param int|null $davPathVersionToUse (1|2)
49+
* @param bool $doChunkUpload
4950
* @param int|null $noOfChunks how many chunks to upload
5051
* @param bool|null $isGivenStep
5152
*
@@ -61,10 +62,11 @@ public static function upload(
6162
?string $xRequestId = '',
6263
?array $headers = [],
6364
?int $davPathVersionToUse = 1,
65+
bool $doChunkUpload = false,
6466
?int $noOfChunks = 1,
65-
?bool $isGivenStep = false
67+
?bool $isGivenStep = false,
6668
): ResponseInterface {
67-
if ($noOfChunks === 1) {
69+
if (!$doChunkUpload) {
6870
$data = \file_get_contents($source);
6971
return WebDavHelper::makeDavRequest(
7072
$baseUrl,
@@ -127,55 +129,6 @@ public static function upload(
127129
return $result;
128130
}
129131

130-
/**
131-
* Upload the same file multiple times with different mechanisms.
132-
*
133-
* @param string|null $baseUrl URL of owncloud
134-
* @param string|null $user user who uploads
135-
* @param string|null $password
136-
* @param string|null $source source file path
137-
* @param string|null $destination destination path on the server
138-
* @param string|null $xRequestId
139-
* @param bool $overwriteMode when false creates separate files to test uploading brand-new files,
140-
* when true it just overwrites the same file over and over again with the same name
141-
*
142-
* @return array of ResponseInterface
143-
* @throws GuzzleException
144-
*/
145-
public static function uploadWithAllMechanisms(
146-
?string $baseUrl,
147-
?string $user,
148-
?string $password,
149-
?string $source,
150-
?string $destination,
151-
?string $xRequestId = '',
152-
?bool $overwriteMode = false,
153-
):array {
154-
$responses = [];
155-
foreach ([WebDavHelper::DAV_VERSION_OLD, WebDavHelper::DAV_VERSION_NEW, WebDavHelper::DAV_VERSION_SPACES] as $davPathVersion) {
156-
foreach ([false, true] as $chunkingUse) {
157-
$finalDestination = $destination;
158-
if (!$overwriteMode && $chunkingUse) {
159-
$finalDestination .= "-{$davPathVersion}dav-{$davPathVersion}chunking";
160-
} elseif (!$overwriteMode && !$chunkingUse) {
161-
$finalDestination .= "-{$davPathVersion}dav-regular";
162-
}
163-
$responses[] = self::upload(
164-
$baseUrl,
165-
$user,
166-
$password,
167-
$source,
168-
$finalDestination,
169-
$xRequestId,
170-
[],
171-
$davPathVersion,
172-
2
173-
);
174-
}
175-
}
176-
return $responses;
177-
}
178-
179132
/**
180133
* cut the file in multiple chunks
181134
* returns an array of chunks with the content of the file

tests/acceptance/bootstrap/WebDav.php

Lines changed: 29 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ public function userHasUploadedAFileTo(string $user, string $source, string $des
16241624
* @param array|null $headers
16251625
* @param int|null $noOfChunks Only use for chunked upload when $this->chunkingToUse is not null
16261626
*
1627-
* @return void
1627+
* @return ResponseInterface
16281628
* @throws Exception
16291629
*/
16301630
public function uploadFileWithHeaders(
@@ -1633,25 +1633,27 @@ public function uploadFileWithHeaders(
16331633
string $destination,
16341634
?array $headers = [],
16351635
?int $noOfChunks = 0
1636-
):void {
1637-
try {
1638-
$this->pauseUploadDelete();
1639-
$this->response = UploadHelper::upload(
1640-
$this->getBaseUrl(),
1641-
$this->getActualUsername($user),
1642-
$this->getUserPassword($user),
1643-
$source,
1644-
$destination,
1645-
$this->getStepLineRef(),
1646-
$headers,
1647-
$this->getDavPathVersion(),
1648-
$noOfChunks
1649-
);
1650-
$this->lastUploadDeleteTime = \time();
1651-
} catch (BadResponseException $e) {
1652-
// 4xx and 5xx responses cause an exception
1653-
$this->response = $e->getResponse();
1636+
): ResponseInterface {
1637+
$doChunkUpload = true;
1638+
if ($noOfChunks <= 0) {
1639+
$doChunkUpload = false;
16541640
}
1641+
1642+
$this->pauseUploadDelete();
1643+
$response = UploadHelper::upload(
1644+
$this->getBaseUrl(),
1645+
$this->getActualUsername($user),
1646+
$this->getUserPassword($user),
1647+
$source,
1648+
$destination,
1649+
$this->getStepLineRef(),
1650+
$headers,
1651+
$this->getDavPathVersion(),
1652+
$doChunkUpload,
1653+
$noOfChunks,
1654+
);
1655+
$this->lastUploadDeleteTime = \time();
1656+
return $response;
16551657
}
16561658

16571659
/**
@@ -1662,7 +1664,7 @@ public function uploadFileWithHeaders(
16621664
* @param boolean $async
16631665
* @param array|null $headers
16641666
*
1665-
* @return void
1667+
* @return ResponseInterface
16661668
*/
16671669
public function userUploadsAFileInChunk(
16681670
string $user,
@@ -1671,7 +1673,7 @@ public function userUploadsAFileInChunk(
16711673
int $noOfChunks = 2,
16721674
bool $async = false,
16731675
?array $headers = []
1674-
):void {
1676+
): ResponseInterface {
16751677
$user = $this->getActualUsername($user);
16761678
Assert::assertGreaterThan(
16771679
0,
@@ -1682,46 +1684,13 @@ public function userUploadsAFileInChunk(
16821684
if ($async === true) {
16831685
$headers['OC-LazyOps'] = 'true';
16841686
}
1685-
$this->uploadFileWithHeaders(
1687+
return $this->uploadFileWithHeaders(
16861688
$user,
16871689
$this->acceptanceTestsDirLocation() . $source,
16881690
$destination,
16891691
$headers,
16901692
$noOfChunks
16911693
);
1692-
$this->pushToLastStatusCodesArrays();
1693-
}
1694-
1695-
/**
1696-
* Uploading with old/new DAV and chunked/non-chunked.
1697-
* Except do not do the new-DAV-new-chunking combination. That is not being
1698-
* supported on all implementations.
1699-
*
1700-
* @When user :user uploads file :source to filenames based on :destination with all mechanisms using the WebDAV API
1701-
*
1702-
* @param string $user
1703-
* @param string $source
1704-
* @param string $destination
1705-
*
1706-
* @return void
1707-
* @throws Exception
1708-
* @throws GuzzleException
1709-
*/
1710-
public function userUploadsAFileToWithAllMechanismsExceptNewChunking(
1711-
string $user,
1712-
string $source,
1713-
string $destination
1714-
):void {
1715-
$user = $this->getActualUsername($user);
1716-
$this->uploadResponses = UploadHelper::uploadWithAllMechanisms(
1717-
$this->getBaseUrl(),
1718-
$this->getActualUsername($user),
1719-
$this->getUserPassword($user),
1720-
$this->acceptanceTestsDirLocation() . $source,
1721-
$destination,
1722-
$this->getStepLineRef(),
1723-
false,
1724-
);
17251694
}
17261695

17271696
/**
@@ -1741,24 +1710,9 @@ public function userUploadsAFileToWithChunks(
17411710
string $destination,
17421711
int $noOfChunks = 2
17431712
):void {
1744-
$this->userUploadsAFileInChunk($user, $source, $destination, $noOfChunks);
1745-
}
1746-
1747-
/**
1748-
* @Then /^the HTTP status code of all upload responses should be "([^"]*)"$/
1749-
*
1750-
* @param int $statusCode
1751-
*
1752-
* @return void
1753-
*/
1754-
public function theHTTPStatusCodeOfAllUploadResponsesShouldBe(int $statusCode):void {
1755-
foreach ($this->uploadResponses as $response) {
1756-
Assert::assertEquals(
1757-
$statusCode,
1758-
$response->getStatusCode(),
1759-
'Response did not return expected status code'
1760-
);
1761-
}
1713+
$response = $this->userUploadsAFileInChunk($user, $source, $destination, $noOfChunks);
1714+
$this->setResponse($response);
1715+
$this->pushToLastStatusCodesArrays();
17621716
}
17631717

17641718
/**
@@ -1950,32 +1904,6 @@ public function theUserShouldNotBeAbleToUploadFileTo(string $user, string $sourc
19501904
}
19511905
}
19521906

1953-
/**
1954-
* @Then /^the HTTP status code of all upload responses should be between "(\d+)" and "(\d+)"$/
1955-
*
1956-
* @param int $minStatusCode
1957-
* @param int $maxStatusCode
1958-
*
1959-
* @return void
1960-
*/
1961-
public function theHTTPStatusCodeOfAllUploadResponsesShouldBeBetween(
1962-
int $minStatusCode,
1963-
int $maxStatusCode
1964-
):void {
1965-
foreach ($this->uploadResponses as $response) {
1966-
Assert::assertGreaterThanOrEqual(
1967-
$minStatusCode,
1968-
$response->getStatusCode(),
1969-
'Response did not return expected status code'
1970-
);
1971-
Assert::assertLessThanOrEqual(
1972-
$maxStatusCode,
1973-
$response->getStatusCode(),
1974-
'Response did not return expected status code'
1975-
);
1976-
}
1977-
}
1978-
19791907
/**
19801908
* @param string $user
19811909
* @param string $destination
@@ -2193,6 +2121,7 @@ public function userUploadsFileToWithMtimeUsingTheWebdavApi(
21932121
$this->getStepLineRef(),
21942122
["X-OC-Mtime" => $mtime],
21952123
$this->getDavPathVersion(),
2124+
false,
21962125
1,
21972126
$isGivenStep
21982127
);
@@ -2227,6 +2156,7 @@ public function userHasUploadedFileToWithMtimeUsingTheWebdavApi(
22272156
$this->getStepLineRef(),
22282157
["X-OC-Mtime" => $mtime],
22292158
$this->getDavPathVersion(),
2159+
false,
22302160
1,
22312161
true
22322162
);

tests/acceptance/features/coreApiVersions/fileVersions.feature

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ Feature: dav-versions
2020
| spaces |
2121

2222

23-
Scenario: upload file and no version is available using various chunking methods
24-
When user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms using the WebDAV API
25-
Then the HTTP status code of all upload responses should be "201"
26-
And the version folder of file "/davtest.txt-1dav-regular" for user "Alice" should contain "0" elements
27-
And the version folder of file "/davtest.txt-2dav-regular" for user "Alice" should contain "0" elements
28-
And the version folder of file "/davtest.txt-3dav-3chunking" for user "Alice" should contain "0" elements
23+
Scenario Outline: no version is available while uploading a file with multiple chunks
24+
Given using <dav-path-version> DAV path
25+
When user "Alice" uploads file "filesForUpload/davtest.txt" to "lorem.txt" in 2 chunks using the WebDAV API
26+
Then the version folder of file "lorem.txt" for user "Alice" should contain "0" elements
27+
Examples:
28+
| dav-path-version |
29+
| old |
30+
| new |
31+
| spaces |
2932

3033
@smokeTest
3134
Scenario Outline: upload a file twice and versions are available
@@ -42,13 +45,17 @@ Feature: dav-versions
4245
| spaces |
4346

4447

45-
Scenario: upload a file twice and versions are available using various chunking methods
46-
When user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms using the WebDAV API
47-
And user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms using the WebDAV API
48-
Then the HTTP status code of all upload responses should be between "201" and "204"
49-
And the version folder of file "/davtest.txt-1dav-regular" for user "Alice" should contain "1" element
50-
And the version folder of file "/davtest.txt-2dav-regular" for user "Alice" should contain "1" element
51-
And the version folder of file "/davtest.txt-3dav-3chunking" for user "Alice" should contain "1" element
48+
Scenario Outline: versions are available while uploading a file twice with multiple chunks
49+
Given using <dav-path-version> DAV path
50+
When user "Alice" uploads file "filesForUpload/davtest.txt" to "lorem.txt" in 2 chunks using the WebDAV API
51+
And user "Alice" uploads file "filesForUpload/davtest.txt" to "lorem.txt" in 3 chunks using the WebDAV API
52+
Then the HTTP status code of responses on all endpoints should be "201"
53+
And the version folder of file "lorem.txt" for user "Alice" should contain "1" element
54+
Examples:
55+
| dav-path-version |
56+
| old |
57+
| new |
58+
| spaces |
5259

5360
@smokeTest
5461
Scenario Outline: remove a file

0 commit comments

Comments
 (0)