Skip to content

Commit

Permalink
move getting share_id from response to helper
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it committed Feb 28, 2019
1 parent 80027fc commit 6089f49
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
20 changes: 20 additions & 0 deletions tests/TestHelpers/SharingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,24 @@ public static function getPermissionSum($permissions) {
}
return $permissionSum;
}

/**
*
* @param \SimpleXMLElement $responseXmlObject
* @param string $errorMessage
*
* @throws \Exception
*
* @return string
*/
public static function getLastShareIdFromResponse(
$responseXmlObject, $errorMessage = "cannot find share id in response"
) {
$xmlPart = $responseXmlObject->xpath("//data/element[last()]/id");

if (!\is_array($xmlPart) || (\count($xmlPart) === 0)) {
throw new \Exception($errorMessage);
}
return $xmlPart[0]->__toString();
}
}
8 changes: 4 additions & 4 deletions tests/acceptance/features/apiFederation/federated.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ Feature: federated
| mountpoint | {{TemporaryMountPointName#/textfile0.txt}} |
| accepted | 0 |

Scenario: Remote sharee requests informations of only one share
Scenario: Remote sharee requests information of only one share
Given user "user0" from server "REMOTE" has shared "/textfile0.txt" with user "user1" from server "LOCAL"
And user "user1" from server "LOCAL" has accepted the last pending share
When user "user1" gets informations of last federated cloud share using the sharing API
When user "user1" retrieves the information of the last federated cloud share using the sharing API
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And the fields of the last response should include
Expand All @@ -86,9 +86,9 @@ Feature: federated
| permissions | 27 |

@issue-34636
Scenario: Remote sharee requests informations of only one share before accepting it
Scenario: Remote sharee requests information of only one share before accepting it
Given user "user0" from server "REMOTE" has shared "/textfile0.txt" with user "user1" from server "LOCAL"
When user "user1" gets informations of last pending federated cloud share using the sharing API
When user "user1" retrieves the information of the last pending federated cloud share using the sharing API
Then the HTTP status code should be "200"
And the body of the response should be empty
#And the OCS status code should be "100"
Expand Down
35 changes: 14 additions & 21 deletions tests/acceptance/features/bootstrap/FederationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use TestHelpers\SharingHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -105,7 +106,9 @@ public function userFromServerAcceptsLastPendingShareUsingTheSharingAPI($user, $
$this->userGetsTheListOfPendingFederatedCloudShares($user);
$this->featureContext->theHTTPStatusCodeShouldBe('200');
$this->featureContext->theOCSStatusCodeShouldBe('100');
$share_id = $this->featureContext->getResponseXml()->data[0]->element[0]->id;
$share_id = SharingHelper::getLastShareIdFromResponse(
$this->featureContext->getResponseXml()
);
$this->featureContext->theUserSendsToOcsApiEndpointWithBody(
'POST',
"/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}",
Expand All @@ -131,13 +134,13 @@ public function userFromServerHasAcceptedLastPendingShare($user, $server) {
}

/**
* @When /^user "([^"]*)" gets informations of last federated cloud share using the sharing API$/
* @When /^user "([^"]*)" retrieves the information of the last federated cloud share using the sharing API$/
*
* @param string $user
*
* @return void
*/
public function userGetsInformationOfLastFederatedCloudShare($user) {
public function userRetrievesInformationOfLastFederatedShare($user) {
$this->featureContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
'GET',
Expand All @@ -146,13 +149,9 @@ public function userGetsInformationOfLastFederatedCloudShare($user) {
);
$this->featureContext->theHTTPStatusCodeShouldBe('200');
$this->featureContext->theOCSStatusCodeShouldBe('100');
$xmlObject = $this->featureContext->getResponseXml();
$xmlPart = $xmlObject->xpath("//data/element[last()]/id");

if (!\is_array($xmlPart) || (\count($xmlPart) === 0)) {
throw new \Exception("cannot find share id in remote shares response");
}
$share_id = $xmlPart[0]->__toString();
$share_id = SharingHelper::getLastShareIdFromResponse(
$this->featureContext->getResponseXml()
);
$this->featureContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
'GET',
Expand All @@ -162,25 +161,19 @@ public function userGetsInformationOfLastFederatedCloudShare($user) {
}

/**
* @When /^user "([^"]*)" gets informations of last pending federated cloud share using the sharing API$/
* @When /^user "([^"]*)" retrieves the information of the last pending federated cloud share using the sharing API$/
*
* @param string $user
*
* @return void
*/
public function userGetsInformationOfLastPendingFederatedCloudShare($user) {
public function userRetrievesInformationOfLastPendingFederatedShare($user) {
$this->userGetsTheListOfPendingFederatedCloudShares($user);
$this->featureContext->theHTTPStatusCodeShouldBe('200');
$this->featureContext->theOCSStatusCodeShouldBe('100');
$xmlObject = $this->featureContext->getResponseXml();
$xmlPart = $xmlObject->xpath("//data/element[last()]/id");

if (!\is_array($xmlPart) || (\count($xmlPart) === 0)) {
throw new \Exception(
"cannot find share id in pending remote shares response"
);
}
$share_id = $xmlPart[0]->__toString();
$share_id = SharingHelper::getLastShareIdFromResponse(
$this->featureContext->getResponseXml()
);
$this->featureContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
'GET',
Expand Down

0 comments on commit 6089f49

Please sign in to comment.