Skip to content

Commit

Permalink
add test to check file rename activity using file-id
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 22, 2024
1 parent 10bf7f1 commit 1aa6f68
Show file tree
Hide file tree
Showing 3 changed files with 572 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/acceptance/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,53 @@ public function userCopiesMovesFileIntoInsideSpaceUsingFileId(string $user, stri
}
}

/**
* @Given /^user "([^"]*)" has (copied|moved|renamed) a file "([^"]*)" into "([^"]*)" inside space "([^"]*)" using file-id "([^"]*)"$/
*
* @param string $user
* @param string $actionType
* @param string $sourceFile
* @param string $destinationFile
* @param string $spaceName
* @param string $fileId
*
* @throws GuzzleException
* @return void
*/
public function userHasRenamedAFileInsideSpaceUsingFileId(string $user, string $actionType, string $sourceFile, string $destinationFile, string $spaceName, string $fileId): void {
// split the source when there are sub-folders
$sourceFile = \trim($sourceFile, "/");
$sourceFile = \explode("/", $sourceFile);
$sourceFile = \end($sourceFile);
$destinationFile = \trim($destinationFile, "/");
if ($actionType === 'copied' || $actionType === 'moved') {
$fileDestination = $this->escapePath($destinationFile) . '/' . $this->escapePath($sourceFile);
} else {
$fileDestination = $destinationFile;
}

$baseUrl = $this->featureContext->getBaseUrl();
$sourceDavPath = WebdavHelper::getDavPath($this->featureContext->getDavPathVersion());
if ($spaceName === 'Shares') {
$sharesPath = $this->featureContext->getSharesMountPath($user, $fileDestination);
$davPath = WebDavHelper::getDavPath($this->featureContext->getDavPathVersion());
$headers['Destination'] = "$baseUrl/$davPath/$sharesPath";
} else {
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $spaceName, $fileId);
}
$fullUrl = "$baseUrl/$sourceDavPath/$fileId";
if ($actionType === 'copied') {
$response = $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
} else {
$response = $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}
Assert::assertEquals(
201,
$response->getStatusCode(),
"Expected response status code should be 201"
);
}

/**
* @When /^user "([^"]*)" tries to move (?:file|folder) "([^"]*)" of space "([^"]*)" to (space|folder) "([^"]*)" using its id in destination path$/
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" of space "([^"]*)" to (folder) "([^"]*)" using its id in destination path$/
Expand Down
25 changes: 25 additions & 0 deletions tests/acceptance/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -2673,6 +2673,31 @@ public function userDeletesFileFromSpaceUsingFileIdPath(string $user, string $fi
$this->pushToLastStatusCodesArrays();
}

/**
* @Given user :user has updated file with content :content using file-id :fileId
*
* @param string $user
* @param string $content
* @param string $fileId
*
* @return void
*/
public function userHasUpdatedAFileWithContentUsingFileId(string $user, string $content, string $fileId): void {
$baseUrl = $this->getBaseUrl();
$sourceDavPath = WebdavHelper::getDavPath($this->getDavPathVersion());
$fullUrl = "$baseUrl/$sourceDavPath/$fileId";
$response = HttpRequestHelper::sendRequest(
$fullUrl,
$this->getStepLineRef(),
'PUT',
$user,
$this->getPasswordForUser($user),
null,
$content
);
$this->theHTTPStatusCodeShouldBe(['201', '204'], "Expected response status code doesn't match.", $response);
}

/**
* @Given /^user "([^"]*)" has deleted (?:file|folder|entity) "([^"]*)"$/
*
Expand Down
Loading

0 comments on commit 1aa6f68

Please sign in to comment.