From 021fa50e9ddba1d17eb6cd3cdcee4131ea9e3243 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Thu, 11 Nov 2021 12:06:46 +0545 Subject: [PATCH] [tests-only] test downloading multiple items with archiver --- .../features/apiArchiver/downloadById.feature | 20 ++++++++++++ .../features/bootstrap/ArchiverContext.php | 31 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/tests/acceptance/features/apiArchiver/downloadById.feature b/tests/acceptance/features/apiArchiver/downloadById.feature index 0937e25ce..355783f62 100644 --- a/tests/acceptance/features/apiArchiver/downloadById.feature +++ b/tests/acceptance/features/apiArchiver/downloadById.feature @@ -41,3 +41,23 @@ Feature: download multiple resources bundled into an archive | user-agent | archive-type | | Linux | tar | | Windows NT | zip | + + Scenario: download multiple files and folders + Given user "Alice" has uploaded file with content "some data" to "/textfile0.txt" + And user "Alice" has uploaded file with content "other data" to "/textfile1.txt" + And user "Alice" has created folder "my_data" + And user "Alice" has uploaded file with content "some data" to "/my_data/textfile2.txt" + And user "Alice" has created folder "more_data" + And user "Alice" has uploaded file with content "more data" to "/more_data/an_other_file.txt" + When user "Alice" downloads the archive of these items using the resource ids + | textfile0.txt | + | textfile1.txt | + | my_data | + | more_data | + Then the HTTP status code should be "200" + And the downloaded tar archive should contain these files: + | name | content | + | textfile0.txt | some data | + | textfile1.txt | other data | + | my_data/textfile2.txt | some data | + | more_data/an_other_file.txt | more data | diff --git a/tests/acceptance/features/bootstrap/ArchiverContext.php b/tests/acceptance/features/bootstrap/ArchiverContext.php index f55540b62..4202c26b6 100644 --- a/tests/acceptance/features/bootstrap/ArchiverContext.php +++ b/tests/acceptance/features/bootstrap/ArchiverContext.php @@ -99,6 +99,37 @@ class ArchiverContext implements Context { ); } + /** + * @When user :arg1 downloads the archive of these items using the resource ids + * + * @param string $user + * @param TableNode $items + * + * @return void + * + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function userDownloadsTheArchiveOfTheseItemsUsingTheResourceIds( + string $user, + TableNode $items + ): void { + $user = $this->featureContext->getActualUsername($user); + $resourceIdsString = ''; + foreach ($items->getRows() as $item) { + $fileId = $this->featureContext->getFileIdForPath($user, $item[0]); + $resourceIdsString .= 'id=' . $fileId . '&'; + } + $resourceIdsString = \rtrim($resourceIdsString, '&'); + $this->featureContext->setResponse( + HttpRequestHelper::get( + $this->featureContext->getBaseUrl() . '/archiver?' . $resourceIdsString, + '', + $user, + $this->featureContext->getPasswordForUser($user), + ) + ); + } + /** * @Then the downloaded :type archive should contain these files: *