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 17, 2024
1 parent f49f448 commit 5b8918f
Show file tree
Hide file tree
Showing 3 changed files with 712 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/acceptance/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,65 @@ public function userCopiesOrMovesFileWithFileIdFromAndToSpaceBetweenSpaces(strin
}
}

/**
* @Given /^user "([^"]*)" has (copied|moved|renamed) a file "([^"]*)" into "([^"]*)" inside space "([^"]*)" using file-id path "([^"]*)"$/
*
* @param string $user
* @param string $actionType
* @param string $sourceFile
* @param string $destinationFile
* @param string $toSpaceName
* @param string $url
*
* @return void
* @throws GuzzleException
*/
public function userHasRenamedAFileIntoUsingFileIdPath(string $user, string $actionType, string $sourceFile, string $destinationFile, string $toSpaceName, string $url): void {
$sourceFile = \trim($sourceFile, "/");
$sourceFile = \explode("/", $sourceFile);
$sourceFile = \end($sourceFile);
$destinationFile = \trim($destinationFile, "/");
$fileDestination = '';
if ($actionType === 'copied' || $actionType === 'moved') {
$fileDestination = $this->escapePath($destinationFile) . '/' . $this->escapePath($sourceFile);
} elseif ($actionType === 'renamed') {
$fileDestination = $destinationFile;
}
$baseUrl = $this->featureContext->getBaseUrl();
if ($toSpaceName === 'Shares') {
$sharesPath = $this->featureContext->getSharesMountPath($user, $fileDestination);
$davPath = WebDavHelper::getDavPath($user, $this->featureContext->getDavPathVersion());
$headers['Destination'] = $baseUrl . "/$davPath" . $sharesPath;
} else {
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName, $url);
}
$fullUrl = $baseUrl . $url;
if ($actionType === 'copied') {
$response = $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
} elseif ($actionType === 'moved' || $actionType === 'renamed') {
$response = $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers);
}
Assert::assertEquals(
201,
$response->getStatusCode(),
"Response did not return expected status code"
);
}

/**
* @Given user :user has sent HTTP method :verb to URL :url with content :content
*
* @param string $user
* @param string $url
* @param string $content
*
* @return void
*/
public function userHasEditedAFileWithContentInsideSpaceUsingFileIdPath(string $user, string $url, string $content): void {
$response = $this->featureContext->sendingToWithDirectUrl($user, 'PUT', $url, $content);
$this->featureContext->theHTTPStatusCodeShouldBe(['201', '204'], "", $response);
}

/**
* @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
27 changes: 27 additions & 0 deletions tests/acceptance/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -2755,6 +2755,33 @@ public function userDeletesFileFromSpaceUsingFileIdPath(string $user, string $fi
$this->pushToLastStatusCodesArrays();
}

/**
* @Given user :user has deleted a file :fileName using file-id path :url
*
* @param string $user
* @param string $fileName
* @param string $url
*
* @return void
*/
public function userHasDeletedAFileUsingFileIdPath(string $user, string $fileName, string $url): void {
$requestUrl = $this->getBaseUrl() . $url;
$user = $this->getActualUsername($user);
$password = $this->getPasswordForUser($user);
$response = HttpRequestHelper::sendRequest(
$requestUrl,
null,
'DELETE',
$user,
$password
);
Assert::assertEquals(
204,
$response->getStatusCode(),
"Response did not return expected status code"
);
}

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

0 comments on commit 5b8918f

Please sign in to comment.