Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] test zip archive download #2744

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions tests/acceptance/features/apiArchiver/downloadById.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,33 @@ Feature: download multiple resources bundled into an archive
Background:
Given user "Alice" has been created with default attributes and without skeleton files

Scenario: download a single file
Scenario Outline: download a single file
Given user "Alice" has uploaded file with content "some data" to "/textfile0.txt"
When user "Alice" downloads the archive of "/textfile0.txt" using the resource id
When user "Alice" downloads the archive of "/textfile0.txt" using the resource id and setting these headers
| header | value |
| User-Agent | <user-agent> |
Then the HTTP status code should be "200"
And the downloaded archive should contain these files:
And the downloaded <archive-type> archive should contain these files:
| name | content |
| textfile0.txt | some data |
Examples:
| user-agent | archive-type |
| Linux | tar |
| Windows NT | zip |

Scenario: download a single folder
Scenario Outline: download a single folder
Given user "Alice" has created folder "my_data"
And user "Alice" has uploaded file with content "some data" to "/my_data/textfile0.txt"
And user "Alice" has uploaded file with content "more data" to "/my_data/an_other_file.txt"
When user "Alice" downloads the archive of "/my_data" using the resource id
When user "Alice" downloads the archive of "/my_data" using the resource id and setting these headers
| header | value |
| User-Agent | <user-agent> |
Then the HTTP status code should be "200"
And the downloaded archive should contain these files:
And the downloaded <archive-type> archive should contain these files:
| name | content |
| my_data/textfile0.txt | some data |
| my_data/an_other_file.txt | more data |
Examples:
| user-agent | archive-type |
| Linux | tar |
| Windows NT | zip |
27 changes: 21 additions & 6 deletions tests/acceptance/features/bootstrap/ArchiverContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,57 @@ public function setUpScenario(BeforeScenarioScope $scope): void {
}

/**
* @When user :user downloads the archive of :resourceId using the resource id
* @When user :user downloads the archive of :resourceId using the resource id and setting these headers
*
* @param string $user
* @param string $resource
* @param TableNode $headersTable
*
* @return void
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function userDownloadsTheArchiveOfUsingTheResourceId(string $user, string $resource): void {
public function userDownloadsTheArchiveOfUsingTheResourceId(
string $user,
string $resource,
TableNode $headersTable
): void {
$this->featureContext->verifyTableNodeColumns(
$headersTable,
['header', 'value']
);
$headers = [];
foreach ($headersTable as $row) {
$headers[$row['header']] = $row ['value'];
}
$resourceId = $this->featureContext->getFileIdForPath($user, $resource);
$user = $this->featureContext->getActualUsername($user);
$this->featureContext->setResponse(
HttpRequestHelper::get(
$this->featureContext->getBaseUrl() . '/archiver?id=' . $resourceId,
'',
$user,
$this->featureContext->getPasswordForUser($user)
$this->featureContext->getPasswordForUser($user),
$headers
)
);
}

/**
* @Then the downloaded archive should contain these files:
* @Then the downloaded :type archive should contain these files:
*
* @param string $type
* @param TableNode $expectedFiles
*
* @return void
*
* @throws Exception
*/
public function theDownloadedArchiveShouldContainTheseFiles(TableNode $expectedFiles) {
public function theDownloadedArchiveShouldContainTheseFiles(string $type, TableNode $expectedFiles) {
$this->featureContext->verifyTableNodeColumns($expectedFiles, ['name', 'content']);
$tempFile = \tempnam(\sys_get_temp_dir(), 'OcAcceptanceTests_');
\unlink($tempFile); // we only need the name
$tempFile = $tempFile . '.tar'; // it needs the extension
$tempFile = $tempFile . '.' . $type; // it needs the extension
\file_put_contents($tempFile, $this->featureContext->getResponse()->getBody()->getContents());
$archive = UnifiedArchive::open($tempFile);
foreach ($expectedFiles->getHash() as $expectedFile) {
Expand Down