Skip to content

Commit

Permalink
Improve then steps for suite 'apiFederationToShares2'
Browse files Browse the repository at this point in the history
Signed-off-by: Parajuli Kiran <[email protected]>
  • Loading branch information
kiranparajuli589 committed Apr 22, 2022
1 parent 88d6d8a commit 023069e
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 81 deletions.
210 changes: 137 additions & 73 deletions tests/acceptance/features/apiFederationToShares2/federated.feature

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions tests/acceptance/features/bootstrap/AppConfigurationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use TestHelpers\AppConfigHelper;
use TestHelpers\OcsApiHelper;
Expand All @@ -47,6 +48,7 @@ class AppConfigurationContext implements Context {
* @param string $value
*
* @return void
* @throws Exception
*/
public function adminSetsServerParameterToUsingAPI(
string $parameter,
Expand All @@ -68,6 +70,7 @@ public function adminSetsServerParameterToUsingAPI(
* @param string $value
*
* @return void
* @throws Exception
*/
public function serverParameterHasBeenSetTo(string $parameter, string $app, string $value):void {
// The capturing group of the regex always includes the quotes at each
Expand Down Expand Up @@ -111,6 +114,7 @@ public function theCapabilitiesSettingOfAppParameterShouldBe(
* @param string $capabilitiesPath the path to the element
*
* @return string
* @throws Exception
*/
public function getAppParameter(string $capabilitiesApp, string $capabilitiesPath):string {
return $this->getParameterValueFromXml(
Expand All @@ -126,6 +130,8 @@ public function getAppParameter(string $capabilitiesApp, string $capabilitiesPat
* @param string $username
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function userGetsCapabilities(string $username):void {
$user = $this->featureContext->getActualUsername($username);
Expand Down Expand Up @@ -184,6 +190,7 @@ public function theUserGetsCapabilitiesCheckResponse():void {

/**
* @return string
* @throws Exception
*/
public function getAdminUsernameForCapabilitiesCheck():string {
if (\TestHelpers\OcisHelper::isTestingOnReva()) {
Expand Down Expand Up @@ -225,6 +232,7 @@ public function theAdministratorGetsCapabilitiesCheckResponse():void {
* @param string $exceptionText text to put at the front of exception messages
*
* @return SimpleXMLElement latest retrieved capabilities in XML format
* @throws Exception
*/
public function getCapabilitiesXml(string $exceptionText = ''): SimpleXMLElement {
if ($exceptionText === '') {
Expand All @@ -237,6 +245,7 @@ public function getCapabilitiesXml(string $exceptionText = ''): SimpleXMLElement
* @param string $exceptionText text to put at the front of exception messages
*
* @return SimpleXMLElement latest retrieved version data in XML format
* @throws Exception
*/
public function getVersionXml(string $exceptionText = ''): SimpleXMLElement {
if ($exceptionText === '') {
Expand Down Expand Up @@ -326,6 +335,7 @@ public function parameterValueExistsInXml(
* @param string $value
*
* @return void
* @throws Exception
*/
public function modifyAppConfig(string $app, string $parameter, string $value):void {
AppConfigHelper::modifyAppConfig(
Expand All @@ -344,6 +354,7 @@ public function modifyAppConfig(string $app, string $parameter, string $value):v
* @param array $appParameterValues
*
* @return void
* @throws Exception
*/
public function modifyAppConfigs(array $appParameterValues):void {
AppConfigHelper::modifyAppConfigs(
Expand All @@ -362,6 +373,7 @@ public function modifyAppConfigs(array $appParameterValues):void {
* @param string $url
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorAddsUrlAsTrustedServerUsingTheTestingApi(string $url):void {
$adminUser = $this->featureContext->getAdminUsername();
Expand All @@ -375,6 +387,7 @@ public function theAdministratorAddsUrlAsTrustedServerUsingTheTestingApi(string
['url' => $this->featureContext->substituteInLineCodes($url)]
);
$this->featureContext->setResponse($response);
$this->featureContext->pushToLastStatusCodesArrays();
}

/**
Expand Down Expand Up @@ -456,6 +469,7 @@ public function theTrustedServerListShouldIncludeTheseUrls(TableNode $table):voi
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theAdministratorHasAddedUrlAsTrustedServer(string $url):void {
$this->theAdministratorAddsUrlAsTrustedServerUsingTheTestingApi($url);
Expand All @@ -475,6 +489,7 @@ public function theAdministratorHasAddedUrlAsTrustedServer(string $url):void {
* @param string $url
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorDeletesUrlFromTrustedServersUsingTheTestingApi(string $url):void {
$adminUser = $this->featureContext->getAdminUsername();
Expand Down Expand Up @@ -514,6 +529,7 @@ public function urlShouldNotBeATrustedServer(string $url):void {
* @When the administrator deletes all trusted servers using the testing API
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorDeletesAllTrustedServersUsingTheTestingApi():void {
$adminUser = $this->featureContext->getAdminUsername();
Expand Down Expand Up @@ -564,6 +580,7 @@ public function theTrustedServerListShouldBeEmpty():void {
* Expires last created share using the testing API
*
* @return void
* @throws GuzzleException
*/
public function expireLastCreatedUserShare():void {
$adminUser = $this->featureContext->getAdminUsername();
Expand All @@ -585,6 +602,7 @@ public function expireLastCreatedUserShare():void {
* @Given the administrator has expired the last created share using the testing API
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorHasExpiredTheLastCreatedShare():void {
$this->expireLastCreatedUserShare();
Expand All @@ -599,6 +617,7 @@ public function theAdministratorHasExpiredTheLastCreatedShare():void {
* @When the administrator expires the last created share using the testing API
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorExpiresTheLastCreatedShare():void {
$this->expireLastCreatedUserShare();
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,7 @@ public function theHTTPStatusCodeShouldBe($expectedStatusCode, ?string $message
$message
);
}
$this->emptyLastHTTPStatusCodesArray();
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/acceptance/features/bootstrap/FederationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class FederationContext implements Context {
* @param string|null $expireDate
*
* @return void
* @throws JsonException
*/
public function userFromServerSharesWithUserFromServerUsingTheSharingAPI(
string $sharerUser,
Expand Down Expand Up @@ -89,6 +90,7 @@ public function userFromServerSharesWithUserFromServerUsingTheSharingAPI(
* @param string|null $expireDate
*
* @return void
* @throws JsonException
*/
public function userFromServerSharesWithUserFromServerUsingTheSharingAPIWithPermissions(
string $sharerUser,
Expand Down Expand Up @@ -120,6 +122,7 @@ public function userFromServerSharesWithUserFromServerUsingTheSharingAPIWithPerm
null,
$expireDate
);
$this->featureContext->pushToLastStatusCodesArrays();
$this->featureContext->usingServer($previous);
}

Expand Down Expand Up @@ -155,6 +158,7 @@ public function userFromServerHasSharedWithUserFromServer(
$this->featureContext->getResponse()
) . '"'
);
$this->featureContext->emptyLastHTTPStatusCodesArray();
}

/**
Expand Down Expand Up @@ -254,6 +258,7 @@ public function userFromServerAcceptsLastPendingShareUsingTheSharingAPI(string $
"/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}",
null
);
$this->featureContext->pushToLastStatusCodesArrays();
$this->featureContext->usingServer($previous);
}

Expand All @@ -272,6 +277,7 @@ public function userFromServerHasAcceptedLastPendingShare(string $user, string $
$server
);
$this->ocsContext->assertOCSResponseIndicatesSuccess();
$this->featureContext->emptyLastHTTPStatusCodesArray();
}

/**
Expand Down Expand Up @@ -302,6 +308,7 @@ public function userRetrievesInformationOfLastFederatedShare(string $user):void
* @param string $user
*
* @return void
* @throws Exception
*/
public function userShouldHaveNoLastPendingFederatedCloudShare(string $user):void {
$this->userGetsTheListOfPendingFederatedCloudShares($user);
Expand All @@ -312,6 +319,7 @@ public function userShouldHaveNoLastPendingFederatedCloudShare(string $user):voi
__METHOD__
. " No pending federated cloud shares were expected, but got unexpectedly."
);
$this->featureContext->emptyLastHTTPStatusCodesArray();
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/features/bootstrap/OCSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ public function theOCSStatusCodeShouldBe(string $statusCode, $message = ""):void
$statusCodes,
$message
);
$this->featureContext->emptyLastOCSStatusCodesArray();
} else {
if ($message === "") {
$message = "OCS status code is not the expected value " . $statusCodes . " got " . $responseStatusCode;
Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ public function addToListOfCreatedPublicLinks(string $name, string $url):void {
* @param string $sharingApp
*
* @return void
* @throws JsonException
* @throws Exception
*/
public function createShare(
string $user,
Expand Down
36 changes: 28 additions & 8 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ public function userMovesEntriesUsingTheAPI(
* @param string $fileDestination
*
* @return void
* @throws JsonException
* @throws GuzzleException
*/
public function userMovesFileUsingTheAPI(
string $user,
Expand All @@ -751,7 +753,6 @@ public function userMovesFileUsingTheAPI(
}
}
try {
$this->emptyLastHTTPStatusCodesArray();
$this->response = $this->makeDavRequest(
$user,
"MOVE",
Expand Down Expand Up @@ -2452,6 +2453,7 @@ public function theHTTPStatusCodeOfResponsesOnAllEndpointsShouldBe(int $statusCo
\intval($duplicateRemovedStatusCodes[0]),
'Responses did not return expected http status code'
);
$this->emptyLastHTTPStatusCodesArray();
} else {
throw new Exception(
'Expected same but found different http status codes of last requested responses.' .
Expand Down Expand Up @@ -2496,13 +2498,20 @@ public function theHTTPStatusCodeOfResponsesOnEachEndpointShouldBe(string $statu
* @throws Exception
*/
public function theOCStatusCodeOfResponsesOnEachEndpointShouldBe(string $statusCodes):void {
$NOT_SET = "notset";
$statusCodes = \explode(',', $statusCodes);
$count = \count($statusCodes);
if ($count === \count($this->lastOCSStatusCodesArray)) {
for ($i = 0; $i < $count; $i++) {
$actualCode = $this->lastOCSStatusCodesArray[$i];
$expectedCode = \trim($statusCodes[$i]);
if ($expectedCode !== $NOT_SET) {
$actualCode = \intval($actualCode);
$expectedCode = \intval($expectedCode);
}
Assert::assertSame(
(int)\trim($statusCodes[$i]),
(int)$this->lastOCSStatusCodesArray[$i],
$expectedCode,
$actualCode,
'Responses did not return expected OCS status code'
);
}
Expand Down Expand Up @@ -2536,7 +2545,7 @@ public function theHTTPStatusCodeOfResponsesOnAllEndpointsShouldBeOr(string $sta
/**
* @Then the OCS status code of responses on all endpoints should be :statusCode
*
* @param $statusCode
* @param string $statusCode
*
* @return void
* @throws Exception
Expand All @@ -2549,6 +2558,7 @@ public function theOCSStatusCodeOfResponsesOnAllEndpointsShouldBe(string $status
\intval($duplicateRemovedStatusCodes[0]),
'Responses did not return expected ocs status code'
);
$this->emptyLastOCSStatusCodesArray();
} else {
throw new Exception(
'Expected same but found different ocs status codes of last requested responses.' .
Expand Down Expand Up @@ -2860,6 +2870,7 @@ public function userUploadsAFileToEndingWithOfSizeBytes(string $user, string $de
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userUploadsFilesWithContentTo(
string $user,
Expand Down Expand Up @@ -2891,6 +2902,8 @@ public function userUploadsFilesWithContentTo(
* @param string $destination
*
* @return string[]
* @throws JsonException
* @throws GuzzleException
*/
public function uploadFileWithContent(
string $user,
Expand Down Expand Up @@ -2955,14 +2968,17 @@ public function adminHasUploadedAFileWithContentTo(
* @param string|null $content
* @param string $destination
*
* @return string[]
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function userUploadsAFileWithContentTo(
string $user,
?string $content,
string $destination
):array {
return $this->uploadFileWithContent($user, $content, $destination);
):void {
$this->uploadFileWithContent($user, $content, $destination);
$this->pushToLastStatusCodesArrays();
}

/**
Expand All @@ -2973,7 +2989,7 @@ public function userUploadsAFileWithContentTo(
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws Exception|GuzzleException
*/
public function userUploadsFollowingFilesWithContentTo(
string $user,
Expand Down Expand Up @@ -3561,6 +3577,7 @@ public function userOnHasDeletedFile(string $user, string $server, string $delet
* @param string $destination
*
* @return void
* @throws JsonException | GuzzleException
*/
public function userCreatesFolder(string $user, string $destination):void {
$user = $this->getActualUsername($user);
Expand All @@ -3574,6 +3591,7 @@ public function userCreatesFolder(string $user, string $destination):void {
$this->setResponseXml(
HttpRequestHelper::parseResponseAsXml($this->response)
);
$this->pushToLastStatusCodesArrays();
}

/**
Expand All @@ -3583,6 +3601,7 @@ public function userCreatesFolder(string $user, string $destination):void {
* @param string $destination
*
* @return void
* @throws JsonException
*/
public function userHasCreatedFolder(string $user, string $destination):void {
$user = $this->getActualUsername($user);
Expand All @@ -3591,6 +3610,7 @@ public function userHasCreatedFolder(string $user, string $destination):void {
["201", "204"],
"HTTP status code was not 201 or 204 while trying to create folder '$destination' for user '$user'"
);
$this->emptyLastHTTPStatusCodesArray();
}

/**
Expand Down

0 comments on commit 023069e

Please sign in to comment.