Merge pull request #2905 from owncloud/refactor-sspaces-api-tests-20211221

[tests-only] Refactor some SpacesContext local API test code
This commit is contained in:
Phil Davis
2021-12-22 08:01:50 +05:45
committed by GitHub
3 changed files with 67 additions and 48 deletions

View File

@@ -39,6 +39,7 @@ default:
- ChecksumContext:
- FavoritesContext:
- FilesVersionsContext:
- OCSContext:
- PublicWebDavContext:
- TrashbinContext:
- WebDavPropertiesContext:

View File

@@ -16,6 +16,8 @@ Feature: Share spaces
Given user "Alice" has created a space "Space to share" of type "project" with quota "10"
When user "Alice" shares a space "Space to share" to user "Brian"
Then the HTTP status code should be "200"
And the OCS status code should be "200"
And the OCS status message should be "OK"
Scenario: A user can see that a received shared space is available

View File

@@ -41,6 +41,11 @@ class SpacesContext implements Context {
*/
private FeatureContext $featureContext;
/**
* @var OCSContext
*/
private OCSContext $ocsContext;
/**
* @var array key is space name and value is the username that created the space
*/
@@ -209,6 +214,9 @@ class SpacesContext implements Context {
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->ocsContext = $environment->getContext('OCSContext');
// Run the BeforeScenario function in OCSContext to set it up correctly
$this->ocsContext->before($scope);
SetupHelper::init(
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
@@ -559,7 +567,7 @@ class SpacesContext implements Context {
public function thePropfindResultShouldContainEntries(
string $shouldOrNot,
TableNode $expectedFiles
):void {
): void {
$this->propfindResultShouldContainEntries(
$shouldOrNot,
$expectedFiles,
@@ -581,7 +589,7 @@ class SpacesContext implements Context {
string $spaceName,
string $shouldOrNot,
TableNode $expectedFiles
):void {
): void {
$this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi(
$this->getSpaceCreator($spaceName),
$spaceName
@@ -609,7 +617,7 @@ class SpacesContext implements Context {
string $spaceName,
string $shouldOrNot,
TableNode $expectedFiles
):void {
): void {
$this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi(
$user,
$spaceName
@@ -815,22 +823,7 @@ class SpacesContext implements Context {
string $folder,
string $spaceName
): void {
$space = $this->getSpaceByName($user, $spaceName);
$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
$baseUrl .= '/';
}
$fullUrl = $baseUrl . "dav/spaces/" . $space['id'] . '/' . $folder;
$this->featureContext->setResponse(
$this->sendCreateFolderRequest(
$fullUrl,
"MKCOL",
$user,
$this->featureContext->getPasswordForUser($user)
)
);
$this->theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi($user, $folder, $spaceName);
}
/**
@@ -849,22 +842,8 @@ class SpacesContext implements Context {
string $folder,
string $spaceName
): void {
$space = $this->getSpaceByName($user, $spaceName);
$this->theUserCreatesAFolderUsingTheGraphApi($user, $folder, $spaceName);
$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
$baseUrl .= '/';
}
$fullUrl = $baseUrl . "dav/spaces/" . $space['id'] . '/' . $folder;
$this->featureContext->setResponse(
$this->sendCreateFolderRequest(
$fullUrl,
"MKCOL",
$user,
$this->featureContext->getPasswordForUser($user)
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201"
@@ -887,8 +866,12 @@ class SpacesContext implements Context {
string $user,
string $folder,
string $spaceName,
string $ownerUser
string $ownerUser = ''
): void {
if ($ownerUser === '') {
$ownerUser = $user;
}
$space = $this->getSpaceByName($ownerUser, $spaceName);
$baseUrl = $this->featureContext->getBaseUrl();
@@ -1112,7 +1095,12 @@ class SpacesContext implements Context {
*
* @return void
*/
public function userHasCreatedSpace(string $user, string $spaceName, string $spaceType, int $quota):void {
public function userHasCreatedSpace(
string $user,
string $spaceName,
string $spaceType,
int $quota
): void {
$space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]];
$body = json_encode($space);
$this->featureContext->setResponse(
@@ -1140,7 +1128,12 @@ class SpacesContext implements Context {
*
* @return void
*/
public function userHasUploadedFile(string $user, string $spaceName, string $fileContent, string $destination):void {
public function userHasUploadedFile(
string $user,
string $spaceName,
string $fileContent,
string $destination
): void {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
$space = $this->getSpaceByName($user, $spaceName);
@@ -1168,13 +1161,14 @@ class SpacesContext implements Context {
* @param string $spaceName
* @param string $userRecipient
*
* @return void
* @throws GuzzleException
*/
public function sendShareSpaceRequest(
string $user,
string $spaceName,
string $userRecipient
): ResponseInterface {
): void {
$space = $this->getSpaceByName($user, $spaceName);
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];
@@ -1184,7 +1178,16 @@ class SpacesContext implements Context {
}
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";
return HttpRequestHelper::post($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user), [], $body);
$this->featureContext->setResponse(
HttpRequestHelper::post(
$fullUrl,
"",
$user,
$this->featureContext->getPasswordForUser($user),
[],
$body
)
);
}
/**
@@ -1194,13 +1197,14 @@ class SpacesContext implements Context {
* @param string $spaceName
* @param string $userRecipient
*
* @return void
* @throws GuzzleException
*/
public function userHasSharedSpace(
string $user,
string $spaceName,
string $userRecipient
): ResponseInterface {
): void {
$space = $this->getSpaceByName($user, $spaceName);
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];
@@ -1210,13 +1214,24 @@ class SpacesContext implements Context {
}
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";
return HttpRequestHelper::post($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user), [], $body);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"Expected response status code should be 200"
$this->featureContext->setResponse(
HttpRequestHelper::post(
$fullUrl,
"",
$user,
$this->featureContext->getPasswordForUser($user),
[],
$body
)
);
$this->OCSContext->theOCSStatusCodeShouldBe(400, "Expected OCS response status code should be 200");
$expectedHTTPStatus = "200";
$this->featureContext->theHTTPStatusCodeShouldBe(
$expectedHTTPStatus,
"Expected response status code should be $expectedHTTPStatus"
);
$expectedOCSStatus = "200";
$this->ocsContext->theOCSStatusCodeShouldBe($expectedOCSStatus, "Expected OCS response status code $expectedOCSStatus");
}
/**
@@ -1226,13 +1241,14 @@ class SpacesContext implements Context {
* @param string $spaceName
* @param string $userRecipient
*
* @return void
* @throws GuzzleException
*/
public function sendUnshareSpaceRequest(
string $user,
string $spaceName,
string $userRecipient
): ResponseInterface {
): void {
$space = $this->getSpaceByName($user, $spaceName);
$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
@@ -1240,6 +1256,6 @@ class SpacesContext implements Context {
}
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient;
return HttpRequestHelper::delete($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user));
HttpRequestHelper::delete($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user));
}
}