diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 98c60cf2e9c..4ea8891c0e6 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -55,6 +55,7 @@ default: - SpacesTUSContext: - GraphContext: - OcisConfigContext: + - ArchiverContext: apiSpacesShares: paths: diff --git a/tests/acceptance/features/apiSpaces/space_download.feature b/tests/acceptance/features/apiSpaces/space_download.feature new file mode 100644 index 00000000000..55628e03b4c --- /dev/null +++ b/tests/acceptance/features/apiSpaces/space_download.feature @@ -0,0 +1,21 @@ +@api +Feature: Download space + As a user + I want to be able to download space + so that I can have it in my local storage + + + Scenario: user downloads a space + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + And using spaces DAV path + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "download space" with the default quota using the GraphApi + And user "Alice" has uploaded a file inside space "download space" with content "" to "" + When user "Alice" downloads the space "download space" using the WebDAV API + Then the downloaded "tar" archive should contain these files: + | name | content | + | file1.txt | some data | + | file2.txt | other data | + | file3.txt | more data | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 3c446abc63b..1ff39c700e3 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3180,4 +3180,77 @@ public function theUserShouldHaveSpaceWithRecipient( } Assert::assertTrue($foundRoleInResponse, "the response does not contain the $recipientType $recipient"); } + + /** + * @When /^user "([^"]*)" downloads the space "([^"]*)" using the WebDAV API/ + * + * @param string $user + * @param string $spaceName + * @throws Exception + * @throws GuzzleException + */ + public function userDownloadsTheSpaceUsingTheWebdavApi(string $user, string $spaceName) { + echo $user; + echo $spaceName."\n"; + $space = $this->getSpaceByName($user, $spaceName); + echo $space["id"] ."\n"; + $url = $this->featureContext->getBaseUrl() . '/archiver?id=' . $space["id"]; + echo $url ."\n"; + $response = HttpRequestHelper::get( + $url, + '', + $user, + $this->featureContext->getPasswordForUser($user), + ); + echo $response->getStatusCode()."\n"; + echo $response->getBody()->getContents()."\n"; + $this->featureContext->setResponse( + HttpRequestHelper::get( + $url, + '', + $user, + $this->featureContext->getPasswordForUser($user), + ) + ); + + } + + // /** + // * @Then /^the downloaded "([^"]*)" archive should contain these files:/ + // * + // * @param string $type + // * @param TableNode $expectedFiles + // * @throws NonExistentArchiveFileException + // */ + // public function theDownloadedTarArchiveShouldContainTheseFiles(string $type, TableNode $expectedFiles) + // { + // $res = $this->featureContext->getResponse(); + // echo $res->getBody()->getContents(); +// + // $tempFile = \tempnam(\sys_get_temp_dir(), 'OcAcceptanceTests_'); + // echo($tempFile."\n"); +// + // \unlink($tempFile); // we only need the name + // $tempFile = $tempFile . '.' . $type; // it needs the extension + // \file_put_contents($tempFile, $this->featureContext->getResponse()->getBody()->getContents()); + //// echo $tempFile."\n"; + // print_r(scandir(\sys_get_temp_dir())); + //// $archive = new PharData($tempFile.".tar"); + //// foreach($archive as $file) { + //// echo "$file\n"; + //// } + // $archive = UnifiedArchive::open($tempFile); + // foreach ($expectedFiles->getHash() as $expectedFile) { + // echo $expectedFiles; + // echo $expectedFile['content']; + // echo ($archive->getFileContent($expectedFile['name'])); + // Assert::assertEquals( + // $expectedFile['content'], + // $archive->getFileContent($expectedFile['name']), + // __METHOD__ . + // " content of '" . $expectedFile['name'] . "' not as expected" + // ); + // } + //// \unlink($tempFile); + // } }