diff --git a/tests/acceptance/features/bootstrap/ArchiverContext.php b/tests/acceptance/features/bootstrap/ArchiverContext.php index e9415c12b44..fbd93b3d2aa 100644 --- a/tests/acceptance/features/bootstrap/ArchiverContext.php +++ b/tests/acceptance/features/bootstrap/ArchiverContext.php @@ -28,6 +28,7 @@ use TestHelpers\SetupHelper; use wapmorgan\UnifiedArchive\UnifiedArchive; use PHPUnit\Framework\Assert; +use \Psr\Http\Message\ResponseInterface; require_once 'bootstrap.php'; @@ -118,18 +119,7 @@ public function userDownloadsTheArchive( foreach ($headersTable as $row) { $headers[$row['header']] = $row ['value']; } - - $user = $this->featureContext->getActualUsername($user); - $queryString = $this->getArchiverQueryString($user, $resource, $addressType); - $this->featureContext->setResponse( - HttpRequestHelper::get( - $this->featureContext->getBaseUrl() . '/archiver?' . $queryString, - '', - $user, - $this->featureContext->getPasswordForUser($user), - $headers - ) - ); + $this->featureContext->setResponse($this->downloadArchive($user, $resource, $addressType, null, $headers)); } /** @@ -151,15 +141,36 @@ public function userDownloadsTheArchiveOfItemOfUser( string $owner, string $addressType ): void { + $this->featureContext->setResponse($this->downloadArchive($downloader, $resource, $addressType, $owner)); + } + + /** + * @param string $downloader + * @param string $resource + * @param string $addressType + * @param string|null $owner + * @param array|null $headers + * + * @return ResponseInterface + * @throws GuzzleException + * @throws JsonException + */ + public function downloadArchive( + string $downloader, + string $resource, + string $addressType, + ?string $owner = null, + ?array $headers = null + ): ResponseInterface { + $owner = $owner ?? $downloader; $downloader = $this->featureContext->getActualUsername($downloader); $queryString = $this->getArchiverQueryString($owner, $resource, $addressType); - $this->featureContext->setResponse( - HttpRequestHelper::get( - $this->featureContext->getBaseUrl() . '/archiver?' . $queryString, - '', - $downloader, - $this->featureContext->getPasswordForUser($downloader), - ) + return HttpRequestHelper::get( + $this->featureContext->getBaseUrl() . '/archiver?' . $queryString, + '', + $downloader, + $this->featureContext->getPasswordForUser($downloader), + $headers ); } diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index 3e796e08cce..b18f2591edd 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -26,6 +26,7 @@ use PHPUnit\Framework\Assert; use TestHelpers\HttpRequestHelper; use TestHelpers\WebDavHelper; +use Psr\Http\Message\ResponseInterface; require_once 'bootstrap.php'; @@ -55,20 +56,7 @@ private function getVersionsPathForFileId(string $fileId):string { * @throws Exception */ public function userTriesToGetFileVersions(string $user, string $file, string $fileOwner):void { - $user = $this->featureContext->getActualUsername($user); - $fileOwner = $this->featureContext->getActualUsername($fileOwner); - $fileId = $this->featureContext->getFileIdForPath($fileOwner, $file); - Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $file user $fileOwner not found (the file may not exist)"); - $response = $this->featureContext->makeDavRequest( - $user, - "PROPFIND", - $this->getVersionsPathForFileId($fileId), - null, - null, - null, - '2' - ); - $this->featureContext->setResponse($response, $user); + $this->featureContext->setResponse($this->getFileVersions($user, $file, $fileOwner)); } /** @@ -81,10 +69,28 @@ public function userTriesToGetFileVersions(string $user, string $file, string $f * @throws Exception */ public function userGetsFileVersions(string $user, string $file):void { + $this->featureContext->setResponse($this->getFileVersions($user, $file)); + } + + /** + * @param string $user + * @param string $file + * @param string|null $fileOwner + * + * @return ResponseInterface + * @throws JsonException + * @throws GuzzleException + */ + public function getFileVersions( + string $user, + string $file, + ?string $fileOwner = null + ): ResponseInterface { $user = $this->featureContext->getActualUsername($user); - $fileId = $this->featureContext->getFileIdForPath($user, $file); - Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $file user $user not found (the file may not exist)"); - $response = $this->featureContext->makeDavRequest( + $fileOwner = $fileOwner ? $this->featureContext->getActualUsername($fileOwner) : $user; + $fileId = $this->featureContext->getFileIdForPath($fileOwner, $file); + Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $file user $fileOwner not found (the file may not exist)"); + return $this->featureContext->makeDavRequest( $user, "PROPFIND", $this->getVersionsPathForFileId($fileId), @@ -93,7 +99,6 @@ public function userGetsFileVersions(string $user, string $file):void { null, '2' ); - $this->featureContext->setResponse($response, $user); } /** diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index b1a80d9038d..9165daae010 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -263,33 +263,6 @@ public function adminHasRetrievedUserUsingTheGraphApi(string $user): void { $this->featureContext->thenTheHTTPStatusCodeShouldBe(200); } - /** - * @param $requestingUser - * @param $targetUser - * - * @return void - * @throws JsonException - * @throws GuzzleException - */ - public function userHasRetrievedUserUsingTheGraphApi( - $requestingUser, - $targetUser - ): void { - $requester = $this->featureContext->getActualUsername($requestingUser); - $requesterPassword = $this->featureContext->getPasswordForUser($requestingUser); - $user = $this->featureContext->getActualUsername($targetUser); - $userId = $this->featureContext->getAttributeOfCreatedUser($user, "id"); - $response = GraphHelper::getUser( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $requester, - $requesterPassword, - $userId - ); - $this->featureContext->setResponse($response); - $this->featureContext->thenTheHTTPStatusCodeShouldBe(200); - } - /** * @param string $groupId * @param string|null $user @@ -2423,8 +2396,26 @@ public function userTriesToExportGdprReportOfAnotherUserUsingGraphApi(string $us } /** - * @When user :user unassigns the role of user :ofUser using the Graph API - * @When user :user tries to unassign the role of user :ofUser using the Graph API + * @param string $user + * + * @return ResponseInterface + * @throws GuzzleException + */ + public function getAssignedRole(string $user) { + $userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id') ?? $user; + return ( + GraphHelper::getAssignedRole( + $this->featureContext->getBAseUrl(), + $this->featureContext->getStepLineRef(), + $this->featureContext->getAdminUsername(), + $this->featureContext->getAdminPassword(), + $userId + ) + ); + } + + /** + * @When /^user "([^"]*)" (?:unassigns|tries to unassign) the role of user "([^"]*)" using the Graph API$/ * * @param string $user * @param string $ofUser @@ -2437,15 +2428,7 @@ public function userTriesToExportGdprReportOfAnotherUserUsingGraphApi(string $us public function theUserUnassignsTheRoleOfUserUsingTheGraphApi(string $user, string $ofUser): void { $userId = $this->featureContext->getAttributeOfCreatedUser($ofUser, 'id') ?? $ofUser; $credentials = $this->getAdminOrUserCredentials($user); - - $response = GraphHelper::getAssignedRole( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), - $userId - ); - $appRoleAssignmentId = $this->featureContext->getJsonDecodedResponse($response)["value"][0]["id"]; + $appRoleAssignmentId = $this->featureContext->getJsonDecodedResponse($this->getAssignedRole($ofUser))["value"][0]["id"]; $this->featureContext->setResponse( GraphHelper::unassignRole( @@ -2470,16 +2453,7 @@ public function theUserUnassignsTheRoleOfUserUsingTheGraphApi(string $user, stri * @throws Exception */ public function userShouldHaveTheRoleAssigned(string $user, string $role): void { - $userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id') ?? $user; - $response = GraphHelper::getAssignedRole( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $this->featureContext->getAdminUserName(), - $this->featureContext->getAdminPassword(), - $userId - ); - - $jsonDecodedResponse = $this->featureContext->getJsonDecodedResponse($response)['value'][0]; + $jsonDecodedResponse = $this->featureContext->getJsonDecodedResponse($this->getAssignedRole($user))['value'][0]; if (empty($this->appEntity)) { $this->setApplicationEntity(); } @@ -2502,16 +2476,7 @@ public function userShouldHaveTheRoleAssigned(string $user, string $role): void * @throws Exception */ public function userShouldNotHaveAnyRoleAssigned(string $user): void { - $userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id') ?? $user; - $response = GraphHelper::getAssignedRole( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $this->featureContext->getAdminUserName(), - $this->featureContext->getAdminPassword(), - $userId - ); - - $jsonDecodedResponse = $this->featureContext->getJsonDecodedResponse($response)['value']; + $jsonDecodedResponse = $this->featureContext->getJsonDecodedResponse($this->getAssignedRole($user))['value']; Assert::assertEmpty( $jsonDecodedResponse, __METHOD__ diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 7845bfc26bb..41d121df2dc 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -1458,96 +1458,6 @@ public function theAdministratorCreatesUserPasswordGroupUsingTheProvisioningApi( $this->manuallyAddSkeletonFilesForUser($user, $password); } - /** - * @When /^the groupadmin "([^"]*)" sends a user creation request for user "([^"]*)" password "([^"]*)" group "([^"]*)" using the provisioning API$/ - * - * @param string $groupadmin - * @param string $userToCreate - * @param string $password - * @param string $group - * - * @return void - * @throws Exception - */ - public function theGroupAdminCreatesUserPasswordGroupUsingTheProvisioningApi( - string $groupadmin, - string $userToCreate, - string $password, - string $group - ):void { - $userToCreate = $this->getActualUsername($userToCreate); - $password = $this->getActualPassword($password); - $email = $userToCreate . '@owncloud.com'; - $bodyTable = new TableNode( - [ - ['userid', $userToCreate], - ['password', $userToCreate], - ['username', $userToCreate], - ['email', $email], - ['groups[]', $group], - ] - ); - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( - $groupadmin, - "POST", - "/cloud/users", - $bodyTable - ); - $this->addUserToCreatedUsersList( - $userToCreate, - $password, - null, - $email, - null, - $this->theHTTPStatusCodeWasSuccess() - ); - $this->manuallyAddSkeletonFilesForUser($userToCreate, $password); - } - - /** - * @When /^the groupadmin "([^"]*)" tries to create new user "([^"]*)" password "([^"]*)" in other group "([^"]*)" using the provisioning API$/ - * - * @param string $groupadmin - * @param string $userToCreate - * @param string|null $password - * @param string $group - * - * @return void - */ - public function theGroupAdminCreatesUserPasswordInOtherGroupUsingTheProvisioningApi( - string $groupadmin, - string $userToCreate, - ?string $password, - string $group - ):void { - $userToCreate = $this->getActualUsername($userToCreate); - $password = $this->getActualPassword($password); - $email = $userToCreate . '@owncloud.com'; - $bodyTable = new TableNode( - [ - ['userid', $userToCreate], - ['password', $userToCreate], - ['username', $userToCreate], - ['email', $email], - ['groups[]', $group], - ] - ); - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( - $groupadmin, - "POST", - "/cloud/users", - $bodyTable - ); - $this->addUserToCreatedUsersList( - $userToCreate, - $password, - null, - $email, - null, - $this->theHTTPStatusCodeWasSuccess() - ); - } - /** * @param string $username * @param string|null $password @@ -2420,25 +2330,6 @@ public function adminRetrievesTheInformationOfUserUsingTheProvisioningApi( ); } - /** - * @Given /^the administrator has retrieved the information of user "([^"]*)"$/ - * - * @param string $user - * - * @return void - * @throws JsonException - */ - public function adminHasRetrievedTheInformationOfUserUsingTheProvisioningApi( - string $user - ):void { - if (OcisHelper::isTestingWithGraphApi()) { - $this->graphContext->adminHasRetrievedUserUsingTheGraphApi($user); - } else { - $this->retrieveUserInformationAsAdminUsingProvisioningApi($user); - $this->theHTTPStatusCodeShouldBeSuccess(); - } - } - /** * @param string $requestingUser * @param string $targetUser @@ -2480,33 +2371,6 @@ public function userRetrievesTheInformationOfUserUsingTheProvisioningApi( ); } - /** - * @Given /^user "([^"]*)" has retrieved the information of user "([^"]*)"$/ - * - * @param string $requestingUser - * @param string $targetUser - * - * @return void - * @throws JsonException - */ - public function userHasRetrievedTheInformationOfUserUsingTheProvisioningApi( - string $requestingUser, - string $targetUser - ):void { - if (OcisHelper::isTestingWithGraphApi()) { - $this->graphContext->userHasRetrievedUserUsingTheGraphApi( - $requestingUser, - $targetUser - ); - } else { - $this->userRetrieveUserInformationUsingProvisioningApi( - $requestingUser, - $targetUser - ); - $this->theHTTPStatusCodeShouldBeSuccess(); - } - } - /** * @Then /^user "([^"]*)" should exist$/ * diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 013099414fc..863f7f2d352 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -2354,20 +2354,24 @@ public function userGetsAllSharesSharedWithHimFromFileOrFolderUsingTheProvisioni } /** - * @When user :user gets all shares shared by him/her using the sharing API - * * @param string $user + * @param string|null $endpointPath * - * @return void + * @return ResponseInterface + * @throws JsonException + * @throws GuzzleException */ - public function userGetsAllSharesSharedByHimUsingTheSharingApi(string $user):void { + public function getAllShares( + string $user, + ?string $endpointPath = null + ): ResponseInterface { $user = $this->getActualUsername($user); - $this->response = OcsApiHelper::sendRequest( + return OcsApiHelper::sendRequest( $this->getBaseUrl(), $user, $this->getPasswordForUser($user), "GET", - $this->getSharesEndpointPath(), + $this->getSharesEndpointPath($endpointPath), $this->getStepLineRef(), [], $this->ocsApiVersion @@ -2375,12 +2379,23 @@ public function userGetsAllSharesSharedByHimUsingTheSharingApi(string $user):voi } /** - * @When the administrator gets all shares shared by him/her using the sharing API + * @When /^user "([^"]*)" gets all shares shared by (?:him|her) using the sharing API$/ + * + * @param string $user + * + * @return void + */ + public function userGetsAllSharesSharedByHimUsingTheSharingApi(string $user):void { + $this->setResponse($this->getAllshares($user)); + } + + /** + * @When /^the administrator gets all shares shared by (?:him|her) using the sharing API$/ * * @return void */ public function theAdministratorGetsAllSharesSharedByHimUsingTheSharingApi():void { - $this->userGetsAllSharesSharedByHimUsingTheSharingApi($this->getAdminUsername()); + $this->setResponse($this->getAllShares($this->getAdminUsername())); } /** @@ -2392,7 +2407,6 @@ public function theAdministratorGetsAllSharesSharedByHimUsingTheSharingApi():voi * @return void */ public function userGetsFilteredSharesSharedByHimUsingTheSharingApi(string $user, string $shareType):void { - $user = $this->getActualUsername($user); if ($shareType === 'public link') { $shareType = 'public_link'; } @@ -2401,16 +2415,7 @@ public function userGetsFilteredSharesSharedByHimUsingTheSharingApi(string $user } else { $rawShareTypes = SharingHelper::SHARE_TYPES[$shareType]; } - $this->response = OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $user, - $this->getPasswordForUser($user), - "GET", - $this->getSharesEndpointPath("?share_types=" . $rawShareTypes), - $this->getStepLineRef(), - [], - $this->ocsApiVersion - ); + $this->setResponse($this->getAllShares($user, "?share_types=" . $rawShareTypes)); } /** @@ -2422,17 +2427,7 @@ public function userGetsFilteredSharesSharedByHimUsingTheSharingApi(string $user * @return void */ public function userGetsAllTheSharesFromTheFileUsingTheSharingApi(string $user, string $path):void { - $user = $this->getActualUsername($user); - $this->response = OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $user, - $this->getPasswordForUser($user), - "GET", - $this->getSharesEndpointPath("?path=$path"), - $this->getStepLineRef(), - [], - $this->ocsApiVersion - ); + $this->setResponse($this->getAllShares($user, "?path=$path")); } /** @@ -2447,17 +2442,7 @@ public function userGetsAllTheSharesWithResharesFromTheFileUsingTheSharingApi( string $user, string $path ):void { - $userActual = $this->getActualUsername($user); - $this->response = OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $userActual, - $this->getPasswordForUser($user), - "GET", - $this->getSharesEndpointPath("?reshares=true&path=$path"), - $this->getStepLineRef(), - [], - $this->ocsApiVersion - ); + $this->setResponse($this->getAllShares($user, "?reshares=true&path=$path")); } /** @@ -2469,17 +2454,7 @@ public function userGetsAllTheSharesWithResharesFromTheFileUsingTheSharingApi( * @return void */ public function userGetsAllTheSharesInsideTheFolderUsingTheSharingApi(string $user, string $path):void { - $user = $this->getActualUsername($user); - $this->response = OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $user, - $this->getPasswordForUser($user), - "GET", - $this->getSharesEndpointPath("?path=$path&subfiles=true"), - $this->getStepLineRef(), - [], - $this->ocsApiVersion - ); + $this->setResponse($this->getAllShares($user, "?path=$path&subfiles=true")); } /** diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 8ffe26920ae..3c446abc63b 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -571,44 +571,13 @@ public function theUserLooksUpTheSingleSpaceUsingTheGraphApiByUsingItsId(string } /** + * @When /^user "([^"]*)" (?:creates|tries to create) a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)" using the Graph API$/ * @When /^user "([^"]*)" (?:creates|tries to create) a space "([^"]*)" of type "([^"]*)" with the default quota using the Graph API$/ * * @param string $user * @param string $spaceName * @param string $spaceType - * - * @return void - * - * @throws GuzzleException - * @throws Exception - */ - public function theUserCreatesASpaceUsingTheGraphApi( - string $user, - string $spaceName, - string $spaceType - ): void { - $space = ["Name" => $spaceName, "driveType" => $spaceType]; - $body = json_encode($space, JSON_THROW_ON_ERROR); - $this->featureContext->setResponse( - GraphHelper::createSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $body - ) - ); - - $this->setSpaceCreator($spaceName, $user); - } - - /** - * @When /^user "([^"]*)" creates a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)" using the Graph API$/ - * @When /^user "([^"]*)" tries to create a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)" using the Graph API$/ - * - * @param string $user - * @param string $spaceName - * @param string $spaceType - * @param int $quota + * @param int|null $quota * * @return void * @@ -619,7 +588,7 @@ public function theUserCreatesASpaceWithQuotaUsingTheGraphApi( string $user, string $spaceName, string $spaceType, - int $quota + ?int $quota = null ): void { $space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]]; $body = json_encode($space); @@ -742,36 +711,6 @@ public function thePropfindResultShouldContainEntries( WebDavHelper::$SPACE_ID_FROM_OCIS = ''; } - /** - * @Then /^the space "([^"]*)" should (not|)\s?contain these (?:files|entries):$/ - * - * @param string $spaceName - * @param string $shouldOrNot (not|) - * @param TableNode $expectedFiles - * - * @return void - * - * @throws Exception|GuzzleException - */ - public function theSpaceShouldContainEntries( - string $spaceName, - string $shouldOrNot, - TableNode $expectedFiles - ): void { - $spaceCreator = $this->getSpaceCreator($spaceName); - $space = $this->getSpaceByName($spaceCreator, $spaceName); - $this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi( - $spaceCreator, - $spaceName - ); - WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id']; - $this->featureContext->propfindResultShouldContainEntries( - $shouldOrNot, - $expectedFiles, - ); - WebDavHelper::$SPACE_ID_FROM_OCIS = ''; - } - /** * @Then /^for user "([^"]*)" the space "([^"]*)" should (not|)\s?contain these (?:files|entries):$/ * @@ -1276,24 +1215,21 @@ public function theUserUploadsAFileToAnotherOwnerSpace( } /** - * @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)"$/ - * @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/ - * * @param string $user * @param string $spaceName - * @param string $newName + * @param array $bodyData * @param string $owner * - * @return void + * @return ResponseInterface * @throws GuzzleException - * @throws Exception + * @throws JsonException */ - public function updateSpaceName( + public function updateSpace( string $user, string $spaceName, - string $newName, + array $bodyData, string $owner = '' - ): void { + ): ResponseInterface { if ($spaceName === "non-existing") { // check sending invalid data $spaceId = "39c49dd3-1f24-4687-97d1-42df43f71713"; @@ -1302,20 +1238,40 @@ public function updateSpaceName( $spaceId = $space["id"]; } - $bodyData = ["Name" => $newName]; $body = json_encode($bodyData, JSON_THROW_ON_ERROR); - $this->featureContext->setResponse( - GraphHelper::updateSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $body, - $spaceId - ) + return GraphHelper::updateSpace( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $body, + $spaceId ); } + /** + * @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)"$/ + * @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param string $newName + * @param string $owner + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function updateSpaceName( + string $user, + string $spaceName, + string $newName, + string $owner = '' + ): void { + $bodyData = ["Name" => $newName]; + $this->featureContext->setResponse($this->updateSpace($user, $spaceName, $bodyData, $owner)); + } + /** * @When /^user "([^"]*)" (?:changes|tries to change) the description of the "([^"]*)" space to "([^"]*)"$/ * @When /^user "([^"]*)" (?:changes|tries to change) the description of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/ @@ -1335,26 +1291,8 @@ public function updateSpaceDescription( string $newDescription, string $owner = '' ): void { - if ($spaceName === "non-existing") { - // check sending invalid data - $spaceId = "39c49dd3-1f24-4687-97d1-42df43f71713"; - } else { - $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); - $spaceId = $space["id"]; - } - $bodyData = ["description" => $newDescription]; - $body = json_encode($bodyData, JSON_THROW_ON_ERROR); - - $this->featureContext->setResponse( - GraphHelper::updateSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $body, - $spaceId - ) - ); + $this->featureContext->setResponse($this->updateSpace($user, $spaceName, $bodyData, $owner)); } /** @@ -1399,26 +1337,8 @@ public function updateSpaceQuota( int $newQuota, string $owner = '' ): void { - if ($spaceName === "non-existing") { - // check sending invalid data - $spaceId = "39c49dd3-1f24-4687-97d1-42df43f71713"; - } else { - $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); - $spaceId = $space["id"]; - } - $bodyData = ["quota" => ["total" => $newQuota]]; - $body = json_encode($bodyData, JSON_THROW_ON_ERROR); - - $this->featureContext->setResponse( - GraphHelper::updateSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $body, - $spaceId - ) - ); + $this->featureContext->setResponse($this->updateSpace($user, $spaceName, $bodyData, $owner)); } /** @@ -1517,8 +1437,8 @@ public function userHasUpdatedSpaceSpecialSection( * * @param string $user * @param string $spaceName - * @param string $spaceType - * @param int $quota + * @param string|null $spaceType + * @param int|null $quota * * @return void * @throws GuzzleException @@ -1530,15 +1450,8 @@ public function userHasCreatedSpace( int $quota ): void { $space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]]; - $body = json_encode($space); - $this->featureContext->setResponse( - GraphHelper::createSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $body - ) - ); + $this->featureContext->setResponse($this->createSpace($user, $space)); + $this->setSpaceCreator($spaceName, $user); $this->featureContext->theHTTPStatusCodeShouldBe( 201, "Expected response status code should be 201 (Created)" @@ -1561,15 +1474,7 @@ public function theUserHasCreatedASpaceByDefaultUsingTheGraphApi( string $spaceName ): void { $space = ["Name" => $spaceName]; - $body = json_encode($space, JSON_THROW_ON_ERROR); - $this->featureContext->setResponse( - GraphHelper::createSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $body - ) - ); + $this->featureContext->setResponse($this->createSpace($user, $space)); $this->setSpaceCreator($spaceName, $user); $this->featureContext->theHTTPStatusCodeShouldBe( 201, @@ -1577,6 +1482,27 @@ public function theUserHasCreatedASpaceByDefaultUsingTheGraphApi( ); } + /** + * @param string $user + * @param string $space + * + * @return ResponseInterface + * @throws GuzzleException + * @throws JsonException + */ + public function createSpace( + string $user, + array $space + ): ResponseInterface { + $body = json_encode($space, JSON_THROW_ON_ERROR); + return GraphHelper::createSpace( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $body + ); + } + /** * @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/ * @@ -2707,42 +2633,15 @@ public function getStoredEtagForPathInSpaceOfAUser(string $user, string $space, } /** - * @Then /^these etags should have changed$/ - * - * @param TableNode $table - * - * @return void - * @throws GuzzleException - */ - public function theseEtagsShouldHaveChanged(TableNode $table): void { - $this->featureContext->verifyTableNodeColumns($table, ["user", "path", "space"]); - $this->featureContext->verifyTableNodeColumnsCount($table, 3); - $unchangedEtagCount = 0; - $unchangedEtagMessage = __METHOD__; - foreach ($table->getColumnsHash() as $row) { - $user = $row['user']; - $path = $row['path']; - $space = $row['space']; - $etag = $this->userGetsEtagOfElementInASpace($user, $space, $path); - $storedEtag = $this->getStoredEtagForPathInSpaceOfAUser($user, $space, $path); - if ($etag === $storedEtag) { - $unchangedEtagCount++; - $unchangedEtagMessage .= "\nExpected etag of element '$path' for user '$user' in space '$space' to change, but it did not."; - } - } - - Assert::assertEquals(0, $unchangedEtagCount, $unchangedEtagMessage); - } - - /** - * @Then /^these etags should not have changed$/ + * @Then /^these etags (should|should not) have changed$/ * + * @param string $action * @param TableNode $table * * @return void * @throws GuzzleException */ - public function theseEtagsShouldNotHaveChanged(TableNode $table): void { + public function theseEtagsShouldShouldNotHaveChanged(string $action, TableNode $table): void { $this->featureContext->verifyTableNodeColumns($table, ["user", "path", "space"]); $this->featureContext->verifyTableNodeColumnsCount($table, 3); $changedEtagCount = 0; @@ -2751,11 +2650,15 @@ public function theseEtagsShouldNotHaveChanged(TableNode $table): void { $user = $row['user']; $path = $row['path']; $space = $row['space']; - $actualEtag = $this->userGetsEtagOfElementInASpace($user, $space, $path); + $etag = $this->userGetsEtagOfElementInASpace($user, $space, $path); $storedEtag = $this->getStoredEtagForPathInSpaceOfAUser($user, $space, $path); - if ($actualEtag !== $storedEtag) { + if ($action === 'should' && $etag === $storedEtag) { + $changedEtagCount++; + $changedEtagMessage .= "\nExpected etag of element '$path' for user '$user' in space '$space' to change, but it did not."; + } + if ($action === 'should not' && $etag !== $storedEtag) { $changedEtagCount++; - $changedEtagMessage .= "\nExpected etag of element '$path' for user '$user' in space '$space' not to change, but it did."; + $changedEtagMessage .= "\nExpected etag of element '$path' for user '$user' in space '$space' to change, but it did not."; } } diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 2bf82133033..528703438a5 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -1184,7 +1184,13 @@ public function contentOfFileShouldBePlusEndOfLine(string $fileName, string $con public function contentOfFileForUserShouldBe(string $fileName, string $user, string $content):void { $user = $this->getActualUsername($user); $this->downloadFileAsUserUsingPassword($user, $fileName); - $this->downloadedContentShouldBe($content); + $actualStatus = $this->response->getStatusCode(); + if ($actualStatus !== 200) { + throw new Exception( + "Expected status code to be '200', but got '$actualStatus'" + ); + } + $this->checkDownloadedContentMatches($content); } /** @@ -3706,38 +3712,6 @@ public function userUploadsTheFollowingTotalChunksUsingOldChunking( } } - /** - * Old style chunking upload - * - * @Given user :user has uploaded the following :total chunks to :file with old chunking - * - * @param string $user - * @param string $total - * @param string $file - * @param TableNode $chunkDetails table of 2 columns, chunk number and chunk - * content with following headings, e.g. - * | number | content | - * | 1 | first data | - * | 2 | followed by second data | - * Chunks may be numbered out-of-order if desired. - * - * @return void - * @throws Exception - */ - public function userHasUploadedTheFollowingTotalChunksUsingOldChunking( - string $user, - string $total, - string $file, - TableNode $chunkDetails - ):void { - $this->verifyTableNodeColumns($chunkDetails, ['number', 'content']); - foreach ($chunkDetails->getHash() as $chunkDetail) { - $chunkNumber = (int) $chunkDetail['number']; - $chunkContent = $chunkDetail['content']; - $this->userHasUploadedChunkedFile($user, $chunkNumber, (int) $total, $chunkContent, $file); - } - } - /** * Old style chunking upload * @@ -3769,37 +3743,6 @@ public function userUploadsTheFollowingChunksUsingOldChunking( ); } - /** - * Old style chunking upload - * - * @Given user :user has uploaded the following chunks to :file with old chunking - * - * @param string $user - * @param string $file - * @param TableNode $chunkDetails table of 2 columns, chunk number and chunk - * content with headings, e.g. - * | number | content | - * | 1 | first data | - * | 2 | followed by second data | - * Chunks may be numbered out-of-order if desired. - * - * @return void - * @throws Exception - */ - public function userHasUploadedTheFollowingChunksUsingOldChunking( - string $user, - string $file, - TableNode $chunkDetails - ):void { - $total = \count($chunkDetails->getRows()); - $this->userHasUploadedTheFollowingTotalChunksUsingOldChunking( - $user, - (string) $total, - $file, - $chunkDetails - ); - } - /** * Old style chunking upload * diff --git a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php index 9665615609d..beef5ebe5de 100644 --- a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php +++ b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php @@ -673,12 +673,7 @@ public function assertValueOfItemInResponseAboutUserIs(string $xpath, ?string $u __METHOD__ ); } - $xmlPart = $resXml->xpath($xpath); - Assert::assertTrue( - isset($xmlPart[0]), - "Cannot find item with xpath \"$xpath\"" - ); - $value = $xmlPart[0]->__toString(); + $value = $this->getXmlItemByXpath($resXml, $xpath); $user = $this->featureContext->getActualUsername($user); $expectedValue = $this->featureContext->substituteInLineCodes( $expectedValue, @@ -718,12 +713,7 @@ public function assertValueOfItemInResponseAboutUserIsEitherOr(string $xpath, ?s __METHOD__ ); } - $xmlPart = $resXml->xpath($xpath); - Assert::assertTrue( - isset($xmlPart[0]), - "Cannot find item with xpath \"$xpath\"" - ); - $value = $xmlPart[0]->__toString(); + $value = $this->getXmlItemByXpath($resXml, $xpath); $user = $this->featureContext->getActualUsername($user); $expectedValue1 = $this->featureContext->substituteInLineCodes( $expectedValue1, @@ -744,6 +734,25 @@ public function assertValueOfItemInResponseAboutUserIsEitherOr(string $xpath, ?s Assert::assertTrue($isExpectedValueInMessage, "The actual value \"$value\" is not one of the expected values: \"$expectedValue1\" or \"$expectedValue2\""); } + /** + * @param $xmlResponse + * @param string $xpath + * + * @return string + * @throws Exception + */ + public function getXmlItemByXpath( + SimpleXMLElement $xmlResponse, + string $xpath + ): string { + $xmlPart = $xmlResponse->xpath($xpath); + Assert::assertTrue( + isset($xmlPart[0]), + "Cannot find item with xpath \"$xpath\"" + ); + return $xmlPart[0]->__toString(); + } + /** * @Then the value of the item :xpath in the response should match :value * @@ -1284,28 +1293,6 @@ public function theseEtagsShouldNotHaveChanged(TableNode $etagTable):void { Assert::assertEquals(0, $changedEtagCount, $changedEtagMessage); } - /** - * @Then the etag of element :path of user :user should not have changed - * - * @param string $path - * @param string $user - * - * @return void - * @throws Exception - */ - public function etagOfElementOfUserShouldNotHaveChanged(string $path, string $user):void { - $user = $this->featureContext->getActualUsername($user); - $actualEtag = $this->getCurrentEtagOfElement($path, $user); - $storedEtag = $this->getStoredEtagOfElement($path, $user, __METHOD__); - Assert::assertEquals( - $storedEtag, - $actualEtag, - __METHOD__ - . " The etag of element '$path' of user '$user' was not expected to change." - . " The stored etag was '$storedEtag' but got '$actualEtag' from the response" - ); - } - /** * @Then these etags should have changed: * @@ -1335,65 +1322,36 @@ public function theseEtagsShouldHaveChanged(TableNode $etagTable):void { } /** - * @Then the etag of element :path of user :user should have changed + * @Then /^the etag of element "([^"]*)" of user "([^"]*)" (should|should not) have changed$/ * * @param string $path * @param string $user + * @param string $shouldShouldNot * * @return void * @throws Exception */ - public function etagOfElementOfUserShouldHaveChanged(string $path, string $user):void { + public function etagOfElementOfUserShouldOrShouldNotHaveChanged(string $path, string $user, string $shouldShouldNot):void { $user = $this->featureContext->getActualUsername($user); $actualEtag = $this->getCurrentEtagOfElement($path, $user); $storedEtag = $this->getStoredEtagOfElement($path, $user, __METHOD__); - Assert::assertNotEquals( - $storedEtag, - $actualEtag, - __METHOD__ - . " The etag of element '$path' of user '$user' was expected to change." - . " The stored etag was '$storedEtag' and also got '$actualEtag' from the response" - ); - } - - /** - * @Then the etag of element :path of user :user on server :server should have changed - * - * @param string $path - * @param string $user - * @param string $server - * - * @return void - * @throws Exception - */ - public function theEtagOfElementOfUserOnServerShouldHaveChanged( - string $path, - string $user, - string $server - ):void { - $previousServer = $this->featureContext->usingServer($server); - $this->etagOfElementOfUserShouldHaveChanged($path, $user); - $this->featureContext->usingServer($previousServer); - } - - /** - * @Then the etag of element :path of user :user on server :server should not have changed - * - * @param string $path - * @param string $user - * @param string $server - * - * @return void - * @throws Exception - */ - public function theEtagOfElementOfUserOnServerShouldNotHaveChanged( - string $path, - string $user, - string $server - ):void { - $previousServer = $this->featureContext->usingServer($server); - $this->etagOfElementOfUserShouldNotHaveChanged($path, $user); - $this->featureContext->usingServer($previousServer); + if ($shouldShouldNot === 'should not') { + Assert::assertEquals( + $storedEtag, + $actualEtag, + __METHOD__ + . " The etag of element '$path' of user '$user' was not expected to change." + . " The stored etag was '$storedEtag' but got '$actualEtag' from the response" + ); + } else { + Assert::assertNotEquals( + $storedEtag, + $actualEtag, + __METHOD__ + . " The etag of element '$path' of user '$user' was expected to change." + . " The stored etag was '$storedEtag' and also got '$actualEtag' from the response" + ); + } } /**