[tests-only] tests: add tests for removing share permission (#8130)
* tests: add tests for removing share permission * tests: add tests for removing share permission in group share * tests: refactor test script for removing permission from share * address reviews --------- Co-authored-by: Saw-jan <saw.jan.grg3e@gmail.com>
This commit is contained in:
co-authored by
Saw-jan
parent
73d9ace439
commit
3976c1c1fc
@@ -80,6 +80,11 @@ trait Sharing {
|
||||
*/
|
||||
private array $shareNgCreatedLinkShares = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $shareNgCreatedUserGroupShares = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -119,6 +124,22 @@ trait Sharing {
|
||||
return \end($this->shareNgCreatedLinkShares);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResponseInterface $response
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function shareNgAddToCreatedUserGroupShares(ResponseInterface $response): void {
|
||||
$this->shareNgCreatedUserGroupShares[] = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface|null
|
||||
*/
|
||||
public function shareNgGetLastCreatedUserGroupShare():?ResponseInterface {
|
||||
return \end($this->shareNgCreatedUserGroupShares);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sharer
|
||||
* @param SimpleXMLElement $shareData
|
||||
@@ -179,7 +200,7 @@ trait Sharing {
|
||||
public function shareNgGetLastCreatedLinkShareID(): string {
|
||||
$lastResponse = $this->shareNgGetLastCreatedLinkShare();
|
||||
if (!isset($this->getJsonDecodedResponse($lastResponse)['id'])) {
|
||||
throw new Error('Response did not contain share id ' . $this->getJsonDecodedResponse($lastResponse)['id'] . ' for the created public link');
|
||||
throw new Error('Response did not contain share id for the created public link');
|
||||
}
|
||||
return $this->getJsonDecodedResponse($lastResponse)['id'];
|
||||
}
|
||||
@@ -196,6 +217,17 @@ trait Sharing {
|
||||
return substr(strrchr($last_created_link_webURL, "/"), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function shareNgGetLastCreatedUserGroupShareID(): string {
|
||||
$lastResponse = $this->shareNgGetLastCreatedUserGroupShare();
|
||||
if (!isset($this->getJsonDecodedResponse($lastResponse)['value'][0]['id'])) {
|
||||
throw new Error('Response did not contain share id for the last created share.');
|
||||
}
|
||||
return $this->getJsonDecodedResponse($lastResponse)['value'][0]['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Split given permissions string each separated with "," into array of strings
|
||||
*
|
||||
|
||||
@@ -126,15 +126,16 @@ class SharingNgContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" sends the following share invitation using the Graph API:$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws JsonException
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userSendsTheFollowingShareInvitationUsingTheGraphApi(string $user, TableNode $table): void {
|
||||
public function sendShareInvitation(string $user, TableNode $table): ResponseInterface {
|
||||
$rows = $table->getRowsHash();
|
||||
$spaceId = ($this->spacesContext->getSpaceByName($user, $rows['space']))["id"];
|
||||
|
||||
@@ -150,20 +151,53 @@ class SharingNgContext implements Context {
|
||||
$permissionsAction = $rows['permissionsAction'] ?? null;
|
||||
$expireDate = $rows["expireDate"] ?? null;
|
||||
|
||||
$response = GraphHelper::sendSharingInvitation(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$spaceId,
|
||||
$itemId,
|
||||
$shareeId,
|
||||
$rows['shareType'],
|
||||
$permissionsRole,
|
||||
$permissionsAction,
|
||||
$expireDate
|
||||
);
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$this->featureContext->shareNgAddToCreatedUserGroupShares($response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^user "([^"]*)" has sent the following share invitation:$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function userHasSentTheFollowingShareInvitation(string $user, TableNode $table): void {
|
||||
$response = $this->sendShareInvitation($user, $table);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" sends the following share invitation using the Graph API:$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function userSendsTheFollowingShareInvitationUsingTheGraphApi(string $user, TableNode $table): void {
|
||||
$this->featureContext->setResponse(
|
||||
GraphHelper::sendSharingInvitation(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$spaceId,
|
||||
$itemId,
|
||||
$shareeId,
|
||||
$rows['shareType'],
|
||||
$permissionsRole,
|
||||
$permissionsAction,
|
||||
$expireDate
|
||||
)
|
||||
$this->sendShareInvitation($user, $table)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -293,4 +327,44 @@ class SharingNgContext implements Context {
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" removes the share permission of (user|group) "([^"]*)" from (file|folder) "([^"]*)" of space "([^"]*)" using the Graph API$/
|
||||
*
|
||||
* @param string $sharer
|
||||
* @param string $shareType (user|group)
|
||||
* @param string $sharee can be both user or group
|
||||
* @param string $resourceType
|
||||
* @param string $resource
|
||||
* @param string $space
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function userRemovesSharePermissionOfUserFromResourceOfSpaceUsingGraphAPI(
|
||||
string $sharer,
|
||||
string $shareType,
|
||||
string $sharee,
|
||||
string $resourceType,
|
||||
string $resource,
|
||||
string $space
|
||||
): void {
|
||||
$spaceId = ($this->spacesContext->getSpaceByName($sharer, $space))["id"];
|
||||
$itemId = ($resourceType === 'folder')
|
||||
? $this->spacesContext->getResourceId($sharer, $space, $resource)
|
||||
: $this->spacesContext->getFileId($sharer, $space, $resource);
|
||||
$permId = $this->featureContext->shareNgGetLastCreatedUserGroupShareID();
|
||||
$this->featureContext->setResponse(
|
||||
GraphHelper::deleteSharePermission(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$sharer,
|
||||
$this->featureContext->getPasswordForUser($sharer),
|
||||
$spaceId,
|
||||
$itemId,
|
||||
$permId
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user