Skip to content

Commit

Permalink
add tests to check activites of file after public edits it
Browse files Browse the repository at this point in the history
Signed-off-by: prashant-gurung899 <[email protected]>
  • Loading branch information
prashant-gurung899 committed Oct 2, 2024
1 parent 7da4086 commit 9f904cc
Show file tree
Hide file tree
Showing 6 changed files with 513 additions and 30 deletions.
60 changes: 39 additions & 21 deletions tests/acceptance/bootstrap/PublicWebDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,23 @@ public function thePublicDeletesFileFolderFromTheLastPublicLinkShareUsingThePubl

/**
* @param string $fileName
* @param string $publicWebDAVAPIVersion
* @param string $password
*
* @return ResponseInterface
*/
public function deleteFileFromPublicShare(string $fileName, string $publicWebDAVAPIVersion, string $password = ""):ResponseInterface {
public function deleteFileFromPublicShare(string $fileName, string $password = ""):ResponseInterface {
$token = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() : $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
"public-files-new"
);
$password = $this->featureContext->getActualPassword($password);
$fullUrl = $this->featureContext->getBaseUrl() . "/$davPath$fileName";
$userName = $this->getUsernameForPublicWebdavApi(
$token,
$password,
$publicWebDAVAPIVersion
"new"
);
$headers = [
'X-Requested-With' => 'XMLHttpRequest'
Expand All @@ -155,20 +154,29 @@ public function deleteFileFromPublicShare(string $fileName, string $publicWebDAV
}

/**
* @When /^the public deletes (?:file|folder|entry) "([^"]*)" from the last public link share using the password "([^"]*)" and (old|new) public WebDAV API$/
* @Given /^the public has deleted (?:file|folder|entry) "([^"]*)" from the last link share with password "([^"]*)" using the public WebDAV API$/
*
* @param string $file
* @param string $password
* @param string $publicWebDAVAPIVersion
*
* @return void
*/
public function thePublicDeletesFileFromTheLastPublicShareUsingThePasswordPasswordAndOldPublicWebdavApi(string $file, string $password, string $publicWebDAVAPIVersion):void {
if ($publicWebDAVAPIVersion === "old") {
return;
}
public function thePublicHasDeletedFileFromTheLastLinkShareWithPasswordUsingPublicWebdavApi(string $file, string $password): void {
$response = $this->deleteFileFromPublicShare($file, $password);
$this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response);
}

/**
* @When /^the public deletes (?:file|folder|entry) "([^"]*)" from the last link share using the password "([^"]*)" using the public WebDAV API$/
*
* @param string $file
* @param string $password
*
* @return void
*/
public function thePublicDeletesFileFromTheLastShareWithPasswordUsingPublicWebdavApi(string $file, string $password): void {
$this->featureContext->setResponse(
$this->deleteFileFromPublicShare($file, $publicWebDAVAPIVersion, $password)
$this->deleteFileFromPublicShare($file, $password)
);
$this->featureContext->pushToLastStatusCodesArrays();
}
Expand Down Expand Up @@ -534,26 +542,41 @@ public function thePublicHasUploadedFileWithContentWithAutoRenameMode(string $fi
* @param string $filename target file name
* @param string $password
* @param string $body content to upload
* @param string $publicWebDAVAPIVersion
*
* @return ResponseInterface
*/
public function publiclyUploadingContentWithPassword(
string $filename,
string $password = '',
string $body = 'test',
string $publicWebDAVAPIVersion = "old"
):ResponseInterface {
return $this->publicUploadContent(
$filename,
$password,
$body,
true,
[],
$publicWebDAVAPIVersion
);
}

/**
* @Given /^the public has uploaded file "([^"]*)" with content "([^"]*)" and password "([^"]*)" to the last link share using the public WebDAV API$/
*
* @param string $filename
* @param string $content
* @param string $password
*
* @return void
*/
public function thePublicHasUploadedFileWithContentAndPasswordToLastLinkShareUsingPublicWebdavApi(string $filename, string $content = 'test', string $password = ''): void {
$response = $this->publiclyUploadingContentWithPassword(
$filename,
$password,
$content,
);
$this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response);
}

/**
* @When /^the public uploads file "([^"]*)" with password "([^"]*)" and content "([^"]*)" using the (old|new) public WebDAV API$/
*
Expand Down Expand Up @@ -1690,7 +1713,6 @@ public function theMtimeOfFileInTheLastSharedPublicLinkUsingTheWebdavApiShouldNo
* @param string $body
* @param bool $autoRename
* @param array $additionalHeaders
* @param string $publicWebDAVAPIVersion
*
* @return ResponseInterface|null
*/
Expand All @@ -1700,11 +1722,7 @@ public function publicUploadContent(
string $body = 'test',
bool $autoRename = false,
array $additionalHeaders = [],
string $publicWebDAVAPIVersion = "old"
):?ResponseInterface {
if ($publicWebDAVAPIVersion === "old") {
return null;
}
$password = $this->featureContext->getActualPassword($password);
if ($this->featureContext->isUsingSharingNG()) {
$token = $this->featureContext->shareNgGetLastCreatedLinkShareToken();
Expand All @@ -1714,13 +1732,13 @@ public function publicUploadContent(
$davPath = WebDavHelper::getDavPath(
$token,
0,
"public-files-$publicWebDAVAPIVersion"
"public-files-new"
);
$url = $this->featureContext->getBaseUrl() . "/$davPath";
$userName = $this->getUsernameForPublicWebdavApi(
$token,
$password,
$publicWebDAVAPIVersion
"new"
);

$filename = \implode(
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ default:
- FeatureContext: *common_feature_context_params
- SharingNgContext:
- GraphContext:
- PublicWebDavContext:

apiCollaboration:
paths:
Expand Down
Loading

0 comments on commit 9f904cc

Please sign in to comment.