Skip to content

Commit

Permalink
Add lastPublicShareId to test class
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed May 30, 2022
1 parent 5f2df05 commit 25321ea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
38 changes: 26 additions & 12 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,21 @@ trait Sharing {
private $userWhoCreatedLastPublicShare = null;

/**
* Contains the API response to the last public link share that was created
* by the test-runner using the Sharing API.
*
* @var SimpleXMLElement
*/
private $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.
*
* @var string
*/
private $lastPublicShareId = null;

/**
* @var int
*/
Expand Down Expand Up @@ -155,6 +166,7 @@ public function getSavedShareId():?int {
*/
public function resetLastPublicShareData():void {
$this->lastPublicShareData = null;
$this->lastPublicShareId = null;
$this->userWhoCreatedLastPublicShare = null;
}

Expand Down Expand Up @@ -1126,13 +1138,15 @@ public function createShare(
if ($this->response->getStatusCode() === 204) {
if ($shareType === 'public_link') {
$this->lastPublicShareData = null;
$this->lastPublicShareId = null;
$this->userWhoCreatedLastPublicShare = null;
} else {
$this->resetLastShareDataForUser($user);
}
} else {
if ($shareType === 'public_link') {
$this->lastPublicShareData = $this->getResponseXml(null, __METHOD__);
$this->setLastPublicLinkShareId((string) $this->lastPublicShareData->data[0]->id);
$this->userWhoCreatedLastPublicShare = $user;
if (isset($this->lastPublicShareData->data)) {
$linkName = (string) $this->lastPublicShareData->data[0]->name;
Expand Down Expand Up @@ -2083,9 +2097,8 @@ public function theUserGetsInfoOfLastPublicLinkShareUsingTheSharingApi():void {
* @throws Exception
*/
public function userGetsInfoOfLastPublicLinkShareUsingTheSharingApi(string $user, ?string $language = null):void {
$lastPublicShareData = $this->getLastPublicShareData();
if ($lastPublicShareData !== null) {
$shareId = (string) $lastPublicShareData->data[0]->id;
if ($this->lastPublicShareId !== null) {
$shareId = $this->lastPublicShareId;
} else {
throw new Exception(
__METHOD__ . " last public link share data was not found"
Expand Down Expand Up @@ -2159,21 +2172,22 @@ public function getLastShareIdOf(string $user):?string {
return $id;
}

/**
* Sets the id of the last public link shared file
*
* @param string $shareId
*/
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 {
$shareData = $this->getLastPublicShareData();
if ($shareData->data) {
// id is a SimpleXMLElement object that contains the share id
// which is a string.
// (It might be a numeric string or might not, either is fine.)
return (string) $shareData->data[0]->id;
} else {
return null;
}
return $this->lastPublicShareId;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/acceptance/features/bootstrap/WebUISharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ public function theUserCreatesANewPublicLinkForFileFolderUsingTheWebUIWith(
):void {
$linkName = $this->createPublicShareLink($name, $settings);
$linkUrl = $this->publicShareTab->getLinkUrl($linkName);
// ToDo: need to find out the share id of the public link share that was just created on the webUI
$urlParts = \explode("/", $linkUrl);
$shareId = \end($urlParts);
echo "\nshare id '$shareId'\n";
$this->featureContext->setLastPublicLinkShareId($shareId);
$this->featureContext->addToListOfCreatedPublicLinks($linkName, $linkUrl);
}

Expand Down

0 comments on commit 25321ea

Please sign in to comment.