Refactor SpacesContext
This commit is contained in:
@@ -39,6 +39,7 @@ default:
|
|||||||
- ChecksumContext:
|
- ChecksumContext:
|
||||||
- FavoritesContext:
|
- FavoritesContext:
|
||||||
- FilesVersionsContext:
|
- FilesVersionsContext:
|
||||||
|
- OCSContext:
|
||||||
- PublicWebDavContext:
|
- PublicWebDavContext:
|
||||||
- TrashbinContext:
|
- TrashbinContext:
|
||||||
- WebDavPropertiesContext:
|
- WebDavPropertiesContext:
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ class SpacesContext implements Context {
|
|||||||
*/
|
*/
|
||||||
private FeatureContext $featureContext;
|
private FeatureContext $featureContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OCSContext
|
||||||
|
*/
|
||||||
|
private OCSContext $ocsContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array key is space name and value is the username that created the space
|
* @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();
|
$environment = $scope->getEnvironment();
|
||||||
// Get all the contexts you need in this context
|
// Get all the contexts you need in this context
|
||||||
$this->featureContext = $environment->getContext('FeatureContext');
|
$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(
|
SetupHelper::init(
|
||||||
$this->featureContext->getAdminUsername(),
|
$this->featureContext->getAdminUsername(),
|
||||||
$this->featureContext->getAdminPassword(),
|
$this->featureContext->getAdminPassword(),
|
||||||
@@ -559,7 +567,7 @@ class SpacesContext implements Context {
|
|||||||
public function thePropfindResultShouldContainEntries(
|
public function thePropfindResultShouldContainEntries(
|
||||||
string $shouldOrNot,
|
string $shouldOrNot,
|
||||||
TableNode $expectedFiles
|
TableNode $expectedFiles
|
||||||
):void {
|
): void {
|
||||||
$this->propfindResultShouldContainEntries(
|
$this->propfindResultShouldContainEntries(
|
||||||
$shouldOrNot,
|
$shouldOrNot,
|
||||||
$expectedFiles,
|
$expectedFiles,
|
||||||
@@ -581,7 +589,7 @@ class SpacesContext implements Context {
|
|||||||
string $spaceName,
|
string $spaceName,
|
||||||
string $shouldOrNot,
|
string $shouldOrNot,
|
||||||
TableNode $expectedFiles
|
TableNode $expectedFiles
|
||||||
):void {
|
): void {
|
||||||
$this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi(
|
$this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi(
|
||||||
$this->getSpaceCreator($spaceName),
|
$this->getSpaceCreator($spaceName),
|
||||||
$spaceName
|
$spaceName
|
||||||
@@ -609,7 +617,7 @@ class SpacesContext implements Context {
|
|||||||
string $spaceName,
|
string $spaceName,
|
||||||
string $shouldOrNot,
|
string $shouldOrNot,
|
||||||
TableNode $expectedFiles
|
TableNode $expectedFiles
|
||||||
):void {
|
): void {
|
||||||
$this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi(
|
$this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi(
|
||||||
$user,
|
$user,
|
||||||
$spaceName
|
$spaceName
|
||||||
@@ -815,22 +823,7 @@ class SpacesContext implements Context {
|
|||||||
string $folder,
|
string $folder,
|
||||||
string $spaceName
|
string $spaceName
|
||||||
): void {
|
): void {
|
||||||
$space = $this->getSpaceByName($user, $spaceName);
|
$this->theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi($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)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -849,22 +842,8 @@ class SpacesContext implements Context {
|
|||||||
string $folder,
|
string $folder,
|
||||||
string $spaceName
|
string $spaceName
|
||||||
): void {
|
): 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(
|
$this->featureContext->theHTTPStatusCodeShouldBe(
|
||||||
201,
|
201,
|
||||||
"Expected response status code should be 201"
|
"Expected response status code should be 201"
|
||||||
@@ -887,8 +866,12 @@ class SpacesContext implements Context {
|
|||||||
string $user,
|
string $user,
|
||||||
string $folder,
|
string $folder,
|
||||||
string $spaceName,
|
string $spaceName,
|
||||||
string $ownerUser
|
string $ownerUser = ''
|
||||||
): void {
|
): void {
|
||||||
|
if ($ownerUser === '') {
|
||||||
|
$ownerUser = $user;
|
||||||
|
}
|
||||||
|
|
||||||
$space = $this->getSpaceByName($ownerUser, $spaceName);
|
$space = $this->getSpaceByName($ownerUser, $spaceName);
|
||||||
|
|
||||||
$baseUrl = $this->featureContext->getBaseUrl();
|
$baseUrl = $this->featureContext->getBaseUrl();
|
||||||
@@ -1112,7 +1095,12 @@ class SpacesContext implements Context {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @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]];
|
$space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]];
|
||||||
$body = json_encode($space);
|
$body = json_encode($space);
|
||||||
$this->featureContext->setResponse(
|
$this->featureContext->setResponse(
|
||||||
@@ -1140,7 +1128,12 @@ class SpacesContext implements Context {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @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);
|
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
|
||||||
|
|
||||||
$space = $this->getSpaceByName($user, $spaceName);
|
$space = $this->getSpaceByName($user, $spaceName);
|
||||||
@@ -1168,13 +1161,14 @@ class SpacesContext implements Context {
|
|||||||
* @param string $spaceName
|
* @param string $spaceName
|
||||||
* @param string $userRecipient
|
* @param string $userRecipient
|
||||||
*
|
*
|
||||||
|
* @return void
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function sendShareSpaceRequest(
|
public function sendShareSpaceRequest(
|
||||||
string $user,
|
string $user,
|
||||||
string $spaceName,
|
string $spaceName,
|
||||||
string $userRecipient
|
string $userRecipient
|
||||||
): ResponseInterface {
|
): void {
|
||||||
$space = $this->getSpaceByName($user, $spaceName);
|
$space = $this->getSpaceByName($user, $spaceName);
|
||||||
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];
|
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];
|
||||||
|
|
||||||
@@ -1184,7 +1178,7 @@ class SpacesContext implements Context {
|
|||||||
}
|
}
|
||||||
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";
|
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";
|
||||||
|
|
||||||
return HttpRequestHelper::post($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user), [], $body);
|
HttpRequestHelper::post($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user), [], $body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1194,13 +1188,14 @@ class SpacesContext implements Context {
|
|||||||
* @param string $spaceName
|
* @param string $spaceName
|
||||||
* @param string $userRecipient
|
* @param string $userRecipient
|
||||||
*
|
*
|
||||||
|
* @return void
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function userHasSharedSpace(
|
public function userHasSharedSpace(
|
||||||
string $user,
|
string $user,
|
||||||
string $spaceName,
|
string $spaceName,
|
||||||
string $userRecipient
|
string $userRecipient
|
||||||
): ResponseInterface {
|
): void {
|
||||||
$space = $this->getSpaceByName($user, $spaceName);
|
$space = $this->getSpaceByName($user, $spaceName);
|
||||||
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];
|
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];
|
||||||
|
|
||||||
@@ -1210,13 +1205,24 @@ class SpacesContext implements Context {
|
|||||||
}
|
}
|
||||||
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";
|
$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(
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(
|
$fullUrl,
|
||||||
200,
|
"",
|
||||||
"Expected response status code should be 200"
|
$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 +1232,14 @@ class SpacesContext implements Context {
|
|||||||
* @param string $spaceName
|
* @param string $spaceName
|
||||||
* @param string $userRecipient
|
* @param string $userRecipient
|
||||||
*
|
*
|
||||||
|
* @return void
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function sendUnshareSpaceRequest(
|
public function sendUnshareSpaceRequest(
|
||||||
string $user,
|
string $user,
|
||||||
string $spaceName,
|
string $spaceName,
|
||||||
string $userRecipient
|
string $userRecipient
|
||||||
): ResponseInterface {
|
): void {
|
||||||
$space = $this->getSpaceByName($user, $spaceName);
|
$space = $this->getSpaceByName($user, $spaceName);
|
||||||
$baseUrl = $this->featureContext->getBaseUrl();
|
$baseUrl = $this->featureContext->getBaseUrl();
|
||||||
if (!str_ends_with($baseUrl, '/')) {
|
if (!str_ends_with($baseUrl, '/')) {
|
||||||
@@ -1240,6 +1247,6 @@ class SpacesContext implements Context {
|
|||||||
}
|
}
|
||||||
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient;
|
$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user