From 2bee588977250c38472ca99cc34f1a4384e1b74b Mon Sep 17 00:00:00 2001 From: Prajwol Amatya <83579989+PrajwolAmatya@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:59:34 +0545 Subject: [PATCH] added test for previewing shared resource inside project space (#7544) --- tests/TestHelpers/SharingHelper.php | 5 ++++ .../features/apiSpaces/filePreviews.feature | 23 ++++++++++++++ .../acceptance/features/bootstrap/Sharing.php | 3 ++ .../features/bootstrap/SpacesContext.php | 30 +++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/tests/TestHelpers/SharingHelper.php b/tests/TestHelpers/SharingHelper.php index a58c154fb..86dafcfcd 100644 --- a/tests/TestHelpers/SharingHelper.php +++ b/tests/TestHelpers/SharingHelper.php @@ -84,6 +84,7 @@ class SharingHelper { * @param string|null $expireDate An expire date for public link shares. * This argument expects a date string * in the format 'YYYY-MM-DD'. + * @param string|null $space_ref * @param int $ocsApiVersion * @param int $sharingApiVersion * @param string $sharingApp @@ -104,6 +105,7 @@ class SharingHelper { $permissions = null, ?string $linkName = null, ?string $expireDate = null, + ?string $space_ref = null, int $ocsApiVersion = 1, int $sharingApiVersion = 1, string $sharingApp = 'files_sharing' @@ -157,6 +159,9 @@ class SharingHelper { if ($expireDate !== null) { $fd['expireDate'] = $expireDate; } + if ($space_ref !== null) { + $fd['space_ref'] = $space_ref; + } $headers = ['OCS-APIREQUEST' => 'true']; return HttpRequestHelper::post( $fullUrl, diff --git a/tests/acceptance/features/apiSpaces/filePreviews.feature b/tests/acceptance/features/apiSpaces/filePreviews.feature index bf79be4bc..21863e894 100644 --- a/tests/acceptance/features/apiSpaces/filePreviews.feature +++ b/tests/acceptance/features/apiSpaces/filePreviews.feature @@ -41,3 +41,26 @@ Feature: Preview file in project space | filesForUpload/example.gif | example.gif | 36 | 36 | | filesForUpload/example.gif | example.gif | 1200 | 1200 | | filesForUpload/example.gif | example.gif | 1280 | 1280 | + + + Scenario Outline: download preview of shared file inside project space + Given user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has uploaded a file from "" to "" via TUS inside of the space "previews of the files" using the WebDAV API + And user "Alice" has shared resource "" inside space "previews of the files" with user "Brian" + When user "Brian" downloads the preview of shared resource "/Shares/" with width "32" and height "32" using the WebDAV API + Then the HTTP status code should be "200" + And the downloaded image should be "32" pixels wide and "32" pixels high + Examples: + | source | destination | + | filesForUpload/testavatar.png | testavatar.png | + | filesForUpload/lorem.txt | lorem.txt | + + + Scenario: download preview of file inside shared folder in project space + Given user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has created a folder "folder" in space "previews of the files" + And user "Alice" has uploaded a file inside space "previews of the files" with content "test" to "/folder/lorem.txt" + And user "Alice" has shared resource "/folder" inside space "previews of the files" with user "Brian" + When user "Brian" downloads the preview of shared resource "Shares/folder/lorem.txt" with width "32" and height "32" using the WebDAV API + Then the HTTP status code should be "200" + And the downloaded image should be "32" pixels wide and "32" pixels high diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index b51ad35e1..f6cea19a9 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -806,6 +806,7 @@ trait Sharing { * @param string|int|string[]|int[]|null $permissions * @param string|null $linkName * @param string|null $expireDate + * @param string|null $space_ref * @param string $sharingApp * * @return ResponseInterface @@ -822,6 +823,7 @@ trait Sharing { $permissions = null, ?string $linkName = null, ?string $expireDate = null, + ?string $space_ref = null, string $sharingApp = 'files_sharing' ): ResponseInterface { $userActual = $this->getActualUsername($user); @@ -842,6 +844,7 @@ trait Sharing { $permissions, $linkName, $expireDate, + $space_ref, $this->ocsApiVersion, $this->sharingApiVersion, $sharingApp diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 232578d8c..df0f1e3b3 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3704,4 +3704,34 @@ class SpacesContext implements Context { ) ); } + + /** + * @Given user :sharer has shared resource :path inside space :space with user :sharee + * + * @param $sharer string + * @param $path string + * @param $space string + * @param $sharee string + * + * @return void + * @throws GuzzleException + */ + public function userHasSharedResourceInsideSpaceWithUser(string $sharer, string $path, string $space, string $sharee): void { + $sharer = $this->featureContext->getActualUsername($sharer); + $resource_id = $this->getResourceId($sharer, $space, $path); + $response = $this->featureContext->createShare( + $sharer, + $path, + '0', + $this->featureContext->getActualUsername($sharee), + null, + null, + null, + null, + null, + $resource_id + ); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); + $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); + } }