Skip to content

Commit

Permalink
add new step for shared resource
Browse files Browse the repository at this point in the history
  • Loading branch information
PrajwolAmatya committed Oct 6, 2023
1 parent 8aef11c commit 8e2ca76
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 26 deletions.
1 change: 1 addition & 0 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ public static function getShareMountId(

// the response returns the shared resource in driveAlias all in lowercase,
// For example: if we get the property of a shared resource "FOLDER" then the response contains "driveAlias": "mountpoint/folder"
// In case of two shares with same name, the response for the second shared resource will contain, "driveAlias": "mountpoint/folder-(2)"
$path = strtolower($path);
foreach ($drives["value"] as $value) {
if ($value["driveAlias"] === "mountpoint/" . $path) {
Expand Down
111 changes: 99 additions & 12 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -3033,11 +3033,7 @@ public function userUploadsAFileWithContentTo(
?string $content,
string $destination
):void {
if ($this->getDavPathVersion() === 3 && str_contains($destination, 'Shares')) {
$this->setResponse($this->userDownloadsOrUploadsSharedResource($user, $destination, 'PUT', null, null, $content));
} else {
$this->uploadFileWithContent($user, $content, $destination);
}
$this->uploadFileWithContent($user, $content, $destination);
$this->pushToLastHttpStatusCodesArray();
}

Expand Down Expand Up @@ -4642,13 +4638,104 @@ public function userHasDeletedEverythingInFolder(string $user, string $folder):v
* @return void
*/
public function downloadPreviewOfFiles(string $user, string $path, string $width, string $height):void {
if ($this->getDavPathVersion() === 3 && str_contains($path, 'Shares')) {
$response = $this->downloadPreviews(
$user,
$path,
null,
$width,
$height
);
$this->setResponse($response);
}

/**
* @When user :user downloads the preview of shared resource :path with width :width and height :height using the WebDAV API
*
* @param string $user
* @param string $path
* @param string $width
* @param string $height
*
* @return void
*/
public function userDownloadsThePreviewOfSharedResourceWithWidthAndHeightUsingTheWebdavApi(string $user, string $path, string $width, string $height): void {
if ($this->getDavPathVersion() === 3) {
$this->setResponse($this->userDownloadsOrUploadsSharedResource($user, $path, 'GET', $width, $height));
} else {
$this->setResponse($this->downloadPreviews($user, $path, null, $width, $height));
}
}

/**
* @Given user :user has downloaded the preview of shared resource :path with width :width and height :height
*
* @param string $user
* @param string $path
* @param string $width
* @param string $height
*
* @return void
*/
public function userHasDownloadedThePreviewOfSharedResourceWithWidthAndHeight(string $user, string $path, string $width, string $height): void {
if ($this->getDavPathVersion() === 3) {
$response = $this->userDownloadsOrUploadsSharedResource($user, $path, 'GET', $width, $height);
} else {
$response = $this->downloadPreviews($user, $path, null, $width, $height);
}
$this->setResponse($response);
$this->theHTTPStatusCodeShouldBe(200, '', $response);
$this->imageDimensionsShouldBe($width, $height);
// save response to user response dictionary for further comparisons
$this->userResponseBodyContents[$user] = $this->responseBodyContent;
}

/**
* @Then as user :user the preview of shared resource :path with width :width and height :height should have been changed
*
* @param string $user
* @param string $path
* @param string $width
* @param string $height
*
* @return void
*/
public function asUserThePreviewOfSharedResourceWithWidthAndHeightShouldHaveBeenChanged(string $user, string $path, string $width, string $height):void {
if ($this->getDavPathVersion() === 3) {
$response = $this->userDownloadsOrUploadsSharedResource($user, $path, 'GET', $width, $height);
} else {
$response = $this->downloadPreviews($user, $path, null, $width, $height);
}
$this->setResponse($response);
$this->theHTTPStatusCodeShouldBe(200, '', $response);
$newResponseBodyContents = $this->response->getBody()->getContents();
Assert::assertNotEquals(
$newResponseBodyContents,
// different users can download files before and after an update is made to a file
// previous response content is fetched from user response body content array for that user
$this->userResponseBodyContents[$user],
__METHOD__ . " previous and current previews content is same but expected to be different",
);
// update the saved content for the next comparison
$this->userResponseBodyContents[$user] = $newResponseBodyContents;
}

/**
* @When user :user uploads file with content :content to shared resource :destination using the WebDAV API
*
* @param string $user
* @param string $content
* @param string $destination
*
* @return void
*/
public function userUploadsFileWithContentSharedResourceToUsingTheWebdavApi(string $user, string $content, string $destination): void {
if ($this->getDavPathVersion() === 3) {
$this->setResponse($this->userDownloadsOrUploadsSharedResource($user, $destination, 'PUT', null, null, $content));
} else {
$this->uploadFileWithContent($user, $content, $destination);
}
}

/**
* @param string $user
* @param string $path
Expand All @@ -4664,8 +4751,8 @@ public function userDownloadsOrUploadsSharedResource(
string $user,
string $path,
string $method,
?string $width,
?string $height,
?string $width = null,
?string $height = null,
?string $content = null
): ResponseInterface {
$user = $this->getActualUsername($user);
Expand Down Expand Up @@ -4811,8 +4898,8 @@ public function theDownloadedPreviewContentShouldMatchWithFixturesPreviewContent
* @return void
*/
public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string $path, string $width, string $height):void {
$this->downloadPreviewOfFiles($user, $path, $width, $height);
$this->theHTTPStatusCodeShouldBe(200);
$response = $this->downloadPreviewOfFiles($user, $path, $width, $height);
$this->theHTTPStatusCodeShouldBe(200, '', $response);
$this->imageDimensionsShouldBe($width, $height);
// save response to user response dictionary for further comparisons
$this->userResponseBodyContents[$user] = $this->responseBodyContent;
Expand All @@ -4829,8 +4916,8 @@ public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string
* @return void
*/
public function asUserThePreviewOfPathWithHeightAndWidthShouldHaveBeenChanged(string $user, string $path, string $width, string $height):void {
$this->downloadPreviewOfFiles($user, $path, $width, $height);
$this->theHTTPStatusCodeShouldBe(200);
$response = $this->downloadPreviewOfFiles($user, $path, $width, $height);
$this->theHTTPStatusCodeShouldBe(200, '', $response);
$newResponseBodyContents = $this->response->getBody()->getContents();
Assert::assertNotEquals(
$newResponseBodyContents,
Expand Down
28 changes: 14 additions & 14 deletions tests/acceptance/features/coreApiWebdavPreviews/previews.feature
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Feature: previews of files downloaded through the webdav API
And user "Alice" has uploaded file "filesForUpload/<resource>" to "/<resource>"
And user "Alice" has shared file "/<resource>" with user "Brian"
And user "Brian" has accepted share "/<resource>" offered by user "Alice"
When user "Brian" downloads the preview of "/Shares/<resource>" with width "32" and height "32" using the WebDAV API
When user "Brian" downloads the preview of shared resource "/Shares/<resource>" 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:
Expand Down Expand Up @@ -215,10 +215,10 @@ Feature: previews of files downloaded through the webdav API
And user "Alice" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
And user "Alice" has shared file "/parent.txt" with user "Brian"
And user "Brian" has accepted share "/parent.txt" offered by user "Alice"
And user "Brian" has downloaded the preview of "/Shares/parent.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of shared resource "/Shares/parent.txt" with width "32" and height "32"
When user "Alice" uploads file with content "this is a file to upload" to "/parent.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Brian" the preview of "/Shares/parent.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "/Shares/parent.txt" with width "32" and height "32" should have been changed
Examples:
| dav-path-version |
| old |
Expand Down Expand Up @@ -249,15 +249,15 @@ Feature: previews of files downloaded through the webdav API
And user "Alice" has shared folder "FOLDER" with user "Brian"
And user "Brian" has accepted share "/FOLDER" offered by user "Alice"
And user "Alice" has downloaded the preview of "/FOLDER/lorem.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32"
When user "Alice" uploads file "filesForUpload/lorem.txt" to "/FOLDER/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Alice" the preview of "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
When user "Brian" uploads file with content "new uploaded content" to "Shares/FOLDER/lorem.txt" using the WebDAV API
And as user "Brian" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
When user "Brian" uploads file with content "new uploaded content" to shared resource "Shares/FOLDER/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Alice" the preview of "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
Examples:
| dav-path-version |
| old |
Expand All @@ -278,18 +278,18 @@ Feature: previews of files downloaded through the webdav API
And user "Brian" has accepted share "/FOLDER" offered by user "Alice"
And user "Carol" has accepted share "/FOLDER" offered by user "Alice"
And user "Alice" has downloaded the preview of "/FOLDER/lorem.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32"
And user "Carol" has downloaded the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32"
And user "Carol" has downloaded the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32"
When user "Alice" uploads file "filesForUpload/lorem.txt" to "/FOLDER/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Alice" the preview of "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
When user "Brian" uploads file with content "new uploaded content" to "Shares/FOLDER/lorem.txt" using the WebDAV API
And as user "Brian" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
When user "Brian" uploads file with content "new uploaded content" to shared resource "Shares/FOLDER/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Alice" the preview of "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
Examples:
| dav-path-version |
| old |
Expand Down

0 comments on commit 8e2ca76

Please sign in to comment.