From cd87508020af447a0f684a09458a54d4c2d0a13a Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 22 Dec 2021 09:31:18 +0545 Subject: [PATCH 1/3] Refactor userHasSharedSpace --- .../features/bootstrap/SpacesContext.php | 37 ++++--------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 0ce7094aa..14b2ea8a8 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -244,7 +244,7 @@ class SpacesContext implements Context { string $baseUrl, string $user, string $password, - string $urlArguments, + string $urlArguments = '', string $xRequestId = '', array $body = [], array $headers = [] @@ -351,9 +351,7 @@ class SpacesContext implements Context { $this->listSpacesRequest( $this->featureContext->getBaseUrl(), $user, - $this->featureContext->getPasswordForUser($user), - "", - "" + $this->featureContext->getPasswordForUser($user) ) ); $this->rememberTheAvailableSpaces(); @@ -383,8 +381,7 @@ class SpacesContext implements Context { $this->featureContext->getBaseUrl(), $user, $this->featureContext->getPasswordForUser($user), - $body, - "" + $body ) ); $this->setSpaceCreator($spaceName, $user); @@ -416,8 +413,7 @@ class SpacesContext implements Context { $this->featureContext->getBaseUrl(), $user, $this->featureContext->getPasswordForUser($user), - $body, - "" + $body ) ); $this->setSpaceCreator($spaceName, $user); @@ -1108,8 +1104,7 @@ class SpacesContext implements Context { $this->featureContext->getBaseUrl(), $user, $this->featureContext->getPasswordForUser($user), - $body, - "" + $body ) ); $this->featureContext->theHTTPStatusCodeShouldBe( @@ -1205,27 +1200,9 @@ class SpacesContext implements Context { string $spaceName, string $userRecipient ): void { - $space = $this->getSpaceByName($user, $spaceName); - $body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient]; + $this->sendShareSpaceRequest($user, $spaceName, $userRecipient); - $baseUrl = $this->featureContext->getBaseUrl(); - if (!str_ends_with($baseUrl, '/')) { - $baseUrl .= '/'; - } - $fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares"; - - $this->featureContext->setResponse( - HttpRequestHelper::post( - $fullUrl, - "", - $user, - $this->featureContext->getPasswordForUser($user), - [], - $body - ) - ); - - $expectedHTTPStatus = "200"; + $expectedHTTPStatus = "200"; $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHTTPStatus, "Expected response status code should be $expectedHTTPStatus" From 5dc6573efcfa5ba96105b683383ffdc3c640f2ca Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 22 Dec 2021 09:49:44 +0545 Subject: [PATCH 2/3] Refactor baseUrl in SpacesContext --- .../features/bootstrap/SpacesContext.php | 66 +++++++------------ 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 14b2ea8a8..85249c39c 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -46,6 +46,11 @@ class SpacesContext implements Context { */ private OCSContext $ocsContext; + /** + * @var string + */ + private string $baseUrl; + /** * @var array key is space name and value is the username that created the space */ @@ -217,10 +222,11 @@ class SpacesContext implements Context { $this->ocsContext = $environment->getContext('OCSContext'); // Run the BeforeScenario function in OCSContext to set it up correctly $this->ocsContext->before($scope); + $this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/"); SetupHelper::init( $this->featureContext->getAdminUsername(), $this->featureContext->getAdminPassword(), - $this->featureContext->getBaseUrl(), + $this->baseUrl, $this->featureContext->getOcPath() ); } @@ -249,11 +255,7 @@ class SpacesContext implements Context { array $body = [], array $headers = [] ): ResponseInterface { - $fullUrl = $baseUrl; - if (!str_ends_with($fullUrl, '/')) { - $fullUrl .= '/'; - } - $fullUrl .= "graph/v1.0/me/drives/" . $urlArguments; + $fullUrl = $baseUrl . "/graph/v1.0/me/drives/" . $urlArguments; return HttpRequestHelper::get($fullUrl, $xRequestId, $user, $password, $headers, $body); } @@ -280,11 +282,7 @@ class SpacesContext implements Context { string $xRequestId = '', array $headers = [] ): ResponseInterface { - $fullUrl = $baseUrl; - if (!str_ends_with($fullUrl, '/')) { - $fullUrl .= '/'; - } - $fullUrl .= "graph/v1.0/drives/"; + $fullUrl = $baseUrl . "/graph/v1.0/drives/"; return HttpRequestHelper::post($fullUrl, $xRequestId, $user, $password, $headers, $body); } @@ -349,7 +347,7 @@ class SpacesContext implements Context { public function theUserListsAllHisAvailableSpacesUsingTheGraphApi(string $user): void { $this->featureContext->setResponse( $this->listSpacesRequest( - $this->featureContext->getBaseUrl(), + $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user) ) @@ -378,7 +376,7 @@ class SpacesContext implements Context { $body = json_encode($space, JSON_THROW_ON_ERROR); $this->featureContext->setResponse( $this->sendCreateSpaceRequest( - $this->featureContext->getBaseUrl(), + $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body @@ -410,7 +408,7 @@ class SpacesContext implements Context { $body = json_encode($space); $this->featureContext->setResponse( $this->sendCreateSpaceRequest( - $this->featureContext->getBaseUrl(), + $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body @@ -438,12 +436,8 @@ class SpacesContext implements Context { $accounts = []; $assignment = []; - $baseUrl = $this->featureContext->getBaseUrl(); - if (!str_ends_with($baseUrl, '/')) { - $baseUrl .= '/'; - } // get the roles list first - $fullUrl = $baseUrl . "api/v0/settings/roles-list"; + $fullUrl = $this->baseUrl . "/api/v0/settings/roles-list"; $this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}")); if ($this->featureContext->getResponse()) { $rawBody = $this->featureContext->getResponse()->getBody()->getContents(); @@ -461,7 +455,7 @@ class SpacesContext implements Context { Assert::assertNotEmpty($roleToAssign, "The selected role $role could not be found"); // get the accounts list first - $fullUrl = $baseUrl . "api/v0/accounts/accounts-list"; + $fullUrl = $this->baseUrl . "/api/v0/accounts/accounts-list"; $this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}")); if ($this->featureContext->getResponse()) { $rawBody = $this->featureContext->getResponse()->getBody()->getContents(); @@ -479,7 +473,7 @@ class SpacesContext implements Context { Assert::assertNotEmpty($accountToChange, "The selected account $user does not exist"); // set the new role - $fullUrl = $baseUrl . "api/v0/settings/assignments-add"; + $fullUrl = $this->baseUrl . "/api/v0/settings/assignments-add"; $body = json_encode(["account_uuid" => $accountToChange["id"], "role_id" => $roleToAssign["id"]], JSON_THROW_ON_ERROR); $this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, $body)); @@ -870,11 +864,7 @@ class SpacesContext implements Context { $space = $this->getSpaceByName($ownerUser, $spaceName); - $baseUrl = $this->featureContext->getBaseUrl(); - if (!str_ends_with($baseUrl, '/')) { - $baseUrl .= '/'; - } - $fullUrl = $baseUrl . "dav/spaces/" . $space['id'] . '/' . $folder; + $fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $folder; $this->featureContext->setResponse( $this->sendCreateFolderRequest( @@ -1005,7 +995,7 @@ class SpacesContext implements Context { $this->featureContext->setResponse( $this->sendUpdateSpaceRequest( - $this->featureContext->getBaseUrl(), + $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body, @@ -1038,7 +1028,7 @@ class SpacesContext implements Context { $this->featureContext->setResponse( $this->sendUpdateSpaceRequest( - $this->featureContext->getBaseUrl(), + $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body, @@ -1071,11 +1061,7 @@ class SpacesContext implements Context { string $xRequestId = '', array $headers = [] ): ResponseInterface { - $fullUrl = $baseUrl; - if (!str_ends_with($fullUrl, '/')) { - $fullUrl .= '/'; - } - $fullUrl .= "graph/v1.0/drives/$spaceId"; + $fullUrl = $baseUrl . "/graph/v1.0/drives/$spaceId"; $method = 'PATCH'; return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers, $body); @@ -1101,7 +1087,7 @@ class SpacesContext implements Context { $body = json_encode($space); $this->featureContext->setResponse( $this->sendCreateSpaceRequest( - $this->featureContext->getBaseUrl(), + $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body @@ -1167,11 +1153,7 @@ class SpacesContext implements Context { $space = $this->getSpaceByName($user, $spaceName); $body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient]; - $baseUrl = $this->featureContext->getBaseUrl(); - if (!str_ends_with($baseUrl, '/')) { - $baseUrl .= '/'; - } - $fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares"; + $fullUrl = $this->baseUrl . "/ocs/v2.php/apps/files_sharing/api/v1/shares"; $this->featureContext->setResponse( HttpRequestHelper::post( @@ -1227,11 +1209,7 @@ class SpacesContext implements Context { string $userRecipient ): void { $space = $this->getSpaceByName($user, $spaceName); - $baseUrl = $this->featureContext->getBaseUrl(); - if (!str_ends_with($baseUrl, '/')) { - $baseUrl .= '/'; - } - $fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient; + $fullUrl = $this->baseUrl . "/ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient; HttpRequestHelper::delete($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user)); } From 60c41c4f6f52ae21b8cad8d665f56ed0bf699ae3 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 22 Dec 2021 10:25:28 +0545 Subject: [PATCH 3/3] More baseUrl refactoring --- .../features/bootstrap/SpacesContext.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 85249c39c..7de32c7e3 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -234,7 +234,6 @@ class SpacesContext implements Context { /** * Send Graph List Spaces Request * - * @param string $baseUrl * @param string $user * @param string $password * @param string $urlArguments @@ -247,7 +246,6 @@ class SpacesContext implements Context { * @throws GuzzleException */ public function listSpacesRequest( - string $baseUrl, string $user, string $password, string $urlArguments = '', @@ -255,7 +253,7 @@ class SpacesContext implements Context { array $body = [], array $headers = [] ): ResponseInterface { - $fullUrl = $baseUrl . "/graph/v1.0/me/drives/" . $urlArguments; + $fullUrl = $this->baseUrl . "/graph/v1.0/me/drives/" . $urlArguments; return HttpRequestHelper::get($fullUrl, $xRequestId, $user, $password, $headers, $body); } @@ -263,7 +261,6 @@ class SpacesContext implements Context { /** * Send Graph Create Space Request * - * @param string $baseUrl * @param string $user * @param string $password * @param string $body @@ -275,14 +272,13 @@ class SpacesContext implements Context { * @throws GuzzleException */ public function sendCreateSpaceRequest( - string $baseUrl, string $user, string $password, string $body, string $xRequestId = '', array $headers = [] ): ResponseInterface { - $fullUrl = $baseUrl . "/graph/v1.0/drives/"; + $fullUrl = $this->baseUrl . "/graph/v1.0/drives/"; return HttpRequestHelper::post($fullUrl, $xRequestId, $user, $password, $headers, $body); } @@ -347,7 +343,6 @@ class SpacesContext implements Context { public function theUserListsAllHisAvailableSpacesUsingTheGraphApi(string $user): void { $this->featureContext->setResponse( $this->listSpacesRequest( - $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user) ) @@ -376,7 +371,6 @@ class SpacesContext implements Context { $body = json_encode($space, JSON_THROW_ON_ERROR); $this->featureContext->setResponse( $this->sendCreateSpaceRequest( - $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body @@ -408,7 +402,6 @@ class SpacesContext implements Context { $body = json_encode($space); $this->featureContext->setResponse( $this->sendCreateSpaceRequest( - $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body @@ -995,7 +988,6 @@ class SpacesContext implements Context { $this->featureContext->setResponse( $this->sendUpdateSpaceRequest( - $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body, @@ -1028,7 +1020,6 @@ class SpacesContext implements Context { $this->featureContext->setResponse( $this->sendUpdateSpaceRequest( - $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body, @@ -1040,7 +1031,6 @@ class SpacesContext implements Context { /** * Send Graph Update Space Request * - * @param string $baseUrl * @param string $user * @param string $password * @param mixed $body @@ -1053,7 +1043,6 @@ class SpacesContext implements Context { * @throws GuzzleException */ public function sendUpdateSpaceRequest( - string $baseUrl, string $user, string $password, $body, @@ -1061,7 +1050,7 @@ class SpacesContext implements Context { string $xRequestId = '', array $headers = [] ): ResponseInterface { - $fullUrl = $baseUrl . "/graph/v1.0/drives/$spaceId"; + $fullUrl = $this->baseUrl . "/graph/v1.0/drives/$spaceId"; $method = 'PATCH'; return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers, $body); @@ -1087,7 +1076,6 @@ class SpacesContext implements Context { $body = json_encode($space); $this->featureContext->setResponse( $this->sendCreateSpaceRequest( - $this->baseUrl, $user, $this->featureContext->getPasswordForUser($user), $body