diff --git a/tests/TestHelpers/HttpRequestHelper.php b/tests/TestHelpers/HttpRequestHelper.php index aab62600da5..f9b7d39f902 100644 --- a/tests/TestHelpers/HttpRequestHelper.php +++ b/tests/TestHelpers/HttpRequestHelper.php @@ -657,6 +657,8 @@ public static function getResponseXml(ResponseInterface $response, ?string $exce * @return array */ public static function parseResponseAsXml(ResponseInterface $response):array { + // rewind so that we can reparse it if it was parsed already + $response->getBody()->rewind(); $body = $response->getBody()->getContents(); $parsedResponse = []; if ($body && \substr($body, 0, 1) === '<') { diff --git a/tests/acceptance/features/apiNotification/emailNotification.feature b/tests/acceptance/features/apiNotification/emailNotification.feature index 69a83d2f196..139f4530a0d 100644 --- a/tests/acceptance/features/apiNotification/emailNotification.feature +++ b/tests/acceptance/features/apiNotification/emailNotification.feature @@ -30,8 +30,9 @@ Feature: Email notification Scenario: user gets an email notification when someone shares a file Given user "Alice" has uploaded file with content "sample text" to "lorem.txt" - When user "Alice" has shared file "lorem.txt" with user "Brian" with permissions "17" + When user "Alice" shares file "lorem.txt" with user "Brian" with permissions "17" using the sharing API Then the HTTP status code should be "200" + And the OCS status code should be "100" And user "Brian" should have received the following email from user "Alice" """ Hello Brian Murphy @@ -80,8 +81,9 @@ Feature: Email notification And user "Brian" has switched the system language to "es" And user "Carol" has switched the system language to "de" And user "Alice" has created folder "/HelloWorld" - When user "Alice" has shared folder "/HelloWorld" with group "group1" + When user "Alice" shares folder "HelloWorld" with group "group1" using the sharing API Then the HTTP status code should be "200" + And the OCS status code should be "100" And user "Brian" should have received the following email from user "Alice" """ Hola Brian Murphy @@ -108,8 +110,9 @@ Feature: Email notification And user "Brian" has switched the system language to "es" And user "Carol" has switched the system language to "de" And user "Alice" has uploaded file with content "hello world" to "text.txt" - When user "Alice" has shared file "text.txt" with group "group1" + When user "Alice" shares file "text.txt" with group "group1" using the sharing API Then the HTTP status code should be "200" + And the OCS status code should be "100" And user "Brian" should have received the following email from user "Alice" """ Hola Brian Murphy diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 5122e423363..d25d7ec6a63 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -249,10 +249,10 @@ private function waitToCreateShare():void { * | | 6 = federated (cloud share). | * | | Pass either the number or the keyword. | * - * @return void + * @return ResponseInterface * @throws Exception */ - public function createShareWithSettings(string $user, ?TableNode $body):void { + public function createShareWithSettings(string $user, ?TableNode $body): ResponseInterface { $user = $this->getActualUsername($user); $this->verifyTableNodeRows( $body, @@ -290,7 +290,7 @@ public function createShareWithSettings(string $user, ?TableNode $body):void { $needToParse = \array_key_exists('expireDate', $bodyRows); $expireDate = $bodyRows['expireDate'] ?? $bodyRows['expireDateAsString'] ?? null; $bodyRows['expireDate'] = $needToParse ? \date('Y-m-d', \strtotime($expireDate)) : $expireDate; - $this->createShare( + return $this->createShare( $user, $bodyRows['path'], $bodyRows['shareType'], @@ -314,10 +314,11 @@ public function createShareWithSettings(string $user, ?TableNode $body):void { */ public function userCreatesAShareWithSettings(string $user, ?TableNode $body):void { $user = $this->getActualUsername($user); - $this->createShareWithSettings( + $response = $this->createShareWithSettings( $user, $body ); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -331,26 +332,12 @@ public function userCreatesAShareWithSettings(string $user, ?TableNode $body):vo * @throws Exception */ public function userHasCreatedAShareWithSettings(string $user, ?TableNode $body) { - $this->createShareWithSettings( + $response = $this->createShareWithSettings( $user, $body ); - $this->theHTTPStatusCodeShouldBe( - 200, - "Failed HTTP status code for last share for user $user" . ", Reason: " . $this->getResponse()->getReasonPhrase() - ); - } - - /** - * @When /^the user creates a share using the sharing API with settings$/ - * - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function theUserCreatesAShareWithSettings(?TableNode $body):void { - $this->createShareWithSettings($this->currentUser, $body); + $this->theHTTPStatusCodeShouldBe(200, "", $response); + $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); } /** @@ -367,7 +354,8 @@ public function userCreatesAPublicLinkShareWithSettings(string $user, ?TableNode // A public link share is shareType 3 $rows[] = ['shareType', 'public_link']; $newBody = new TableNode($rows); - $this->createShareWithSettings($user, $newBody); + $response = $this->createShareWithSettings($user, $newBody); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -399,20 +387,6 @@ public function theUserCreatesAPublicLinkShareWithSettings(?TableNode $body):voi $this->userCreatesAPublicLinkShareWithSettings($this->currentUser, $body); } - /** - * @Given /^the user has created a share with settings$/ - * - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function theUserHasCreatedAShareWithSettings(?TableNode $body):void { - $this->createShareWithSettings($this->currentUser, $body); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200"); - $this->theHTTPStatusCodeShouldBe(200); - } - /** * @Given /^the user has created a public link share with settings$/ * @@ -436,7 +410,7 @@ public function theUserHasCreatedAPublicLinkShareWithSettings(?TableNode $body): * @param string|null $linkName * @param string|null $expireDate * - * @return void + * @return ResponseInterface */ public function createAPublicShare( string $user, @@ -446,9 +420,8 @@ public function createAPublicShare( $permissions = null, ?string $linkName = null, ?string $expireDate = null - ):void { - $user = $this->getActualUsername($user); - $this->createShare( + ): ResponseInterface { + return $this->createShare( $user, $path, 'public_link', @@ -470,7 +443,8 @@ public function createAPublicShare( * @return void */ public function userCreatesAPublicLinkShareOf(string $user, string $path):void { - $this->createAPublicShare($user, $path); + $response = $this->createAPublicShare($user, $path); + $this->setResponse($response); } /** @@ -482,55 +456,9 @@ public function userCreatesAPublicLinkShareOf(string $user, string $path):void { * @return void */ public function userHasCreatedAPublicLinkShareOf(string $user, string $path):void { - $this->createAPublicShare($user, $path); - $this->theHTTPStatusCodeShouldBeSuccess(); - } - - /** - * @param string $path - * - * @return void - */ - public function createPublicLinkShareOfResourceAsCurrentUser(string $path):void { - $this->createAPublicShare($this->currentUser, $path); - } - - /** - * @When /^the user creates a public link share of (?:file|folder) "([^"]*)" using the sharing API$/ - * - * @param string $path - * - * @return void - */ - public function aPublicLinkShareOfIsCreated(string $path):void { - $this->createPublicLinkShareOfResourceAsCurrentUser($path); - } - - /** - * @Given /^the user has created a public link share of (?:file|folder) "([^"]*)"$/ - * - * @param string $path - * - * @return void - */ - public function aPublicLinkShareOfHasCreated(string $path):void { - $this->createPublicLinkShareOfResourceAsCurrentUser($path); - $this->theHTTPStatusCodeShouldBeSuccess(); - } - - /** - * @param string $user - * @param string $path - * @param string|int|string[]|int[]|null $permissions - * - * @return void - */ - public function createPublicLinkShareOfResourceWithPermission( - string $user, - string $path, - $permissions - ):void { - $this->createAPublicShare($user, $path, true, null, $permissions); + $response = $this->createAPublicShare($user, $path); + $this->theHTTPStatusCodeShouldBe(200, "", $response); + $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); } /** @@ -547,11 +475,8 @@ public function userCreatesAPublicLinkShareOfWithPermission( string $path, $permissions ):void { - $this->createPublicLinkShareOfResourceWithPermission( - $user, - $path, - $permissions - ); + $response = $this->createAPublicShare($user, $path, true, null, $permissions); + $this->setResponse($response); } /** @@ -568,53 +493,9 @@ public function userHasCreatedAPublicLinkShareOfWithPermission( string $path, $permissions ):void { - $this->createPublicLinkShareOfResourceWithPermission( - $user, - $path, - $permissions - ); - $this->theHTTPStatusCodeShouldBeSuccess(); - } - - /** - * @param string $path - * @param string|int|string[]|int[]|null $permissions - * - * @return void - */ - public function createPublicLinkShareWithPermissionByCurrentUser(string $path, $permissions):void { - $this->createAPublicShare( - $this->currentUser, - $path, - true, - null, - $permissions - ); - } - - /** - * @When /^the user creates a public link share of (?:file|folder) "([^"]*)" using the sharing API with (read|update|create|delete|change|uploadwriteonly|share|all) permission(?:s|)$/ - * - * @param string $path - * @param string|int|string[]|int[]|null $permissions - * - * @return void - */ - public function aPublicLinkShareOfIsCreatedWithPermission(string $path, $permissions):void { - $this->createPublicLinkShareWithPermissionByCurrentUser($path, $permissions); - } - - /** - * @Given /^the user has created a public link share of (?:file|folder) "([^"]*)" with (read|update|create|delete|change|uploadwriteonly|share|all) permission(?:s|)$/ - * - * @param string $path - * @param string|int|string[]|int[]|null $permissions - * - * @return void - */ - public function aPublicLinkShareOfHasCreatedWithPermission(string $path, $permissions):void { - $this->createPublicLinkShareWithPermissionByCurrentUser($path, $permissions); - $this->theHTTPStatusCodeShouldBeSuccess(); + $response = $this->createAPublicShare($user, $path, true, null, $permissions); + $this->theHTTPStatusCodeShouldBe(200, "", $response); + $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); } /** @@ -704,43 +585,6 @@ public function createPublicLinkShareOfResourceWithExpiryByCurrentUser( ); } - /** - * @When /^the user creates a public link share of (?:file|folder) "([^"]*)" using the sharing API with expiry "([^"]*)$"/ - * - * @param string $path - * @param string $expiryDate in a valid date format, e.g. "+30 days" - * - * @return void - */ - public function aPublicLinkShareOfIsCreatedWithExpiry( - string $path, - string $expiryDate - ):void { - $this->createPublicLinkShareOfResourceWithExpiryByCurrentUser( - $path, - $expiryDate - ); - } - - /** - * @Given /^the user has created a public link share of (?:file|folder) "([^"]*)" with expiry "([^"]*)$/ - * - * @param string $path - * @param string $expiryDate in a valid date format, e.g. "+30 days" - * - * @return void - */ - public function aPublicLinkShareOfHasCreatedWithExpiry( - string $path, - string $expiryDate - ):void { - $this->createPublicLinkShareOfResourceWithExpiryByCurrentUser( - $path, - $expiryDate - ); - $this->theHTTPStatusCodeShouldBeSuccess(); - } - /** * @Then /^user "([^"]*)" should not be able to create a public link share of (file|folder) "([^"]*)" using the sharing API$/ * @@ -752,11 +596,6 @@ public function aPublicLinkShareOfHasCreatedWithExpiry( * @throws Exception */ public function shouldNotBeAbleToCreatePublicLinkShare(string $sharer, string $entry, string $filepath):void { - $this->asFileOrFolderShouldExist( - $this->getActualUsername($sharer), - $entry, - $filepath - ); $this->createAPublicShare($sharer, $filepath); Assert::assertEquals( 404, @@ -969,7 +808,7 @@ public function userHasUpdatedTheLastShareOfWith(string $user, string $shareOwne * @param string|null $expireDate * @param string $sharingApp * - * @return void + * @return ResponseInterface * @throws JsonException * @throws Exception */ @@ -984,13 +823,13 @@ public function createShare( ?string $linkName = null, ?string $expireDate = null, string $sharingApp = 'files_sharing' - ):void { + ): ResponseInterface { $userActual = $this->getActualUsername($user); if (\is_string($permissions) && !\is_numeric($permissions)) { $permissions = $this->splitPermissionsString($permissions); } $this->waitToCreateShare(); - $this->response = SharingHelper::createShare( + $response = SharingHelper::createShare( $this->getBaseUrl(), $userActual, $this->getPasswordForUser($user), @@ -1007,33 +846,24 @@ public function createShare( $this->sharingApiVersion, $sharingApp ); - $httpStatusCode = $this->response->getStatusCode(); - // In case of HTTP status code 204 "no content", or a failure code like 4xx - // in the HTTP or OCS status there is no useful content in response payload body. - // Clear the test-runner's memory of "last share data" to avoid later steps - // accidentally using some previous share data. - if (($httpStatusCode === 204) - || !$this->theHTTPStatusCodeWasSuccess() - || (($httpStatusCode === 200) && ($this->ocsContext->getOCSResponseStatusCode($this->response) > 299)) + + // save the created share data + if (($response->getStatusCode() === 200) + && \in_array($this->ocsContext->getOCSResponseStatusCode($response), ['100', '200']) ) { - if ($shareType === 'public_link') { - $this->emptyCreatedPublicShares(); - } else { - $this->emptyCreatedUserGroupShares(); - } - } else { - $response = $this->getResponseXml(null, __METHOD__); - if (isset($response->data)) { - $shareData = $response->data; + $xmlResponse = $this->getResponseXml($response); + if (isset($xmlResponse->data)) { + $shareData = $xmlResponse->data; if ($shareType === 'public_link') { $this->addToCreatedPublicShares($shareData); } else { - $sharer = (string) $response->data->uid_owner; + $sharer = (string) $xmlResponse->data->uid_owner; $this->addToCreatedUserGroupshares($sharer, $shareData); } } } $this->localLastShareTime = \microtime(true); + return $response; } /** @@ -1310,89 +1140,54 @@ public function isUserOrGroupInSharedData(string $userOrGroupId, $shareType, $pe /** * - * @param string $user1 + * @param string $sharer * @param string $filepath - * @param string $user2 + * @param string $sharee * @param string|int|string[]|int[] $permissions - * @param bool|null $getShareData If true then only create the share if it is not - * already existing, and at the end request the - * share information and leave that in $this->response - * Typically used in a "Given" step which verifies - * that the share did get created successfully. * - * @return void + * @return ResponseInterface */ - public function shareFileWithUserUsingTheSharingApi( - string $user1, + public function createAUserShare( + string $sharer, string $filepath, - string $user2, - $permissions = null, - ?bool $getShareData = false - ):void { - $user1Actual = $this->getActualUsername($user1); - $user2Actual = $this->getActualUsername($user2); - - $path = $this->getSharesEndpointPath("?path=" . \urlencode($filepath)); - $this->response = OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $user1Actual, - $this->getPasswordForUser($user1), - "GET", - $path, - $this->getStepLineRef(), - [], - $this->ocsApiVersion + string $sharee, + $permissions = null + ): ResponseInterface { + return $this->createShare( + $sharer, + $filepath, + '0', + $this->getActualUsername($sharee), + null, + null, + $permissions ); - if ($getShareData && $this->isUserOrGroupInSharedData($user2Actual, "user", $permissions)) { - return; - } else { - $this->createShare( - $user1, - $filepath, - '0', - $user2Actual, - null, - null, - $permissions - ); - } - if ($getShareData) { - $this->response = OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $user1Actual, - $this->getPasswordForUser($user1), - "GET", - $path, - $this->getStepLineRef(), - [], - $this->ocsApiVersion - ); - } } /** * @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))? using the sharing API$/ * @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)" using the sharing API$/ * - * @param string $user1 + * @param string $sharer * @param string $filepath - * @param string $user2 + * @param string $sharee * @param string|int|string[]|int[] $permissions * * @return void */ public function userSharesFileWithUserUsingTheSharingApi( - string $user1, + string $sharer, string $filepath, - string $user2, + string $sharee, $permissions = null ):void { - $this->shareFileWithUserUsingTheSharingApi( - $user1, + $response = $this->createAUserShare( + $sharer, $filepath, - $user2, + $this->getActualUsername($sharee), $permissions ); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -1431,37 +1226,28 @@ public function userSharesTheFollowingFilesWithUserUsingTheSharingApi( * @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))?$/ * @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)"$/ * - * @param string $user1 + * @param string $sharer * @param string $filepath - * @param string $user2 + * @param string $sharee * @param string|int|string[]|int[] $permissions * * @return void * @throws Exception */ public function userHasSharedFileWithUserUsingTheSharingApi( - string $user1, + string $sharer, string $filepath, - string $user2, + string $sharee, $permissions = null ):void { - $user1 = $this->getActualUsername($user1); - $user2 = $this->getActualUsername($user2); - $this->shareFileWithUserUsingTheSharingApi( - $user1, + $response = $this->createAUserShare( + $sharer, $filepath, - $user2, - $permissions, - true - ); - $this->ocsContext->assertOCSResponseIndicatesSuccess( - 'The ocs share response does not indicate success.', - ); - // this is expected to fail if a file is shared with create and delete permissions, which is not possible - Assert::assertTrue( - $this->isUserOrGroupInSharedData($user2, "user", $permissions), - __METHOD__ . " User $user1 failed to share $filepath with user $user2" + $this->getActualUsername($sharee), + $permissions ); + $this->theHTTPStatusCodeShouldBe(200, "", $response); + $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); } /** @@ -1588,58 +1374,24 @@ public function theUserHasSharedFileWithGroupUsingTheSharingApi( * @param string $filepath * @param string $group * @param string|int|string[]|int[] $permissions - * @param bool $getShareData If true then only create the share if it is not - * already existing, and at the end request the - * share information and leave that in $this->response - * Typically used in a "Given" step which verifies - * that the share did get created successfully. * - * @return void + * @return ResponseInterface */ - public function shareFileWithGroupUsingTheSharingApi( + public function createAGroupShare( string $user, string $filepath, string$group, - $permissions = null, - bool $getShareData = false - ):void { - $userActual = $this->getActualUsername($user); - $path = $this->getSharesEndpointPath("?path=$filepath"); - $this->response = OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $userActual, - $this->getPasswordForUser($user), - "GET", - $path, - $this->getStepLineRef(), - [], - $this->ocsApiVersion + $permissions = null + ): ResponseInterface { + return $this->createShare( + $user, + $filepath, + '1', + $group, + null, + null, + $permissions ); - if ($getShareData && $this->isUserOrGroupInSharedData($group, "group", $permissions)) { - return; - } else { - $this->createShare( - $user, - $filepath, - '1', - $group, - null, - null, - $permissions - ); - } - if ($getShareData) { - $this->response = OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $userActual, - $this->getPasswordForUser($user), - "GET", - $path, - $this->getStepLineRef(), - [], - $this->ocsApiVersion - ); - } } /** @@ -1659,12 +1411,13 @@ public function userSharesFileWithGroupUsingTheSharingApi( string $group, $permissions = null ) { - $this->shareFileWithGroupUsingTheSharingApi( + $response = $this->createAGroupShare( $user, $filepath, $group, $permissions ); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -1716,19 +1469,14 @@ public function userHasSharedFileWithGroupUsingTheSharingApi( string $group, $permissions = null ) { - $this->shareFileWithGroupUsingTheSharingApi( + $response = $this->createAGroupShare( $user, $filepath, $group, - $permissions, - true - ); - - Assert::assertTrue( - $this->isUserOrGroupInSharedData($group, "group", $permissions), - __METHOD__ - . " Could not assert that user '$user' has shared '$filepath' with group '$group' with permissions '$permissions'" + $permissions ); + $this->theHTTPStatusCodeShouldBe(200, "", $response); + $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); } /** @@ -1780,12 +1528,7 @@ public function userTriesToShareFileUsingTheSharingApi( $permissions = null ):void { $sharee = $this->getActualUsername($sharee); - $this->asFileOrFolderShouldExist( - $this->getActualUsername($sharer), - $entry, - $filepath - ); - $this->createShare( + $response = $this->createShare( $sharer, $filepath, $userOrGroupShareType, @@ -1794,7 +1537,7 @@ public function userTriesToShareFileUsingTheSharingApi( null, $permissions ); - $statusCode = $this->ocsContext->getOCSResponseStatusCode($this->response); + $statusCode = $this->ocsContext->getOCSResponseStatusCode($response); Assert::assertTrue( ($statusCode == 404) || ($statusCode == 403), "Sharing should have failed with status code 403 or 404 but got status code $statusCode" @@ -1824,8 +1567,7 @@ public function userShouldBeAbleToShareUsingTheSharingApi( $permissions = null ):void { $sharee = $this->getActualUsername($sharee); - $this->asFileOrFolderShouldExist($sharer, $entry, $filepath); - $this->createShare( + $response = $this->createShare( $sharer, $filepath, $userOrGroupShareType, @@ -1835,9 +1577,11 @@ public function userShouldBeAbleToShareUsingTheSharingApi( $permissions ); - //v1.php returns 100 as success code - //v2.php returns 200 in the same case - $this->ocsContext->theOCSStatusCodeShouldBe("100, 200"); + $statusCode = $this->ocsContext->getOCSResponseStatusCode($response); + Assert::assertTrue( + ($statusCode == 100) || ($statusCode == 200), + "Sharing should be successful but got ocs status code $statusCode" + ); } /** @@ -2995,7 +2739,6 @@ public function checkPublicShares(string $user, string $path, ?TableNode $TableN */ public function checkPublicSharesAreEmpty(string $user, string $entry, string $path):void { $user = $this->getActualUsername($user); - $this->asFileOrFolderShouldExist($user, $entry, $path); $response = $this->getShares($user, $path); //It shouldn't have public shares Assert::assertEquals( diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 32302b99f3e..9eca98f35b3 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -1156,7 +1156,8 @@ public function theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi( $ownerUser = $user; } $this->setSpaceIDByName($ownerUser, $spaceName); - $this->featureContext->userCreatesFolder($user, $folder); + $response = $this->featureContext->createFolder($user, $folder); + $this->featureContext->setResponse($response); } /** diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 42c3b9e9b53..e663cf62b40 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -446,6 +446,34 @@ public function makeDavRequest( ); } + /** + * + * @param string $user + * @param string $folder + * @param bool|null $isGivenStep + * + * @return ResponseInterface + * @throws JsonException | GuzzleException + * @throws GuzzleException | JsonException + */ + public function createFolder(string $user, string $folder, ?bool $isGivenStep = false): ResponseInterface { + $folder = '/' . \ltrim($folder, '/'); + return $this->makeDavRequest( + $user, + "MKCOL", + $folder, + [], + null, + "files", + null, + false, + null, + [], + null, + $isGivenStep + ); + } + /** * @param string $user * @param string|null $path @@ -3627,32 +3655,14 @@ public function userOnHasDeletedFile(string $user, string $server, string $fileO * * @param string $user * @param string $destination - * @param bool|null $isGivenStep * * @return void * @throws JsonException | GuzzleException * @throws GuzzleException | JsonException */ - public function userCreatesFolder(string $user, string $destination, ?bool $isGivenStep = false):void { - $user = $this->getActualUsername($user); - $destination = '/' . \ltrim($destination, '/'); - $this->response = $this->makeDavRequest( - $user, - "MKCOL", - $destination, - [], - null, - "files", - null, - false, - null, - [], - null, - $isGivenStep - ); - $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->response) - ); + public function userCreatesFolder(string $user, string $destination):void { + $response = $this->createFolder($user, $destination); + $this->setResponse($response); $this->pushToLastHttpStatusCodesArray(); } @@ -3667,13 +3677,12 @@ public function userCreatesFolder(string $user, string $destination, ?bool $isGi * @throws GuzzleException */ public function userHasCreatedFolder(string $user, string $destination):void { - $user = $this->getActualUsername($user); - $this->userCreatesFolder($user, $destination, true); + $response = $this->createFolder($user, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to create folder '$destination' for user '$user'" + "HTTP status code was not 201 or 204 while trying to create folder '$destination' for user '$user'", + $response ); - $this->emptyLastHTTPStatusCodesArray(); } /** @@ -3692,13 +3701,13 @@ public function adminHasCreatedFolder(string $destination):void { $admin, __METHOD__ . "The provided user is not admin but '" . $admin . "'" ); - $this->userCreatesFolder($admin, $destination, true); + $response = $this->createFolder($admin, $destination, true); $this->theHTTPStatusCodeShouldBe( ["201", "204"], - "HTTP status code was not 201 or 204 while trying to create folder '$destination' for admin '$admin'" + "HTTP status code was not 201 or 204 while trying to create folder '$destination' for admin '$admin'", + $response ); $this->adminResources[] = $destination; - $this->emptyLastHTTPStatusCodesArray(); } /** @@ -3719,32 +3728,6 @@ public function userHasCreatedFollowingFolders(string $user, TableNode $table):v } } - /** - * @When the user creates folder :destination using the WebDAV API - * - * @param string $destination - * - * @return void - */ - public function theUserCreatesFolder(string $destination):void { - $this->userCreatesFolder($this->getCurrentUser(), $destination); - } - - /** - * @Given the user has created folder :destination - * - * @param string $destination - * - * @return void - */ - public function theUserHasCreatedFolder(string $destination):void { - $this->theUserCreatesFolder($destination); - $this->theHTTPStatusCodeShouldBe( - ["201", "204"], - "HTTP status code was not 201 or 204 while trying to create folder '$destination'" - ); - } - /** * @Then user :user should be able to create folder :destination * @@ -3774,12 +3757,11 @@ public function userShouldBeAbleToCreateFolder(string $user, string $destination */ public function userShouldNotBeAbleToCreateFolder(string $user, string $destination):void { $user = $this->getActualUsername($user); - $this->userCreatesFolder($user, $destination); - $this->theHTTPStatusCodeShouldBeFailure(); - $this->asFileOrFolderShouldNotExist( - $user, - "folder", - $destination + $response = $this->createFolder($user, $destination); + Assert::assertNotEquals( + 201, + $response->getStatusCode(), + "User '$user' should not be able to create folder '$destination' but was successful" ); } @@ -4842,10 +4824,11 @@ public function userFileShouldHaveStoredId(string $user, string $fileOrFolder, s * @throws Exception */ public function theDavElementShouldBe(string $element, string $message):void { + $resXmlArray = HttpRequestHelper::parseResponseAsXml($this->getResponse()); WebDavAssert::assertDavResponseElementIs( $element, $message, - $this->responseXml, + $resXmlArray, __METHOD__ ); }