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][full-ci] Backport refactoring webdav context removing setresponse() in given/then step #7480

Merged
merged 2 commits into from
Oct 13, 2023
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
2 changes: 1 addition & 1 deletion tests/acceptance/features/apiAntivirus/antivirus.feature
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ Feature: antivirus
And user "Alice" has created a space "new-space" with the default quota using the GraphApi
And user "Alice" has created a folder ".space" in space "new-space"
And user "Alice" has uploaded a file inside space "new-space" with content "Here you can add a description for this Space." to ".space/readme.md"
And user "Alice" has uploaded a file inside space "new-space" with content "X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" to ".space/readme.md"
When user "Alice" uploads a file inside space "new-space" with content "X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" to ".space/readme.md" using the WebDAV API
Then the HTTP status code should be "204"
And user "Alice" should get a notification with subject "Virus found" and message:
| message |
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3189,7 +3189,7 @@ public function restoreAdminPassword(): void {
*/
public function deleteAllResourceCreatedByAdmin(): void {
foreach ($this->adminResources as $resource) {
$this->userDeletesFile("admin", $resource);
$this->deleteFile("admin", $resource);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2525,8 +2525,8 @@ function (&$value, $key) {
*/
public function userDownloadsFailWithMessage(string $fileName, string $user, PyStringNode $errorMessage):void {
$user = $this->getActualUsername($user);
$this->downloadFileAsUserUsingPassword($user, $fileName);
$receivedErrorMessage = $this->getResponseXml(null, __METHOD__)->xpath('//s:message');
$response = $this->downloadFileAsUserUsingPassword($user, $fileName);
$receivedErrorMessage = $this->getResponseXml($response, __METHOD__)->xpath('//s:message');
Assert::assertEquals(
$errorMessage,
(string) $receivedErrorMessage[0],
Expand Down
77 changes: 54 additions & 23 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ public function theUserCreatesAFolderUsingTheGraphApi(
string $folder,
string $spaceName
): void {
$folder = \trim($folder, '/');
$exploded = explode('/', $folder);
$path = '';
for ($i = 0; $i < \count($exploded); $i++) {
Expand Down Expand Up @@ -1121,19 +1122,48 @@ public function theUserTriesToCreateASubFolderUsingTheGraphApi(
*
* @throws GuzzleException
*/
public function theUserHasCreateAFolderUsingTheGraphApi(
public function userHasCreatedAFolderInSpace(
string $user,
string $folder,
string $spaceName
): void {
$this->theUserCreatesAFolderUsingTheGraphApi($user, $folder, $spaceName);

$folder = \trim($folder, '/');
$paths = explode('/', $folder);
$folderPath = '';
foreach ($paths as $path) {
$folderPath .= "$path/";
$response = $this->createFolderInSpace($user, $folderPath, $spaceName);
}
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201"
"Expected response status code should be 201",
$response
);
}

/**
* @param string $user
* @param string $folder
* @param string $spaceName
* @param string $ownerUser
*
* @return ResponseInterface
*
* @throws GuzzleException
*/
public function createFolderInSpace(
string $user,
string $folder,
string $spaceName,
string $ownerUser = ''
): ResponseInterface {
if ($ownerUser === '') {
$ownerUser = $user;
}
$this->setSpaceIDByName($ownerUser, $spaceName);
return $this->featureContext->createFolder($user, $folder);
}

/**
* @When /^user "([^"]*)" creates a folder "([^"]*)" in space "([^"]*)" owned by the user "([^"]*)" using the WebDav Api$/
*
Expand All @@ -1152,11 +1182,7 @@ public function theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi(
string $spaceName,
string $ownerUser = ''
): void {
if ($ownerUser === '') {
$ownerUser = $user;
}
$this->setSpaceIDByName($ownerUser, $spaceName);
$response = $this->featureContext->createFolder($user, $folder);
$response = $this->createFolderInSpace($user, $folder, $spaceName, $ownerUser);
$this->featureContext->setResponse($response);
}

Expand All @@ -1168,7 +1194,7 @@ public function theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi(
* @param string $content
* @param string $destination
*
* @return string[]
* @return void
* @throws GuzzleException
* @throws Exception
*/
Expand All @@ -1177,9 +1203,10 @@ public function theUserUploadsAFileToSpace(
string $spaceName,
string $content,
string $destination
): array {
): void {
$this->setSpaceIDByName($user, $spaceName);
return $this->featureContext->uploadFileWithContent($user, $content, $destination);
$response = $this->featureContext->uploadFileWithContent($user, $content, $destination);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -1201,7 +1228,8 @@ public function theUserUploadsALocalFileToSpace(
string $spaceName
): void {
$this->setSpaceIDByName($user, $spaceName);
$this->featureContext->userUploadsAFileTo($user, $source, $destination);
$response = $this->featureContext->uploadFile($user, $source, $destination);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -1225,7 +1253,8 @@ public function theUserUploadsAFileToAnotherOwnerSpace(
string $destination
): void {
$this->setSpaceIDByName($ownerUser, $spaceName);
$this->featureContext->uploadFileWithContent($user, $content, $destination);
$response = $this->featureContext->uploadFileWithContent($user, $content, $destination);
$this->featureContext->setResponse($response);
}

/**
Expand Down Expand Up @@ -1706,19 +1735,19 @@ public function userShouldNotBeAbleToDownloadFileInsideSpace(
string $spaceName
):void {
$this->setSpaceIDByName($user, $spaceName);
$this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user));
$response = $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user));
Assert::assertGreaterThanOrEqual(
400,
$this->featureContext->getResponse()->getStatusCode(),
$response->getStatusCode(),
__METHOD__
. ' download must fail'
);
Assert::assertLessThanOrEqual(
499,
$this->featureContext->getResponse()->getStatusCode(),
$response->getStatusCode(),
__METHOD__
. ' 4xx error expected but got status code "'
. $this->featureContext->getResponse()->getStatusCode() . '"'
. $response->getStatusCode() . '"'
);
}

Expand Down Expand Up @@ -1830,7 +1859,7 @@ public function userCopiesOrMovesFileWithFileIdFromAndToSpaceBetweenSpaces(strin
* @param string $fileContent
* @param string $destination
*
* @return string[]
* @return array
* @throws GuzzleException
*/
public function userHasUploadedFile(
Expand All @@ -1840,9 +1869,10 @@ public function userHasUploadedFile(
string $destination
): array {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
$fileId = $this->theUserUploadsAFileToSpace($user, $spaceName, $fileContent, $destination);
$this->featureContext->theHTTPStatusCodeShouldBeOr(201, 204);
return $fileId;
$this->setSpaceIDByName($user, $spaceName);
$response = $this->featureContext->uploadFileWithContent($user, $fileContent, $destination, true);
$this->featureContext->theHTTPStatusCodeShouldBe(['201', '204'], "", $response);
return $response->getHeader('oc-fileid');
}

/**
Expand Down Expand Up @@ -2646,7 +2676,8 @@ public function downloadFile(
string $spaceName
): void {
$this->setSpaceIDByName($user, $spaceName);
$this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user));
$response = $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user));
$this->featureContext->setResponse($response);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/features/bootstrap/TrashbinContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,11 @@ public function contentOfFileForUserIfAlsoInTrashShouldBeOtherwise(
):void {
$isInTrash = $this->isInTrash($user, $fileName);
$user = $this->featureContext->getActualUsername($user);
$this->featureContext->downloadFileAsUserUsingPassword($user, $fileName);
$response = $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName);
if ($isInTrash) {
$this->featureContext->downloadedContentShouldBe($content);
$this->featureContext->checkDownloadedContentMatches($content, '', $response);
} else {
$this->featureContext->downloadedContentShouldBe($alternativeContent);
$this->featureContext->checkDownloadedContentMatches($alternativeContent, '', $response);
}
}

Expand Down
Loading