-
Notifications
You must be signed in to change notification settings - Fork 187
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] [full-ci] add test for downloading space #6683
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@api | ||
Feature: Download space | ||
As a user | ||
I want to download space | ||
So that I can store it locally | ||
|
||
|
||
Scenario: user downloads a space | ||
Given user "Alice" has been created with default attributes and without skeleton files | ||
And using spaces DAV path | ||
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API | ||
amrita-shrestha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
And user "Alice" has created a space "Project-space" with the default quota using the GraphApi | ||
And user "Alice" has uploaded a file inside space "Project-space" with content "some data" to "file1.txt" | ||
And user "Alice" has uploaded a file inside space "Project-space" with content "other data" to "file2.txt" | ||
And user "Alice" has uploaded a file inside space "Project-space" with content "more data" to "file3.txt" | ||
And user "Alice" has created a folder ".space" in space "Project-space" | ||
And user "Alice" has uploaded a file inside space "Project-space" with content "space description" to ".space/readme.md" | ||
When user "Alice" downloads the space "Project-space" using the WebDAV API | ||
Then the HTTP status code should be "200" | ||
And the downloaded "tar" archive should contain these files: | ||
amrita-shrestha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| name | content | | ||
| file1.txt | some data | | ||
| file2.txt | other data | | ||
| file3.txt | more data | | ||
| .space/readme.md | space description | |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
use GuzzleHttp\Exception\GuzzleException; | ||
use TestHelpers\HttpRequestHelper; | ||
use TestHelpers\SetupHelper; | ||
use wapmorgan\UnifiedArchive\UnifiedArchive; | ||
use PHPUnit\Framework\Assert; | ||
use \Psr\Http\Message\ResponseInterface; | ||
|
||
|
@@ -219,18 +218,41 @@ public function userDownloadsTheArchiveOfTheseItems( | |
*/ | ||
public function theDownloadedArchiveShouldContainTheseFiles(string $type, TableNode $expectedFiles):void { | ||
$this->featureContext->verifyTableNodeColumns($expectedFiles, ['name', 'content']); | ||
$contents = $this->featureContext->getResponse()->getBody()->getContents(); | ||
$tempFile = \tempnam(\sys_get_temp_dir(), 'OcAcceptanceTests_'); | ||
\unlink($tempFile); // we only need the name | ||
$tempFile = $tempFile . '.' . $type; // it needs the extension | ||
\file_put_contents($tempFile, $this->featureContext->getResponse()->getBody()->getContents()); | ||
$archive = UnifiedArchive::open($tempFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While downloading space, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. downloaded space archive has So, we implemented this new way to check folder/file existence as well as the content of the file |
||
foreach ($expectedFiles->getHash() as $expectedFile) { | ||
Assert::assertEquals( | ||
$expectedFile['content'], | ||
$archive->getFileContent($expectedFile['name']), | ||
__METHOD__ . | ||
" content of '" . $expectedFile['name'] . "' not as expected" | ||
); | ||
\file_put_contents($tempFile, $contents); | ||
|
||
// open the archive | ||
$archiveData = new RecursiveIteratorIterator( | ||
new PharData($tempFile), | ||
RecursiveIteratorIterator::SELF_FIRST | ||
); | ||
foreach ($expectedFiles->getHash() as $expectedItem) { | ||
$expectedPath = trim($expectedItem['name'], "/"); | ||
$found = false; | ||
foreach ($archiveData as $info) { | ||
// get only the parent folder path for the given item | ||
$actualPath = explode(".$type", $info->getPathname())[1]; | ||
$actualPath = trim($actualPath, "/"); | ||
|
||
if ($expectedPath === $actualPath) { | ||
if (!$info->isDir()) { | ||
Assert::assertEquals( | ||
$expectedItem['content'], | ||
$info->getContent(), | ||
__METHOD__ . | ||
" content of '" . $expectedPath . "' not as expected" | ||
); | ||
} | ||
$found = true; | ||
break; | ||
} | ||
} | ||
if (!$found) { | ||
Assert::fail("Resource '" . $expectedPath . "' is not in the downloaded archive."); | ||
} | ||
} | ||
\unlink($tempFile); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saw-jan what about adding test coverage for users tries to download space share with permission can edit and can manage? Will it be too much?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be easy with examples table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But let's do it int next PR. This pr is almost a month old.
Scenarios to add: