diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 60d8a6d49b..0724f9da76 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -2785,7 +2785,7 @@ class FeatureContext extends BehatVariablesContext { "code" => "%last_share_id%", "function" => [ $this, - "getLastShareId" + "getLastCreatedUserGroupShareId" ], "parameter" => [] ], diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 15eecacaad..392ddd1e23 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -39,22 +39,9 @@ trait Sharing { private int $sharingApiVersion = 1; /** - * Contains the API response to the last share that was created by each user - * using the Sharing API. Shares created on the webUI do not have an entry. - * - * @var SimpleXMLElement[] + * @var array */ - private array $lastShareDataByUser = []; - - /** - * Contains the share id of the last share that was created by each user, - * either using the Sharing API or on the web UI. - * - * @var string[] - */ - private array $lastShareIdByUser = []; - - private ?string $userWhoCreatedLastShare = null; + private array $createdUserGroupShares = []; private ?string $userWhoCreatedLastPublicShare = null; @@ -71,8 +58,6 @@ trait Sharing { */ private ?string $lastPublicShareId = null; - private ?int $savedShareId = null; - private ?float $localLastShareTime = null; /** @@ -106,13 +91,6 @@ trait Sharing { */ private array $createdPublicLinks = []; - /** - * @return array - */ - public function getCreatedPublicLinks():array { - return $this->createdPublicLinks; - } - /** * The end (last) entry will itself be an array with keys "name", "url" and "path" * @@ -165,37 +143,27 @@ trait Sharing { } /** - * @return SimpleXMLElement - * @throws Exception - */ - public function getLastShareData():SimpleXMLElement { - return $this->getLastShareDataForUser($this->userWhoCreatedLastShare); - } - - /** - * @param string|null $user + * @param string $sharer + * @param SimpleXMLElement $shareData * - * @return SimpleXMLElement - * @throws Exception + * @return void */ - public function getLastShareDataForUser(?string $user):SimpleXMLElement { - if ($user === null) { - throw new Exception( - __METHOD__ . " user not specified. Probably no user or group shares have been created yet in the test scenario." - ); - } - if (isset($this->lastShareDataByUser[$user])) { - return $this->lastShareDataByUser[$user]; - } else { - throw new Exception(__METHOD__ . " last share data for user '$user' was not found"); - } + public function addToCreatedUserGroupShares(string $sharer, SimpleXMLElement $shareData): void { + $this->createdUserGroupShares["$sharer"] = $shareData; } /** - * @return int|null + * @return array */ - public function getSavedShareId():?int { - return $this->savedShareId; + public function getCreatedUserGroupShares(): array { + return $this->createdUserGroupShares; + } + + /** + * @return SimpleXMLElement + */ + public function getLastCreatedUserGroupShare(): SimpleXMLElement { + return \end($this->createdUserGroupShares); } /** @@ -208,17 +176,10 @@ trait Sharing { } /** - * @param string $user - * * @return void */ - public function resetLastShareInfoForUser(string $user):void { - if (isset($this->lastShareDataByUser[$user])) { - unset($this->lastShareDataByUser[$user]); - } - if (isset($this->lastShareIdByUser[$user])) { - unset($this->lastShareIdByUser[$user]); - } + public function emptyCreatedUserGroupShares(): void { + $this->createdUserGroupShares = []; } /** @@ -228,13 +189,6 @@ trait Sharing { return $this->localLastShareTime; } - /** - * @return int - */ - public function getServerLastShareTime():int { - return (int) $this->getLastShareData()->data->stime; - } - /** * @param string|null $postfix string to append to the end of the path * @@ -833,15 +787,6 @@ trait Sharing { $this->theHTTPStatusCodeShouldBeSuccess(); } - /** - * Give the mimetype of the last shared file - * - * @return string - */ - public function getMimeTypeOfLastSharedFile():string { - return \json_decode(\json_encode($this->getLastShareData()->data->mimetype), true)[0]; - } - /** * @Then /^user "([^"]*)" should not be able to create a public link share of (file|folder) "([^"]*)" using the sharing API$/ * @@ -904,6 +849,25 @@ trait Sharing { $this->theHTTPStatusCodeShouldBeSuccess(); } + /** + * Gets the last user share id using the sharer's name + * + * @param string|null $user + * + * @return string + * @throws Exception + */ + public function getLastCreatedUserGroupShareId(?string $user = null): string { + if ($user === null) { + return (string) $this->getLastCreatedUserGroupShare()->id; + } + $createdShares = $this->getCreatedUserGroupShares(); + if (isset($createdShares[$user])) { + return (string) $createdShares[$user]->id; + } + throw new Exception(__METHOD__ . " user '$user' doesn't have a share in the created shares list"); + } + /** * @param string $user * @param TableNode|null $body @@ -925,9 +889,9 @@ trait Sharing { $share_id = $this->getLastPublicLinkShareId(); } else { if ($shareOwner === null) { - $share_id = $this->getLastShareId(); + $share_id = $this->getLastCreatedUserGroupShareId(); } else { - $share_id = $this->getLastShareIdForUser($shareOwner); + $share_id = $this->getLastCreatedUserGroupShareId($shareOwner); } } @@ -1112,7 +1076,7 @@ trait Sharing { if ($shareType === 'public_link') { $this->resetLastPublicShareData(); } else { - $this->resetLastShareInfoForUser($user); + $this->emptyCreatedUserGroupShares(); } } else { if ($shareType === 'public_link') { @@ -1125,10 +1089,12 @@ trait Sharing { $this->addToListOfCreatedPublicLinks($linkName, $linkUrl, $path); } } else { - $shareData = $this->getResponseXml(null, __METHOD__); - $this->lastShareDataByUser[$user] = $shareData; - $shareId = (string) $shareData->data[0]->id; - $this->setLastShareIdOf($user, $shareId); + $response = $this->getResponseXml(null, __METHOD__); + if (isset($response->data)) { + $shareData = $response->data; + $sharer = (string) $response->data->uid_owner; + $this->addToCreatedUserGroupShares($sharer, $shareData); + } } } $this->localLastShareTime = \microtime(true); @@ -1970,9 +1936,9 @@ trait Sharing { $shareId = $this->getLastPublicLinkShareId(); } else { if ($sharer === null) { - $shareId = $this->getLastShareId(); + $shareId = $this->getLastCreatedUserGroupShareId(); } else { - $shareId = $this->getLastShareIdForUser($sharer); + $shareId = $this->getLastCreatedUserGroupShareId($sharer); } } $url = $this->getSharesEndpointPath("/$shareId"); @@ -2063,7 +2029,7 @@ trait Sharing { * @throws Exception */ public function userGetsInfoOfLastShareUsingTheSharingApi(string $user, ?string $language = null):void { - $shareId = $this->getLastShareId(); + $shareId = $this->getLastCreatedUserGroupShareId(); $language = TranslationHelper::getLanguage($language); $this->getShareData($user, $shareId, $language); $this->pushToLastStatusCodesArrays(); @@ -2142,19 +2108,6 @@ trait Sharing { $this->asLastShareInfoAboutUserSharingWithUserShouldInclude($sharer, $sharer, $sharee, $table); } - /** - * Sets the id of the last shared file - * - * @param string $user - * @param string $shareId - * - * @return void - */ - public function setLastShareIdOf(string $user, string $shareId):void { - $this->lastShareIdByUser[$user] = $shareId; - $this->userWhoCreatedLastShare = $user; - } - /** * Sets the id of the last public link shared file * @@ -2195,33 +2148,6 @@ trait Sharing { return $this->userWhoCreatedLastPublicShare; } - /** - * Retrieves the id of the last shared file - * - * @return string|null - */ - public function getLastShareId():?string { - return $this->getLastShareIdForUser($this->userWhoCreatedLastShare); - } - - /** - * @param string $user - * - * @return string|null - */ - public function getLastShareIdForUser(string $user):?string { - if ($user === "") { - throw new Exception( - __METHOD__ . " user not specified. Probably no user or group shares have been created yet in the test scenario." - ); - } - if (isset($this->lastShareIdByUser[$user])) { - return $this->lastShareIdByUser[$user]; - } else { - throw new Exception(__METHOD__ . " last share id for user '$user' was not found"); - } - } - /** * Retrieves all the shares of the respective user * @@ -2473,7 +2399,7 @@ trait Sharing { ):void { $user = $this->getActualUsername($user); $this->verifyTableNodeRows($body, [], $this->shareResponseFields); - $this->getShareData($user, (string)$this->getLastShareData()->data[0]->id); + $this->getShareData($user, $this->getLastCreatedUserGroupShareId()); $this->theHTTPStatusCodeShouldBe( 200, "Error getting info of last share for user $user" @@ -2532,7 +2458,7 @@ trait Sharing { TableNode $body ):void { $user = $this->getActualUsername($user); - $shareId = $this->getLastShareIdForUser($user); + $shareId = $this->getLastCreatedUserGroupShareId($user); $this->getShareData($user, $shareId); $this->theHTTPStatusCodeShouldBe( 200, @@ -2608,7 +2534,7 @@ trait Sharing { * @throws Exception */ public function checkingLastShareIDIsIncluded():void { - $shareId = $this->getLastShareId(); + $shareId = $this->getLastCreatedUserGroupShareId(); if (!$this->isFieldInResponse('id', $shareId)) { Assert::fail( "Share id $shareId not found in response" @@ -2623,7 +2549,7 @@ trait Sharing { * @throws Exception */ public function checkLastShareIDIsNotIncluded():void { - $shareId = $this->getLastShareId(); + $shareId = $this->getLastCreatedUserGroupShareId(); if ($this->isFieldInResponse('id', $shareId, false)) { Assert::fail( "Share id $shareId has been found in response" @@ -2764,7 +2690,7 @@ trait Sharing { */ public function checkFieldsOfSpaceSharingResponse(string $user, string $space, ?TableNode $body):void { $this->verifyTableNodeColumnsCount($body, 2); - + $bodyRows = $body->getRowsHash(); $userRelatedFieldNames = [ "owner", @@ -2807,7 +2733,7 @@ trait Sharing { } $value = $this->getActualUsername($value); $value = $this->replaceValuesFromTable($field, $value); - + Assert::assertTrue( $this->isFieldInResponse($field, $value, true, $this->getLastPublicShareData()->data[0]), "$field doesn't have value '$value'" @@ -3959,7 +3885,7 @@ trait Sharing { public function expireShare(string $shareId = null):void { $adminUser = $this->getAdminUsername(); if ($shareId === null) { - $shareId = $this->getLastShareId(); + $shareId = $this->getLastCreatedUserGroupShareId(); } $response = OcsApiHelper::sendRequest( $this->getBaseUrl(),