Skip to content

Commit 4515240

Browse files
committed
test(refactor): remove variable in other code
1 parent 3b9ee2e commit 4515240

File tree

4 files changed

+27
-175
lines changed

4 files changed

+27
-175
lines changed

tests/acceptance/TestHelpers/UploadHelper.php

Lines changed: 14 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ class UploadHelper extends Assert {
4646
* @param string|null $xRequestId
4747
* @param array|null $headers
4848
* @param int|null $davPathVersionToUse (1|2)
49-
* @param int|null $chunkingVersion (1|2|null)
50-
* if set to null chunking will not be used
5149
* @param int|null $noOfChunks how many chunks to upload
5250
* @param bool|null $isGivenStep
5351
*
@@ -63,12 +61,10 @@ public static function upload(
6361
?string $xRequestId = '',
6462
?array $headers = [],
6563
?int $davPathVersionToUse = 1,
66-
?int $chunkingVersion = null,
6764
?int $noOfChunks = 1,
6865
?bool $isGivenStep = false
6966
): ResponseInterface {
70-
//simple upload with no chunking
71-
if ($chunkingVersion === null) {
67+
if ($noOfChunks === 1) {
7268
$data = \file_get_contents($source);
7369
return WebDavHelper::makeDavRequest(
7470
$baseUrl,
@@ -91,56 +87,16 @@ public static function upload(
9187
null,
9288
$isGivenStep
9389
);
94-
} else {
95-
//prepare chunking
96-
$chunks = self::chunkFile($source, $noOfChunks);
97-
$chunkingId = 'chunking-' . \rand(1000, 9999);
98-
$v2ChunksDestination = '/uploads/' . $user . '/' . $chunkingId;
9990
}
10091

92+
//prepare chunking
93+
$chunks = self::chunkFile($source, $noOfChunks);
94+
$chunkingId = 'chunking-' . \rand(1000, 9999);
10195
$result = null;
10296

103-
//prepare chunking version specific stuff
104-
if ($chunkingVersion === 1) {
105-
$headers['OC-Chunked'] = '1';
106-
} elseif ($chunkingVersion === 2) {
107-
$result = WebDavHelper::makeDavRequest(
108-
$baseUrl,
109-
$user,
110-
$password,
111-
'MKCOL',
112-
$v2ChunksDestination,
113-
$headers,
114-
null,
115-
$xRequestId,
116-
null,
117-
$davPathVersionToUse,
118-
"uploads",
119-
null,
120-
"basic",
121-
false,
122-
0,
123-
null,
124-
[],
125-
null,
126-
$isGivenStep
127-
);
128-
if ($result->getStatusCode() >= 400) {
129-
return $result;
130-
}
131-
}
132-
13397
//upload chunks
13498
foreach ($chunks as $index => $chunk) {
135-
if ($chunkingVersion === 1) {
136-
$filename = $destination . "-" . $chunkingId . "-" .
137-
\count($chunks) . '-' . $index;
138-
$davRequestType = "files";
139-
} else {
140-
// do chunking version 2
141-
$filename = $v2ChunksDestination . '/' . $index;
142-
$davRequestType = "uploads";
143-
}
99+
$filename = $destination . "-" . $chunkingId . "-" . \count($chunks) . '-' . $index;
144100
$result = WebDavHelper::makeDavRequest(
145101
$baseUrl,
146102
$user,
@@ -152,38 +108,7 @@ public static function upload(
152108
$xRequestId,
153109
$chunk,
154110
$davPathVersionToUse,
155-
$davRequestType,
156-
null,
157-
"basic",
158-
false,
159-
0,
160-
null,
161-
[],
162-
null,
163-
$isGivenStep
164-
);
165-
if ($result->getStatusCode() >= 400) {
166-
return $result;
167-
}
168-
}
169-
//finish upload for new chunking
170-
if ($chunkingVersion === 2) {
171-
$source = $v2ChunksDestination . '/.file';
172-
$headers['Destination'] = $baseUrl . "/" .
173-
WebDavHelper::getDavPath($davPathVersionToUse, $user) .
174-
$destination;
175-
$result = WebDavHelper::makeDavRequest(
176-
$baseUrl,
177-
$user,
178-
$password,
179-
'MOVE',
180-
$source,
181-
$headers,
182-
null,
183-
$xRequestId,
184-
null,
185-
$davPathVersionToUse,
186-
"uploads",
111+
"files",
187112
null,
188113
"basic",
189114
false,
@@ -197,7 +122,8 @@ public static function upload(
197122
return $result;
198123
}
199124
}
200-
self::assertNotNull($result, __METHOD__ . " chunking version $chunkingVersion was requested but no upload was done.");
125+
126+
self::assertNotNull($result, __METHOD__ . " chunking was requested but no upload was done.");
201127
return $result;
202128
}
203129

@@ -212,7 +138,6 @@ public static function upload(
212138
* @param string|null $xRequestId
213139
* @param bool $overwriteMode when false creates separate files to test uploading brand-new files,
214140
* when true it just overwrites the same file over and over again with the same name
215-
* @param string|null $exceptChunkingType empty string or "old" or "new"
216141
*
217142
* @return array of ResponseInterface
218143
* @throws GuzzleException
@@ -225,44 +150,15 @@ public static function uploadWithAllMechanisms(
225150
?string $destination,
226151
?string $xRequestId = '',
227152
?bool $overwriteMode = false,
228-
?string $exceptChunkingType = ''
229153
):array {
230154
$responses = [];
231-
foreach ([1, 2] as $davPathVersion) {
232-
if ($davPathVersion === 1) {
233-
$davHuman = 'old';
234-
} else {
235-
$davHuman = 'new';
236-
}
237-
238-
switch ($exceptChunkingType) {
239-
case 'old':
240-
$exceptChunkingVersion = 1;
241-
break;
242-
case 'new':
243-
$exceptChunkingVersion = 2;
244-
break;
245-
default:
246-
$exceptChunkingVersion = -1;
247-
break;
248-
}
249-
250-
foreach ([null, 1, 2] as $chunkingVersion) {
251-
if ($chunkingVersion === $exceptChunkingVersion) {
252-
continue;
253-
}
254-
$valid = WebDavHelper::isValidDavChunkingCombination(
255-
$davPathVersion,
256-
$chunkingVersion
257-
);
258-
if ($valid === false) {
259-
continue;
260-
}
155+
foreach ([WebDavHelper::DAV_VERSION_OLD, WebDavHelper::DAV_VERSION_NEW, WebDavHelper::DAV_VERSION_SPACES] as $davPathVersion) {
156+
foreach ([false, true] as $chunkingUse) {
261157
$finalDestination = $destination;
262-
if (!$overwriteMode && $chunkingVersion !== null) {
263-
$finalDestination .= "-{$davHuman}dav-{$davHuman}chunking";
264-
} elseif (!$overwriteMode && $chunkingVersion === null) {
265-
$finalDestination .= "-{$davHuman}dav-regular";
158+
if (!$overwriteMode && $chunkingUse) {
159+
$finalDestination .= "-{$davPathVersion}dav-{$davPathVersion}chunking";
160+
} elseif (!$overwriteMode && !$chunkingUse) {
161+
$finalDestination .= "-{$davPathVersion}dav-regular";
266162
}
267163
$responses[] = self::upload(
268164
$baseUrl,
@@ -273,7 +169,6 @@ public static function uploadWithAllMechanisms(
273169
$xRequestId,
274170
[],
275171
$davPathVersion,
276-
$chunkingVersion,
277172
2
278173
);
279174
}

tests/acceptance/TestHelpers/WebDavHelper.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -816,34 +816,6 @@ public static function sanitizeUrl(?string $url, ?bool $trailingSlash = false):s
816816
return \preg_replace("/([^:]\/)\/+/", '$1', $url);
817817
}
818818

819-
/**
820-
* Decides if the proposed dav version and chunking version are
821-
* a valid combination.
822-
* If no chunkingVersion is specified, then any dav version is valid.
823-
* If a chunkingVersion is specified, then it has to match the dav version.
824-
* Note: in future, the dav and chunking versions might or might not
825-
* move together and/or be supported together. So a more complex
826-
* matrix could be needed here.
827-
*
828-
* @param string|int $davPathVersion
829-
* @param string|int|null $chunkingVersion
830-
*
831-
* @return boolean is this a valid combination
832-
*/
833-
public static function isValidDavChunkingCombination(
834-
$davPathVersion,
835-
$chunkingVersion
836-
): bool {
837-
if ($davPathVersion === self::DAV_VERSION_SPACES) {
838-
// allow only old chunking version when using the spaces dav
839-
return $chunkingVersion === 1;
840-
}
841-
return (
842-
($chunkingVersion === 'no' || $chunkingVersion === null) ||
843-
($davPathVersion === $chunkingVersion)
844-
);
845-
}
846-
847819
/**
848820
* get Mtime of File in a public link share
849821
*

tests/acceptance/bootstrap/WebDav.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,6 @@ public function uploadFileWithHeaders(
16451645
$this->getStepLineRef(),
16461646
$headers,
16471647
$this->getDavPathVersion(),
1648-
$noOfChunks <= 0 ? null : 1,
16491648
$noOfChunks
16501649
);
16511650
$this->lastUploadDeleteTime = \time();
@@ -1698,14 +1697,15 @@ public function userUploadsAFileInChunk(
16981697
* Except do not do the new-DAV-new-chunking combination. That is not being
16991698
* supported on all implementations.
17001699
*
1701-
* @When user :user uploads file :source to filenames based on :destination with all mechanisms except new chunking using the WebDAV API
1700+
* @When user :user uploads file :source to filenames based on :destination with all mechanisms using the WebDAV API
17021701
*
17031702
* @param string $user
17041703
* @param string $source
17051704
* @param string $destination
17061705
*
17071706
* @return void
17081707
* @throws Exception
1708+
* @throws GuzzleException
17091709
*/
17101710
public function userUploadsAFileToWithAllMechanismsExceptNewChunking(
17111711
string $user,
@@ -1721,7 +1721,6 @@ public function userUploadsAFileToWithAllMechanismsExceptNewChunking(
17211721
$destination,
17221722
$this->getStepLineRef(),
17231723
false,
1724-
'new'
17251724
);
17261725
}
17271726

@@ -2194,7 +2193,6 @@ public function userUploadsFileToWithMtimeUsingTheWebdavApi(
21942193
$this->getStepLineRef(),
21952194
["X-OC-Mtime" => $mtime],
21962195
$this->getDavPathVersion(),
2197-
null,
21982196
1,
21992197
$isGivenStep
22002198
);
@@ -2229,7 +2227,6 @@ public function userHasUploadedFileToWithMtimeUsingTheWebdavApi(
22292227
$this->getStepLineRef(),
22302228
["X-OC-Mtime" => $mtime],
22312229
$this->getDavPathVersion(),
2232-
null,
22332230
1,
22342231
true
22352232
);

tests/acceptance/features/coreApiVersions/fileVersions.feature

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

2222

23-
Scenario Outline: upload file and no version is available using various chunking methods (except new chunking)
24-
Given using <dav-path-version> DAV path
25-
When user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms except new chunking using the WebDAV API
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
2625
Then the HTTP status code of all upload responses should be "201"
27-
And the version folder of file "/davtest.txt-olddav-regular" for user "Alice" should contain "0" elements
28-
And the version folder of file "/davtest.txt-newdav-regular" for user "Alice" should contain "0" elements
29-
And the version folder of file "/davtest.txt-olddav-oldchunking" for user "Alice" should contain "0" elements
30-
Examples:
31-
| dav-path-version |
32-
| old |
33-
| new |
34-
| spaces |
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
3529

3630
@smokeTest
3731
Scenario Outline: upload a file twice and versions are available
@@ -48,19 +42,13 @@ Feature: dav-versions
4842
| spaces |
4943

5044

51-
Scenario Outline: upload a file twice and versions are available using various chunking methods (except new chunking)
52-
Given using <dav-path-version> DAV path
53-
When user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms except new chunking using the WebDAV API
54-
And user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms except new chunking using the WebDAV API
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
5548
Then the HTTP status code of all upload responses should be between "201" and "204"
56-
And the version folder of file "/davtest.txt-olddav-regular" for user "Alice" should contain "1" element
57-
And the version folder of file "/davtest.txt-newdav-regular" for user "Alice" should contain "1" element
58-
And the version folder of file "/davtest.txt-olddav-oldchunking" for user "Alice" should contain "1" element
59-
Examples:
60-
| dav-path-version |
61-
| old |
62-
| new |
63-
| spaces |
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
6452

6553
@smokeTest
6654
Scenario Outline: remove a file

0 commit comments

Comments
 (0)