refactored acceptance test code to store response data related to public shares on single store (#6930)

This commit is contained in:
Prajwol Amatya
2023-08-03 13:51:22 +05:45
committed by GitHub
parent b730234e86
commit db098fa4f5
7 changed files with 75 additions and 259 deletions
+38 -210
View File
@@ -43,21 +43,6 @@ trait Sharing {
*/
private array $createdUserGroupShares = [];
private ?string $userWhoCreatedLastPublicShare = null;
/**
* Contains the API response to the last public link share that was created
* by the test-runner using the Sharing API.
* Shares created on the webUI do not have an entry.
*/
private ?SimpleXMLElement $lastPublicShareData = null;
/**
* Contains the share id of the last public link share that was created by
* the test-runner, either using the Sharing API or on the web UI.
*/
private ?string $lastPublicShareId = null;
private ?float $localLastShareTime = null;
/**
@@ -85,61 +70,32 @@ trait Sharing {
'attributes', 'permissions', 'share_with', 'share_with_displayname', 'share_with_additional_info'
];
/*
* Contains information about the public links that have been created with the webUI.
* Each entry in the array has a "name", "url" and "path".
*/
private array $createdPublicLinks = [];
/**
* The end (last) entry will itself be an array with keys "name", "url" and "path"
*
* @return array
* @var array
*/
public function getLastCreatedPublicLink():array {
return \end($this->createdPublicLinks);
}
private array $createdPublicShares = [];
/**
* @return string
*/
public function getLastCreatedPublicLinkUrl():string {
$lastCreatedLink = $this->getLastCreatedPublicLink();
return $lastCreatedLink["url"];
}
/**
* @return string
*/
public function getLastCreatedPublicLinkPath():string {
$lastCreatedLink = $this->getLastCreatedPublicLink();
return $lastCreatedLink["path"];
}
/**
* @return string
*/
public function getLastCreatedPublicLinkToken():string {
$lastCreatedLinkUrl = $this->getLastCreatedPublicLinkUrl();
// The token is the last part of the URL, delimited by "/"
$urlParts = \explode("/", $lastCreatedLinkUrl);
return \end($urlParts);
public function getLastCreatedPublicShareToken():string {
return (string) $this->getLastCreatedPublicShare()->token;
}
/**
* @return SimpleXMLElement|null
*/
public function getLastPublicShareData():?SimpleXMLElement {
return $this->lastPublicShareData;
public function getLastCreatedPublicShare():?SimpleXMLElement {
return \end($this->createdPublicShares);
}
/**
* @param SimpleXMLElement $responseXml
* @param SimpleXMLElement $shareData
*
* @return void
*/
public function setLastPublicShareData(SimpleXMLElement $responseXml): void {
$this->lastPublicShareData = $responseXml;
public function addToCreatedPublicShares(SimpleXMLElement $shareData): void {
$this->createdPublicShares[] = $shareData;
}
/**
@@ -169,10 +125,8 @@ trait Sharing {
/**
* @return void
*/
public function resetLastPublicShareData():void {
$this->lastPublicShareData = null;
$this->lastPublicShareId = null;
$this->userWhoCreatedLastPublicShare = null;
public function emptyCreatedPublicShares():void {
$this->createdPublicShares = [];
}
/**
@@ -886,7 +840,7 @@ trait Sharing {
$user = $this->getActualUsername($user);
if ($updateLastPublicLink) {
$share_id = $this->getLastPublicLinkShareId();
$share_id = (string) $this->getLastCreatedPublicShare()->id;
} else {
if ($shareOwner === null) {
$share_id = $this->getLastCreatedUserGroupShareId();
@@ -1003,17 +957,6 @@ trait Sharing {
}
}
/**
* @param string $name
* @param string $url
* @param string $path
*
* @return void
*/
public function addToListOfCreatedPublicLinks(string $name, string $url, string $path = ""):void {
$this->createdPublicLinks[] = ["name" => $name, "url" => $url, "path" => $path];
}
/**
* @param string $user
* @param string|null $path
@@ -1074,26 +1017,19 @@ trait Sharing {
|| (($httpStatusCode === 200) && ($this->ocsContext->getOCSResponseStatusCode($this->response) > 299))
) {
if ($shareType === 'public_link') {
$this->resetLastPublicShareData();
$this->emptyCreatedPublicShares();
} else {
$this->emptyCreatedUserGroupShares();
}
} else {
if ($shareType === 'public_link') {
$this->setLastPublicShareData($this->getResponseXml(null, __METHOD__));
$this->setLastPublicLinkShareId((string) $this->lastPublicShareData->data[0]->id);
$this->setUserWhoCreatedLastPublicShare($user);
if (isset($this->lastPublicShareData->data)) {
$linkName = (string) $this->lastPublicShareData->data[0]->name;
$linkUrl = (string) $this->lastPublicShareData->data[0]->url;
$this->addToListOfCreatedPublicLinks($linkName, $linkUrl, $path);
}
} else {
$response = $this->getResponseXml(null, __METHOD__);
if (isset($response->data)) {
$shareData = $response->data;
$response = $this->getResponseXml(null, __METHOD__);
if (isset($response->data)) {
$shareData = $response->data;
if ($shareType === 'public_link') {
$this->addToCreatedPublicShares($shareData);
} else {
$sharer = (string) $response->data->uid_owner;
$this->addToCreatedUserGroupShares($sharer, $shareData);
$this->addToCreatedUserGroupshares($sharer, $shareData);
}
}
}
@@ -1933,7 +1869,7 @@ trait Sharing {
public function deleteLastShareUsingSharingApi(string $user, string $sharer = null, bool $deleteLastPublicLink = false):void {
$user = $this->getActualUsername($user);
if ($deleteLastPublicLink) {
$shareId = $this->getLastPublicLinkShareId();
$shareId = (string) $this->getLastCreatedPublicShare()->id;
} else {
if ($sharer === null) {
$shareId = $this->getLastCreatedUserGroupShareId();
@@ -2042,7 +1978,7 @@ trait Sharing {
* @throws Exception
*/
public function theUserGetsInfoOfLastPublicLinkShareUsingTheSharingApi():void {
$this->userGetsInfoOfLastPublicLinkShareUsingTheSharingApi($this->getUserWhoCreatedLastPublicShare());
$this->userGetsInfoOfLastPublicLinkShareUsingTheSharingApi((string) $this->getLastCreatedPublicShare()->uid_owner);
}
/**
@@ -2056,8 +1992,8 @@ trait Sharing {
* @throws Exception
*/
public function userGetsInfoOfLastPublicLinkShareUsingTheSharingApi(string $user, ?string $language = null):void {
if ($this->lastPublicShareId !== null) {
$shareId = $this->lastPublicShareId;
if ($this->getLastCreatedPublicShare()->id !== null) {
$shareId = (string) $this->getLastCreatedPublicShare()->id;
} else {
throw new Exception(
__METHOD__ . " last public link share data was not found"
@@ -2108,46 +2044,6 @@ trait Sharing {
$this->asLastShareInfoAboutUserSharingWithUserShouldInclude($sharer, $sharer, $sharee, $table);
}
/**
* Sets the id of the last public link shared file
*
* @param string $shareId
*
* @return void
*/
public function setLastPublicLinkShareId(string $shareId):void {
$this->lastPublicShareId = $shareId;
}
/**
* Retrieves the id of the last public link shared file
*
* @return string|null
*/
public function getLastPublicLinkShareId():?string {
return $this->lastPublicShareId;
}
/**
* Sets the user who created the last public link share
*
* @param string $user
*
* @return void
*/
public function setUserWhoCreatedLastPublicShare(string $user):void {
$this->userWhoCreatedLastPublicShare = $user;
}
/**
* Gets the user who created the last public link share
*
* @return string|null
*/
public function getUserWhoCreatedLastPublicShare():?string {
return $this->userWhoCreatedLastPublicShare;
}
/**
* Retrieves all the shares of the respective user
*
@@ -2223,7 +2119,7 @@ trait Sharing {
*/
public function userGetsTheLastShareSharedWithHimUsingTheSharingApi(string $user, TableNode $table):void {
$user = $this->getActualUsername($user);
$shareId = $this->getLastPublicLinkShareId();
$shareId = (string) $this->getLastCreatedPublicShare()->id;
$this->getShareData($user, $shareId);
$this->checkFields($user, $table);
}
@@ -2429,7 +2325,7 @@ trait Sharing {
):void {
$user = $this->getActualUsername($user);
$this->verifyTableNodeRows($body, [], $this->shareResponseFields);
$this->getShareData($user, (string)$this->getLastPublicLinkShareId());
$this->getShareData($user, (string) $this->getLastCreatedPublicShare()->id);
$this->theHTTPStatusCodeShouldBe(
200,
"Error getting info of last public link share for user $user"
@@ -2564,7 +2460,7 @@ trait Sharing {
* @throws Exception
*/
public function checkLastPublicLinkShareIDIsNotIncluded():void {
$shareId = $this->getLastPublicLinkShareId();
$shareId = (string) $this->getLastCreatedPublicShare()->id;
if ($this->isFieldInResponse('id', $shareId, false)) {
Assert::fail(
"Public link share id $shareId has been found in response"
@@ -2705,7 +2601,8 @@ trait Sharing {
"space_id"
];
$this->setLastPublicShareData($this->getResponseXml(null, __METHOD__));
$response = $this->getResponseXml(null, __METHOD__);
$this->addToCreatedPublicShares($response->data);
foreach ($bodyRows as $field => $value) {
if (\in_array($field, $userRelatedFieldNames)) {
$value = $this->substituteInLineCodes(
@@ -2735,7 +2632,7 @@ trait Sharing {
$value = $this->replaceValuesFromTable($field, $value);
Assert::assertTrue(
$this->isFieldInResponse($field, $value, true, $this->getLastPublicShareData()->data[0]),
$this->isFieldInResponse($field, $value, true, $this->getLastCreatedPublicShare()),
"$field doesn't have value '$value'"
);
}
@@ -3585,73 +3482,6 @@ trait Sharing {
return $usersShares['ocs']['data'];
}
/**
* The tests can create public link shares with the API or with the webUI.
* If lastPublicShareData is null, then there have not been any created with the API,
* so look for details of a public link share created with the webUI.
*
* @return string authorization token
*/
public function getLastPublicShareToken():string {
if ($this->lastPublicShareData === null) {
return $this->getLastCreatedPublicLinkToken();
} else {
if (\count($this->lastPublicShareData->data->element) > 0) {
return (string)$this->lastPublicShareData->data[0]->token;
}
return (string)$this->lastPublicShareData->data->token;
}
}
/**
* Returns the attribute values from the last public link share data
*
* @param $attr - attribute name to get
*
* @return string
* @throws Exception
*/
public function getLastPublicShareAttribute(string $attr): string {
if ($this->lastPublicShareData === null) {
throw new Exception(__METHOD__ . "No public share data available.");
}
if (!\in_array($attr, $this->shareResponseFields)) {
throw new Exception(
__METHOD__ . " attribute $attr is not in the list of allowed attributes"
);
}
if (\count($this->lastPublicShareData->data->element) > 0) {
if (!isset($this->lastPublicShareData->data[0]->$attr)) {
throw new Exception(__METHOD__ . " No attribute $attr available in the last share data.");
}
return (string)$this->lastPublicShareData->data[0]->{$attr};
}
if (!isset($this->lastPublicShareData->data->$attr)) {
throw new Exception(__METHOD__ . " No attribute $attr available in the last share data.");
}
return (string)$this->lastPublicShareData->data->{$attr};
}
/**
* @return string path of file that was shared (relevant when a single file has been shared)
*/
public function getLastPublicSharePath():string {
if ($this->lastPublicShareData === null) {
// There have not been any public links created with the API
// so get the path of the last public link created with the webUI
return $this->getLastCreatedPublicLinkPath();
} else {
if (\count($this->lastPublicShareData->data->element) > 0) {
return (string)$this->lastPublicShareData->data[0]->path;
}
return (string)$this->lastPublicShareData->data->path;
}
}
/**
* Send request for preview of a file in a public link
*
@@ -3678,8 +3508,7 @@ trait Sharing {
* @return void
*/
public function thePublicAccessesThePreviewOfTheSharedFileUsingTheSharingApi(string $path):void {
$shareData = $this->getLastPublicShareData();
$token = (string) $shareData->data->token;
$token = $this->getLastCreatedPublicShareToken();
$this->getPublicPreviewOfFile($path, $token);
$this->pushToLastStatusCodesArrays();
}
@@ -3700,8 +3529,7 @@ trait Sharing {
$this->emptyLastHTTPStatusCodesArray();
$this->emptyLastOCSStatusCodesArray();
foreach ($paths as $path) {
$shareData = $this->getLastPublicShareData();
$token = (string) $shareData->data->token;
$token = $this->getLastCreatedPublicShareToken();
$this->getPublicPreviewOfFile($path["path"], $token);
$this->pushToLastStatusCodesArrays();
}
@@ -3722,12 +3550,12 @@ trait Sharing {
$user = $this->getActualUsername($user);
$userPassword = $this->getPasswordForUser($user);
$shareData = $this->getLastPublicShareData();
$owner = (string) $shareData->data->uid_owner;
$name = $this->encodePath((string) $shareData->data->file_target);
$shareData = $this->getLastCreatedPublicShare();
$owner = (string) $shareData->uid_owner;
$name = $this->encodePath((string) $shareData->file_target);
$name = \trim($name, "/");
$ownerDisplayName = (string) $shareData->data->displayname_owner;
$token = (string) $shareData->data->token;
$ownerDisplayName = (string) $shareData->displayname_owner;
$token = (string) $shareData->token;
if (\strtolower($shareServer) == "remote") {
$remote = $this->getRemoteBaseUrl();
@@ -3870,7 +3698,7 @@ trait Sharing {
* @throws GuzzleException
*/
public function expireLastCreatedPublicLinkShare():void {
$shareId = $this->getLastPublicLinkShareId();
$shareId = (string) $this->getLastCreatedPublicShare()->id;
$this->expireShare($shareId);
}