Skip to content

Commit 367f551

Browse files
add test to download files and folders as archive
Signed-off-by: prashant-gurung899 <prasantgrg777@gmail.com>
1 parent e22c355 commit 367f551

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

tests/acceptance/bootstrap/ArchiverContext.php

+22-9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ArchiverContext implements Context {
4343
* @var FeatureContext
4444
*/
4545
private FeatureContext $featureContext;
46+
private SpacesContext $spacesContext;
4647

4748
/**
4849
* @BeforeScenario
@@ -58,6 +59,7 @@ public function before(BeforeScenarioScope $scope): void {
5859
$environment = $scope->getEnvironment();
5960
// Get all the contexts you need in this context
6061
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
62+
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
6163
}
6264

6365
/**
@@ -120,13 +122,15 @@ private function getArchiverQueryString(
120122
case 'id':
121123
case 'ids':
122124
return 'id=' . $this->featureContext->getFileIdForPath($user, $resource);
125+
case 'remoteItemIds':
126+
return 'id=' . $this->spacesContext->getSharesRemoteItemId($user, $resource);
123127
case 'path':
124128
case 'paths':
125129
return 'path=' . $resource;
126130
default:
127131
throw new Exception(
128132
'"' . $addressType .
129-
'" is not a legal value for $addressType, must be id|ids|path|paths'
133+
'" is not a legal value for $addressType, must be id|ids|remoteItemIds|path|paths'
130134
);
131135
}
132136
}
@@ -276,7 +280,7 @@ public function theDownloadedArchiveShouldContainTheseFiles(string $type, TableN
276280
$tar = $this->getArchiveClass($type);
277281
$tar->open($tempFile);
278282
$archiveData = $tar->contents();
279-
283+
280284
// extract the archive
281285
$tar->open($tempFile);
282286
$tar->extract($tempExtractFolder);
@@ -291,13 +295,22 @@ public function theDownloadedArchiveShouldContainTheseFiles(string $type, TableN
291295

292296
if ($expectedPath === $actualPath) {
293297
if (!$info->getIsdir()) {
294-
$fileContent = \file_get_contents("$tempExtractFolder/$actualPath");
295-
Assert::assertEquals(
296-
$expectedItem['content'],
297-
$fileContent,
298-
__METHOD__ .
299-
" content of '" . $expectedPath . "' not as expected"
300-
);
298+
$fileFullPath = "$tempExtractFolder/$actualPath";
299+
$fileMimeType = \mime_content_type($fileFullPath);
300+
301+
if ($fileMimeType === "text/plain") {
302+
$fileContent = \file_get_contents($fileFullPath);
303+
Assert::assertEquals(
304+
$expectedItem['content'],
305+
$fileContent,
306+
__METHOD__ . " content of '" . $expectedPath . "' not as expected"
307+
);
308+
} else {
309+
Assert::assertFileExists(
310+
$fileFullPath,
311+
__METHOD__ . " File '" . $expectedPath . "' is not in the downloaded archive."
312+
);
313+
}
301314
}
302315
$found = true;
303316
break;

tests/acceptance/features/apiOcm/share.feature

+33
Original file line numberDiff line numberDiff line change
@@ -1297,3 +1297,36 @@ Feature: an user shares resources using ScienceMesh application
12971297
| Viewer |
12981298
| Uploader |
12991299
| Editor |
1300+
1301+
@issue-10272
1302+
Scenario: federated user downloads shared resources as an archive
1303+
Given using spaces DAV path
1304+
And using server "REMOTE"
1305+
And "Brian" has created the federation share invitation
1306+
And using server "LOCAL"
1307+
And "Alice" has accepted invitation
1308+
And user "Alice" has uploaded file with content "some data" to "textfile.txt"
1309+
And user "Alice" has created folder "imageFolder"
1310+
And user "Alice" has uploaded file "filesForUpload/testavatar.png" to "imageFolder/testavatar.png"
1311+
And user "Alice" has sent the following resource share invitation to federated user:
1312+
| resource | textfile.txt |
1313+
| space | Personal |
1314+
| sharee | Brian |
1315+
| shareType | user |
1316+
| permissionsRole | Viewer |
1317+
And user "Alice" has sent the following resource share invitation to federated user:
1318+
| resource | imageFolder |
1319+
| space | Personal |
1320+
| sharee | Brian |
1321+
| shareType | user |
1322+
| permissionsRole | Viewer |
1323+
And using server "REMOTE"
1324+
When user "Brian" downloads the archive of these items using the resource remoteItemIds
1325+
| textfile.txt |
1326+
| imageFolder |
1327+
Then the HTTP status code should be "200"
1328+
And the downloaded zip archive should contain these files:
1329+
| name | content |
1330+
| textfile.txt | some data |
1331+
| imageFolder | |
1332+
| imageFolder/testavatar.png | |

0 commit comments

Comments
 (0)