From 0387e15d347d49853ce52cd1a9b39e69f5f98ff4 Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Wed, 14 Sep 2022 13:38:15 +0545 Subject: [PATCH] Reuse the core code --- .drone.env | 2 +- ...ected-failures-localAPI-on-OCIS-storage.md | 4 +- .../features/apiSpaces/changeSpaces.feature | 1 + .../features/apiSpaces/copySpaces.feature | 13 +- ...eateFileFolderWhenSharesSpaceExist.feature | 22 +- .../features/apiSpaces/download.feature | 1 + .../apiSpaces/editPublicLinkOfSpace.feature | 1 + .../features/apiSpaces/filePreviews.feature | 1 + .../features/apiSpaces/listSpaces.feature | 1 + .../features/apiSpaces/moveSpaces.feature | 1 + .../features/apiSpaces/quota.feature | 1 + .../apiSpaces/removeSpaceObjects.feature | 1 + .../apiSpaces/restoreSpaceObjects.feature | 1 + .../features/apiSpaces/restoreSpaces.feature | 1 + .../features/apiSpaces/search.feature | 10 +- .../features/apiSpaces/shareSpaces.feature | 1 + .../apiSpaces/shareSpacesViaLink.feature | 1 + .../apiSpaces/shareSubItemOfSpace.feature | 6 +- .../shareSubItemOfSpaceViaPublicLink.feature | 1 + .../features/apiSpaces/uploadSpaces.feature | 1 + .../features/bootstrap/SpacesContext.php | 385 +++--------------- 21 files changed, 92 insertions(+), 364 deletions(-) diff --git a/.drone.env b/.drone.env index 35be59894..8c9cf337a 100644 --- a/.drone.env +++ b/.drone.env @@ -1,5 +1,5 @@ # The test runner source for API tests -CORE_COMMITID=67fad9d49fa7f3f42f77e882ee4cbb206464ca5d +CORE_COMMITID=82a05d010110c0b4b2513c22185eac28b5dce054 CORE_BRANCH=master # The test runner source for UI tests diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 5330a6acb..58bdd3ad6 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -32,8 +32,8 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiSpaces/changingFilesShare.feature:12](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changingFilesShare.feature#L12) ### [copy to overwrite (file and folder) from Personal to Shares Jail behaves differently](https://github.com/owncloud/ocis/issues/4393) -- [apiSpaces/copySpaces.feature:487](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/copySpaces.feature#L487) -- [apiSpaces/copySpaces.feature:501](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/copySpaces.feature#L501) +- [apiSpaces/copySpaces.feature:488](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/copySpaces.feature#L488) +- [apiSpaces/copySpaces.feature:502](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/copySpaces.feature#L502) ### [search doesn't find the project space by name](https://github.com/owncloud/ocis/issues/4506) - [apiSpaces/search.feature:95](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/search.feature#L95) diff --git a/tests/acceptance/features/apiSpaces/changeSpaces.feature b/tests/acceptance/features/apiSpaces/changeSpaces.feature index 2ea08dfb4..629ce6160 100644 --- a/tests/acceptance/features/apiSpaces/changeSpaces.feature +++ b/tests/acceptance/features/apiSpaces/changeSpaces.feature @@ -16,6 +16,7 @@ Feature: Change data of space And user "Alice" has created a space "Project Jupiter" of type "project" with quota "20" And user "Alice" has shared a space "Project Jupiter" to user "Brian" with role "editor" And user "Alice" has shared a space "Project Jupiter" to user "Bob" with role "viewer" + And using spaces DAV path Scenario Outline: Only space admin user can change the name of a Space via the Graph API diff --git a/tests/acceptance/features/apiSpaces/copySpaces.feature b/tests/acceptance/features/apiSpaces/copySpaces.feature index 11a5b57bf..09de24ed3 100644 --- a/tests/acceptance/features/apiSpaces/copySpaces.feature +++ b/tests/acceptance/features/apiSpaces/copySpaces.feature @@ -9,6 +9,7 @@ Feature: copy file | username | | Alice | | Brian | + And using spaces DAV path Scenario Outline: Copying a file within a same space project with role manager and editor @@ -527,9 +528,9 @@ Feature: copy file Then the HTTP status code should be "204" And as "Alice" folder "/Sample-Folder-A/sample-folder-b/sample-folder-c" should exist And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these entries: - | /second-level-folder/third-level-folder/sample-folder-c | + | /second-level-folder/third-level-folder/sample-folder-c/ | And for user "Brian" folder "BRIAN-FOLDER" of the space "Personal" should contain these files: - | /second-level-folder/third-level-folder/sample-folder-c | + | /second-level-folder/third-level-folder/sample-folder-c/ | And the response when user "Alice" gets the info of the last share should include | file_target | /Shares/BRIAN-FOLDER | @@ -594,7 +595,7 @@ Feature: copy file And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these entries: | /second-level-folder/third-level-file.txt/third-level-folder | And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these entries: - | /second-level-folder/second-level-folder | + | /second-level-folder/second-level-folder/ | And the response when user "Alice" gets the info of the last share should include | file_target | /Shares/BRIAN-FOLDER | @@ -616,7 +617,7 @@ Feature: copy file Then the HTTP status code should be "204" And as "Alice" folder "/Sample-Folder-A/sample-folder-b/sample-folder-c" should exist And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files: - | /second-level-folder/third-level-folder/sample-folder-c | + | /second-level-folder/third-level-folder/sample-folder-c/ | And the response when user "Alice" gets the info of the last share should include | file_target | /Shares/BRIAN-FOLDER | @@ -684,8 +685,8 @@ Feature: copy file When user "Alice" copies folder "/FOLDER/second-level-folder" from space "Personal" to "/BRIAN-FOLDER/second-level-folder/third-level-file.txt" inside space "Shares Jail" using the WebDAV API Then the HTTP status code should be "204" And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files: - | /second-level-folder/third-level-file.txt | - | /second-level-folder/third-level-file.txt/third-level-folder | + | /second-level-folder/third-level-file.txt/ | + | /second-level-folder/third-level-file.txt/third-level-folder/ | And as "Alice" folder "FOLDER/second-level-folder/third-level-folder" should exist And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these files: | /second-level-folder/second-level-folder | diff --git a/tests/acceptance/features/apiSpaces/createFileFolderWhenSharesSpaceExist.feature b/tests/acceptance/features/apiSpaces/createFileFolderWhenSharesSpaceExist.feature index 912225f6a..2d6575260 100644 --- a/tests/acceptance/features/apiSpaces/createFileFolderWhenSharesSpaceExist.feature +++ b/tests/acceptance/features/apiSpaces/createFileFolderWhenSharesSpaceExist.feature @@ -18,12 +18,12 @@ Feature: create file or folder named similar to Shares folder When user "Brian" creates folder "" using the WebDAV API Then the HTTP status code should be "201" And for user "Brian" the space "Personal" should contain these entries: - | / | + | / | Examples: | folder_name | - | /Share | - | /shares | - | /Share1 | + | Share | + | shares | + | Share1 | Scenario Outline: create a file with a name similar to Shares Given using spaces DAV path @@ -31,25 +31,25 @@ Feature: create file or folder named similar to Shares folder Then the HTTP status code should be "201" And the content of file "" for user "Brian" should be "some text" And for user "Brian" the space "Personal" should contain these entries: - | / | + | | And for user "Brian" the space "Shares Jail" should contain these entries: - | /FOLDER | + | FOLDER/ | Examples: | file_name | - | /Share | - | /shares | - | /Share1 | + | Share | + | shares | + | Share1 | Scenario: try to create a folder named Shares Given using spaces DAV path When user "Brian" creates folder "/Shares" using the WebDAV API Then the HTTP status code should be "201" And for user "Brian" the space "Shares Jail" should contain these entries: - | /FOLDER | + | FOLDER/ | Scenario: try to create a file named Shares Given using spaces DAV path When user "Brian" uploads file with content "some text" to "/Shares" using the WebDAV API Then the HTTP status code should be "201" And for user "Brian" the space "Shares Jail" should contain these entries: - | /FOLDER | + | FOLDER/ | diff --git a/tests/acceptance/features/apiSpaces/download.feature b/tests/acceptance/features/apiSpaces/download.feature index 983c8b58a..af74af584 100644 --- a/tests/acceptance/features/apiSpaces/download.feature +++ b/tests/acceptance/features/apiSpaces/download.feature @@ -11,6 +11,7 @@ Feature: Download file in project space | Alice | | Brian | | Bob | + And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "download file" with the default quota using the GraphApi And user "Alice" has uploaded a file inside space "download file" with content "some content" to "file.txt" diff --git a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature index 29e4a96f9..e065f3081 100644 --- a/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature +++ b/tests/acceptance/features/apiSpaces/editPublicLinkOfSpace.feature @@ -14,6 +14,7 @@ Feature: A manager of the space can edit public link | username | | Alice | | Brian | + And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "edit space" with the default quota using the GraphApi And user "Alice" has created a public link share of the space "edit space" with settings: diff --git a/tests/acceptance/features/apiSpaces/filePreviews.feature b/tests/acceptance/features/apiSpaces/filePreviews.feature index 93f9009cb..6d861d3e8 100644 --- a/tests/acceptance/features/apiSpaces/filePreviews.feature +++ b/tests/acceptance/features/apiSpaces/filePreviews.feature @@ -11,6 +11,7 @@ Feature: Preview file in project space | Alice | And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "previews of the files" with the default quota using the GraphApi + And using spaces DAV path Scenario Outline: An user can preview created txt files in the project space diff --git a/tests/acceptance/features/apiSpaces/listSpaces.feature b/tests/acceptance/features/apiSpaces/listSpaces.feature index f4f3e96a0..bf80f38ac 100644 --- a/tests/acceptance/features/apiSpaces/listSpaces.feature +++ b/tests/acceptance/features/apiSpaces/listSpaces.feature @@ -8,6 +8,7 @@ Feature: List and create spaces Background: Given user "Alice" has been created with default attributes and without skeleton files + And using spaces DAV path Scenario: An ordinary user can request information about their Space via the Graph API diff --git a/tests/acceptance/features/apiSpaces/moveSpaces.feature b/tests/acceptance/features/apiSpaces/moveSpaces.feature index dc7297f6e..4a04c3773 100644 --- a/tests/acceptance/features/apiSpaces/moveSpaces.feature +++ b/tests/acceptance/features/apiSpaces/moveSpaces.feature @@ -9,6 +9,7 @@ Feature: move (rename) file | username | | Alice | | Brian | + And using spaces DAV path Scenario Outline: Moving a file within same space project with role manager and editor Given the administrator has given "Brian" the role "Space Admin" using the settings api diff --git a/tests/acceptance/features/apiSpaces/quota.feature b/tests/acceptance/features/apiSpaces/quota.feature index 781d6b1ce..72f29d5bf 100644 --- a/tests/acceptance/features/apiSpaces/quota.feature +++ b/tests/acceptance/features/apiSpaces/quota.feature @@ -14,6 +14,7 @@ Feature: State of the quota Background: Given user "Alice" has been created with default attributes and without skeleton files And the administrator has given "Alice" the role "Space Admin" using the settings api + And using spaces DAV path Scenario Outline: Quota information is returned in the list of spaces returned via the Graph API diff --git a/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature b/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature index e7650acb7..bdcd09eaa 100644 --- a/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature +++ b/tests/acceptance/features/apiSpaces/removeSpaceObjects.feature @@ -13,6 +13,7 @@ Feature: Remove files, folder | username | | Alice | | Brian | + And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "delete objects" with the default quota using the GraphApi And user "Alice" has created a folder "folderForDeleting/sub1/sub2" in space "delete objects" diff --git a/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature b/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature index b1c970c62..74c81fd48 100644 --- a/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature +++ b/tests/acceptance/features/apiSpaces/restoreSpaceObjects.feature @@ -14,6 +14,7 @@ Feature: Restore files, folder | Brian | | Bob | | Carol | + And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" creates a space "restore objects" of type "project" with the default quota using the GraphApi And user "Alice" has created a folder "newFolder" in space "restore objects" diff --git a/tests/acceptance/features/apiSpaces/restoreSpaces.feature b/tests/acceptance/features/apiSpaces/restoreSpaces.feature index cc8814786..e2a4b8db9 100644 --- a/tests/acceptance/features/apiSpaces/restoreSpaces.feature +++ b/tests/acceptance/features/apiSpaces/restoreSpaces.feature @@ -16,6 +16,7 @@ Feature: Restoring space | Bob | And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "restore a space" of type "project" with quota "10" + And using spaces DAV path Scenario: An owner can restore a Space via the Graph API diff --git a/tests/acceptance/features/apiSpaces/search.feature b/tests/acceptance/features/apiSpaces/search.feature index ade0b35c1..8fcd40f5c 100644 --- a/tests/acceptance/features/apiSpaces/search.feature +++ b/tests/acceptance/features/apiSpaces/search.feature @@ -10,12 +10,12 @@ Feature: Search | username | | Alice | | Brian | - And using new DAV path + And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "find data" with the default quota using the GraphApi And user "Alice" has created a folder "folder/SubFolder1/subFOLDER2" in space "find data" And user "Alice" has uploaded a file inside space "find data" with content "some content" to "folder/SubFolder1/subFOLDER2/insideTheFolder.txt" - + And using new DAV path Scenario: Alice can find data from the project space When user "Alice" searches for "fol" using the WebDAV API @@ -51,7 +51,7 @@ Feature: Search | /SubFolder1/subFOLDER2 | | /SubFolder1/subFOLDER2/insideTheFolder.txt | And for user "Brian" the search result should contain space "mountpoint/folder" - + Scenario: User can find hidden file Given user "Alice" has created a folder ".space" in space "find data" @@ -72,7 +72,7 @@ Feature: Search | /SubFolder1/subFOLDER2 | | /SubFolder1/subFOLDER2/insideTheFolder.txt | - + Scenario: User cannot find declined folder Given user "Alice" shares the following entity "folder" inside of space "find data" with user "Brian" with role "viewer" And user "Brian" has declined share "/folder" offered by user "Alice" @@ -90,7 +90,7 @@ Feature: Search When user "Alice" searches for "folder" using the WebDAV API Then the HTTP status code should be "207" And the search result should contain "0" entries - + Scenario: User can find project space by name When user "Alice" searches for "find data" using the WebDAV API diff --git a/tests/acceptance/features/apiSpaces/shareSpaces.feature b/tests/acceptance/features/apiSpaces/shareSpaces.feature index 176423df0..e95c97f2e 100644 --- a/tests/acceptance/features/apiSpaces/shareSpaces.feature +++ b/tests/acceptance/features/apiSpaces/shareSpaces.feature @@ -14,6 +14,7 @@ Feature: Share spaces | Bob | And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "share space" with the default quota using the GraphApi + And using spaces DAV path Scenario Outline:: A user can share a space to another user diff --git a/tests/acceptance/features/apiSpaces/shareSpacesViaLink.feature b/tests/acceptance/features/apiSpaces/shareSpacesViaLink.feature index 643157df9..49b7d2cbb 100644 --- a/tests/acceptance/features/apiSpaces/shareSpacesViaLink.feature +++ b/tests/acceptance/features/apiSpaces/shareSpacesViaLink.feature @@ -11,6 +11,7 @@ Feature: Share spaces via link | username | | Alice | | Brian | + And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "share space" with the default quota using the GraphApi And user "Alice" has uploaded a file inside space "share space" with content "some content" to "test.txt" diff --git a/tests/acceptance/features/apiSpaces/shareSubItemOfSpace.feature b/tests/acceptance/features/apiSpaces/shareSubItemOfSpace.feature index 184fae7da..228524400 100644 --- a/tests/acceptance/features/apiSpaces/shareSubItemOfSpace.feature +++ b/tests/acceptance/features/apiSpaces/shareSubItemOfSpace.feature @@ -13,13 +13,15 @@ Feature: Share a file or folder that is inside a space | Alice | | Brian | | Bob | + And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "share sub-item" with the default quota using the GraphApi And user "Alice" has created a folder "folder" in space "share sub-item" And user "Alice" has uploaded a file inside space "share sub-item" with content "some content" to "file.txt" + And using new DAV path - - Scenario Outline: A manager of the space can share an entity inside project space to another user with role: + + Scenario Outline: A manager of the space can share an entity inside project space to another user with role When user "Alice" shares the following entity "" inside of space "share sub-item" with user "Brian" with role "" Then the HTTP status code should be "200" And the OCS status code should be "200" diff --git a/tests/acceptance/features/apiSpaces/shareSubItemOfSpaceViaPublicLink.feature b/tests/acceptance/features/apiSpaces/shareSubItemOfSpaceViaPublicLink.feature index 96f74ad2b..ca027bcf3 100644 --- a/tests/acceptance/features/apiSpaces/shareSubItemOfSpaceViaPublicLink.feature +++ b/tests/acceptance/features/apiSpaces/shareSubItemOfSpaceViaPublicLink.feature @@ -23,6 +23,7 @@ Feature: Share a file or folder that is inside a space via public link | username | | Alice | | Brian | + And using spaces DAV path And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "share sub-item" with the default quota using the GraphApi And user "Alice" has created a folder "folder" in space "share sub-item" diff --git a/tests/acceptance/features/apiSpaces/uploadSpaces.feature b/tests/acceptance/features/apiSpaces/uploadSpaces.feature index 9b170787c..c987c688d 100644 --- a/tests/acceptance/features/apiSpaces/uploadSpaces.feature +++ b/tests/acceptance/features/apiSpaces/uploadSpaces.feature @@ -14,6 +14,7 @@ Feature: Upload files into a space | Bob | And the administrator has given "Alice" the role "Space Admin" using the settings api And user "Alice" has created a space "Project Ceres" of type "project" with quota "2000" + And using spaces DAV path Scenario Outline: An user creates a folder in the Space via the Graph API diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index dac9c6fc2..fc999aab8 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -69,7 +69,10 @@ class SpacesContext implements Context { * @var ChecksumContext */ private ChecksumContext $checksumContext; - + /** + * @var FilesVersionsContext + */ + private FilesVersionsContext $filesVersionsContext; /** * @var string */ @@ -107,18 +110,6 @@ class SpacesContext implements Context { */ private $storedEtags = []; - /** - * - * @var string[][] - */ - private $tokenOfLastLock = []; - - private $etagPropfindBody = '' - . '' - . ''; - /** * @param string $spaceName * @@ -192,22 +183,6 @@ class SpacesContext implements Context { */ private string $responseSpaceId; - /** - * @param string $responseSpaceId - * - * @return void - */ - public function setResponseSpaceId(string $responseSpaceId): void { - $this->responseSpaceId = $responseSpaceId; - } - - /** - * @return string - */ - public function getResponseSpaceId(): string { - return $this->responseSpaceId; - } - /** * Get SpaceId by Name * @@ -285,6 +260,8 @@ class SpacesContext implements Context { */ public function setSpaceIDByName(string $user, string $spaceName): void { $space = $this->getSpaceByName($user, $spaceName); + Assert::assertIsArray($space, "Space with name $spaceName not found"); + Assert::assertNotEmpty($space["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName not found"); WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id']; } @@ -340,29 +317,6 @@ class SpacesContext implements Context { return $this->featureContext->getResponse(); } - /** - * Download a file using user password - * - * @param string $fullUrl - * @param string $user - * - * @return void - */ - public function downloadFileAsUserUsingPassword( - string $fullUrl, - string $user - ):void { - $this->featureContext->setResponse( - HttpRequestHelper::sendRequest( - $fullUrl, - $this->featureContext->getStepLineRef(), - 'GET', - $user, - $this->featureContext->getPasswordForUser($user), - ) - ); - } - /** * The method returns fileId * @@ -456,6 +410,7 @@ class SpacesContext implements Context { $this->webDavPropertiesContext = $environment->getContext('WebDavPropertiesContext'); $this->favoritesContext = $environment->getContext('FavoritesContext'); $this->checksumContext = $environment->getContext('ChecksumContext'); + $this->filesVersionsContext = $environment->getContext('FilesVersionsContext'); // Run the BeforeScenario function in OCSContext to set it up correctly $this->ocsContext->before($scope); $this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/"); @@ -542,31 +497,6 @@ class SpacesContext implements Context { return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PROPFIND', $user, $password, $headers, $body); } - /** - * Send Put Request to Url - * - * @param string $fullUrl - * @param string $user - * @param string $password - * @param string $xRequestId - * @param array $headers - * @param string $content - * - * @return ResponseInterface - * - * @throws GuzzleException - */ - public function sendPutRequestToUrl( - string $fullUrl, - string $user, - string $password, - string $xRequestId = '', - array $headers = [], - string $content = "" - ): ResponseInterface { - return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PUT', $user, $password, $headers, $content); - } - /** * Send POST Request to url * @@ -856,24 +786,20 @@ class SpacesContext implements Context { string $spaceName, string $foldersPath = '' ): void { - $space = $this->getSpaceByName($user, $spaceName); - Assert::assertIsArray($space); - Assert::assertNotEmpty($spaceId = $space["id"]); - Assert::assertNotEmpty($spaceWebDavUrl = $space["root"]["webDavUrl"]); - $headers['Depth'] = 'infinity'; + $this->setSpaceIDByName($user, $spaceName); $this->featureContext->setResponse( - $this->sendPropfindRequestToUrl( - $spaceWebDavUrl . '/' . $foldersPath, + WebDavHelper::propfind( + $this->featureContext->getBaseUrl(), $user, $this->featureContext->getPasswordForUser($user), + $foldersPath, + [], '', - $headers + 'infinity', + 'files', + WebDavHelper::DAV_VERSION_SPACES ) ); - $this->setResponseSpaceId($spaceId); - $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->featureContext->getResponse()) - ); } /** @@ -890,10 +816,11 @@ class SpacesContext implements Context { string $shouldOrNot, TableNode $expectedFiles ): void { - $this->propfindResultShouldContainEntries( + $this->featureContext->propfindResultShouldContainEntries( $shouldOrNot, $expectedFiles, ); + WebDavHelper::$SPACE_ID_FROM_OCIS = ''; } /** @@ -912,14 +839,18 @@ class SpacesContext implements Context { string $shouldOrNot, TableNode $expectedFiles ): void { + $spaceCreator = $this->getSpaceCreator($spaceName); + $space = $this->getSpaceByName($spaceCreator, $spaceName); $this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi( - $this->getSpaceCreator($spaceName), + $spaceCreator, $spaceName ); - $this->propfindResultShouldContainEntries( + WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id']; + $this->featureContext->propfindResultShouldContainEntries( $shouldOrNot, $expectedFiles, ); + WebDavHelper::$SPACE_ID_FROM_OCIS = ''; } /** @@ -940,14 +871,14 @@ class SpacesContext implements Context { string $shouldOrNot, TableNode $expectedFiles ): void { + $space = $this->getSpaceByName($user, $spaceName); $this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi( $user, $spaceName ); - $this->propfindResultShouldContainEntries( - $shouldOrNot, - $expectedFiles - ); + WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id']; + $this->featureContext->propfindResultShouldContainEntries($shouldOrNot, $expectedFiles, $user, 'PROPFIND'); + WebDavHelper::$SPACE_ID_FROM_OCIS = ''; } /** @@ -970,16 +901,21 @@ class SpacesContext implements Context { string $shouldOrNot, TableNode $expectedFiles ): void { + $space = $this->getSpaceByName($user, $spaceName); $this->theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi( $user, $spaceName, $folderPath ); - $this->propfindResultShouldContainEntries( + WebDavHelper::$SPACE_ID_FROM_OCIS = $space['id']; + $this->featureContext->propfindResultShouldContainEntries( $shouldOrNot, $expectedFiles, + $this->featureContext->getActualUsername($user), + 'PROPFIND', $folderPath ); + WebDavHelper::$SPACE_ID_FROM_OCIS = ''; } /** @@ -1214,43 +1150,6 @@ class SpacesContext implements Context { } } - /** - * @param string $shouldOrNot (not|) - * @param TableNode $expectedFiles - * @param string $folderPath - * - * @return void - * - * @throws Exception - */ - public function propfindResultShouldContainEntries( - string $shouldOrNot, - TableNode $expectedFiles, - string $folderPath = '' - ): void { - $this->verifyTableNodeColumnsCount($expectedFiles, 1); - $elementRows = $expectedFiles->getRows(); - $should = ($shouldOrNot !== "not"); - - foreach ($elementRows as $expectedFile) { - $fileFound = $this->findEntryFromPropfindResponse( - $expectedFile[0], - $folderPath - ); - if ($should) { - Assert::assertNotEmpty( - $fileFound, - "response does not contain the entry '$expectedFile[0]'" - ); - } else { - Assert::assertEmpty( - $fileFound, - "response does contain the entry '$expectedFile[0]' but should not" - ); - } - } - } - /** * Verify that the tableNode contains expected number of columns * @@ -1288,72 +1187,6 @@ class SpacesContext implements Context { return \str_replace([" ", "(", ")"], ["%20", "%28", "%29"], $path); } - /** - * parses a PROPFIND response from $this->response into xml - * and returns found search results if found else returns false - * - * @param string|null $entryNameToSearch - * @param string $folderPath - * - * @return array - * string if $entryNameToSearch is given and is found - * array if $entryNameToSearch is not given - * boolean false if $entryNameToSearch is given and is not found - */ - public function findEntryFromPropfindResponse( - string $entryNameToSearch = null, - string $folderPath = '' - ): array { - $spaceId = $this->getResponseSpaceId(); - //if we are using that step the second time in a scenario e.g. 'But ... should not' - //then don't parse the result again, because the result is in a ResponseInterface - if (empty($this->getResponseXml())) { - $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->featureContext->getResponse()) - ); - } - Assert::assertNotEmpty($this->getResponseXml(), __METHOD__ . ' Response is empty'); - Assert::assertNotEmpty($spaceId, __METHOD__ . ' SpaceId is empty'); - - // trim any leading "/" passed by the caller, we can just match the "raw" name - $trimmedEntryNameToSearch = \trim($entryNameToSearch, "/"); - - // url encode for spaces and brackets that may appear in the filePath - $folderPath = $this->escapePath($folderPath); - - // topWebDavPath should be something like /remote.php/webdav/ or - // /remote.php/dav/files/alice/ - $topWebDavPath = "/" . "dav/spaces/" . $spaceId . "/" . $folderPath; - - Assert::assertIsArray( - $this->responseXml, - __METHOD__ . " responseXml for space $spaceId is not an array" - ); - Assert::assertArrayHasKey( - "value", - $this->responseXml, - __METHOD__ . " responseXml for space $spaceId does not have key 'value'" - ); - $multistatusResults = $this->responseXml["value"]; - $results = []; - if ($multistatusResults !== null) { - foreach ($multistatusResults as $multistatusResult) { - $entryPath = \urldecode($multistatusResult['value'][0]['value']); - $entryName = \str_replace($topWebDavPath, "", $entryPath); - $entryName = \rawurldecode($entryName); - $entryName = \trim($entryName, "/"); - if ($trimmedEntryNameToSearch === $entryName) { - return $multistatusResult; - } - $results[] = $entryName; - } - } - if ($entryNameToSearch === null) { - return $results; - } - return []; - } - /** * @When /^user "([^"]*)" creates a (?:folder|subfolder) "([^"]*)" in space "([^"]*)" using the WebDav Api$/ * @@ -1423,19 +1256,8 @@ class SpacesContext implements Context { if ($ownerUser === '') { $ownerUser = $user; } - - $space = $this->getSpaceByName($ownerUser, $spaceName); - - $fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $folder; - - $this->featureContext->setResponse( - $this->sendCreateFolderRequest( - $fullUrl, - "MKCOL", - $user, - $this->featureContext->getPasswordForUser($user) - ) - ); + $this->setSpaceIDByName($ownerUser, $spaceName); + $this->featureContext->userCreatesFolder($user, $folder); } /** @@ -1456,20 +1278,8 @@ class SpacesContext implements Context { string $content, string $destination ): void { - $space = $this->getSpaceByName($user, $spaceName); - Assert::assertIsArray($space, "Space with name $spaceName not found"); - Assert::assertNotEmpty($space["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName not found"); - - $this->featureContext->setResponse( - $this->sendPutRequestToUrl( - $space["root"]["webDavUrl"] . "/" . $destination, - $user, - $this->featureContext->getPasswordForUser($user), - "", - [], - $content - ) - ); + $this->setSpaceIDByName($user, $spaceName); + $this->featureContext->uploadFileWithContent($user, $content, $destination); } /** @@ -1492,20 +1302,8 @@ class SpacesContext implements Context { string $content, string $destination ): void { - $space = $this->getSpaceByName($ownerUser, $spaceName); - Assert::assertIsArray($space, "Space with name $spaceName not found"); - Assert::assertNotEmpty($space["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName not found"); - - $this->featureContext->setResponse( - $this->sendPutRequestToUrl( - $space["root"]["webDavUrl"] . "/" . $destination, - $user, - $this->featureContext->getPasswordForUser($user), - "", - [], - $content - ) - ); + $this->setSpaceIDByName($ownerUser, $spaceName); + $this->featureContext->uploadFileWithContent($user, $content, $destination); } /** @@ -1917,7 +1715,7 @@ class SpacesContext implements Context { ):void { $space = $this->getSpaceByName($user, $spaceName); $fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileName, "/"); - $this->downloadFileAsUserUsingPassword($fullUrl, $user); + $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user)); Assert::assertGreaterThanOrEqual( 400, $this->featureContext->getResponse()->getStatusCode(), @@ -2017,22 +1815,7 @@ class SpacesContext implements Context { string $destination ): void { $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); - - $space = $this->getSpaceByName($user, $spaceName); - Assert::assertIsArray($space, "Space with name $spaceName not found"); - Assert::assertNotEmpty($space["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName not found"); - - $this->featureContext->setResponse( - $this->sendPutRequestToUrl( - $space["root"]["webDavUrl"] . "/" . $destination, - $user, - $this->featureContext->getPasswordForUser($user), - "", - [], - $fileContent - ) - ); - + $this->theUserUploadsAFileToSpace($user, $spaceName, $fileContent, $destination); $this->featureContext->theHTTPStatusCodeShouldBeOr(201, 204); } @@ -2098,7 +1881,6 @@ class SpacesContext implements Context { ]; $fullUrl = $this->baseUrl . $this->ocsApiUrl; - $this->featureContext->setResponse( $this->sendPostRequestToUrl( $fullUrl, @@ -2671,20 +2453,8 @@ class SpacesContext implements Context { string $fileName, string $spaceName ): void { - $space = $this->getSpaceByName($user, $spaceName); - $fullUrl = $this->baseUrl . $this->davSpacesUrl . $space['id'] . '/' . $fileName; - - $this->featureContext->setResponse( - HttpRequestHelper::sendRequest( - $fullUrl, - "", - 'HEAD', - $user, - $this->featureContext->getPasswordForUser($user), - [], - "" - ) - ); + $this->setSpaceIDByName($user, $spaceName); + $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName, $this->featureContext->getPasswordForUser($user)); } /** @@ -2746,56 +2516,9 @@ class SpacesContext implements Context { string $index, string $spaceName ): void { - $fileVersion = $this->listFileVersion($user, $fileName, $spaceName); - if (!isset($fileVersion[$index])) { - Assert::fail( - 'could not find version of file "' . $fileName . '" with index "' . $index . '"' - ); - } - $url = $this->baseUrl . $fileVersion[$index][0]; - - $this->featureContext->setResponse( - HttpRequestHelper::sendRequest( - $url, - "", - 'HEAD', - $user, - $this->featureContext->getPasswordForUser($user), - [], - "" - ) - ); - } - - /** - * Method returns an array with url values from the propfind request - * like: /remote.php/dav/meta/spaceUuid%fileUuid/v/fileUuid.REV.2022-05-17T10:39:49.672285951Z - * - * @param string $user - * @param string $fileName - * @param string $spaceName - * - * @return array - * @throws GuzzleException - */ - public function listFileVersion( - string $user, - string $fileName, - string $spaceName - ): array { - $fileId = $this->getFileId($user, $spaceName, $fileName); - $fullUrl = $this->baseUrl . '/remote.php/dav/meta/' . $fileId . '/v'; - - $this->featureContext->setResponse( - $this->sendPropfindRequestToUrl( - $fullUrl, - $user, - $this->featureContext->getPasswordForUser($user) - ) - ); - - $responseXml = HttpRequestHelper::getResponseXml($this->featureContext->getResponse()); - return $responseXml->xpath("//d:response/d:href"); + $this->setSpaceIDByName($user, $spaceName); + $this->filesVersionsContext->downloadVersion($user, $fileName, $index); + WebDavHelper::$SPACE_ID_FROM_OCIS = ''; } /** @@ -2809,20 +2532,8 @@ class SpacesContext implements Context { * @throws GuzzleException */ public function userGetsEtagOfElementInASpace(string $user, string $space, string $path) { - $user = $this->featureContext->getActualUsername($user); - $space = $this->getSpaceByName($user, $space); - - $fullUrl = $space['root']['webDavUrl'] . '/' . ltrim($path, '/'); - $response = $this->sendPropfindRequestToUrl( - $fullUrl, - $user, - $this->featureContext->getPasswordForUser($user), - $this->featureContext->getStepLineRef(), - [], - $this->etagPropfindBody - ); - $responseXml = HttpRequestHelper::getResponseXml($response); - $this->featureContext->setResponseXmlObject($responseXml); + $this->setSpaceIDByName($user, $space); + $this->webDavPropertiesContext->storeEtagOfElement($user, $path); return $this->featureContext->getEtagFromResponseXmlObject(); }