Skip to content

Commit

Permalink
test(refactor): change the structure of destinations to make it more …
Browse files Browse the repository at this point in the history
…readable
  • Loading branch information
anon-pradip committed Nov 11, 2024
1 parent f6fd630 commit e422655
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
58 changes: 49 additions & 9 deletions tests/acceptance/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ public function userCopiesMovesFileIntoInsideSpaceUsingFileId(string $user, stri
}

/**
* @Given /^user "([^"]*)" has (copied|moved|renamed) file "([^"]*)" into "([^"]*)" inside space "([^"]*)" using file-id "([^"]*)"$/
* @Given /^user "([^"]*)" has (copied|moved) file "([^"]*)" into "([^"]*)" inside space "([^"]*)" using file-id "([^"]*)"$/
*
* @param string $user
* @param string $actionType
Expand All @@ -2061,14 +2061,15 @@ public function userHasCopiedOrMovedFileInsideSpaceUsingFileId(
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') {
$fileDestination = $this->escapePath($destinationFile) . '/' . $this->escapePath($sourceFile);
} elseif ($actionType === 'renamed' || $actionType === 'moved') {
$fileDestination = $destinationFile;
$sourceFile = \trim($sourceFile, "/");
$sourceFile = \explode("/", $sourceFile);
$sourceFile = \end($sourceFile);
$destinationFile = \trim($destinationFile, "/");

$fileDestination = $this->escapePath($destinationFile);

if (!strpos($destinationFile, "/")) {
$fileDestination .= '/' . $this->escapePath($sourceFile);
}

$baseUrl = $this->featureContext->getBaseUrl();
Expand All @@ -2093,6 +2094,45 @@ public function userHasCopiedOrMovedFileInsideSpaceUsingFileId(
);
}

/**
* @Given /^user "([^"]*)" has renamed file with id "([^"]*)" to "([^"]*)" inside space "([^"]*)"$/
*
* @param string $user
* @param string $fileId
* @param string $destinationFile
* @param string $spaceName
*
* @throws GuzzleException
* @return void
*/
public function userHasRenamedFileInsideSpaceUsingFileId(
string $user,
string $fileId,
string $destinationFile,
string $spaceName
): void {
$destinationFile = \trim($destinationFile, "/");

$fileDestination = $this->escapePath($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";
$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
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Feature: check activities
Scenario: check rename activity
Given user "Alice" has uploaded file with content "ownCloud test text file" to "textfile.txt"
And we save it into "FILEID"
And user "Alice" has renamed file "textfile.txt" into "renamed.txt" inside space "Personal" using file-id "<<FILEID>>"
And user "Alice" has renamed file with id "<<FILEID>>" to "renamed.txt" inside space "Personal"
When user "Alice" lists the activities of file "renamed.txt" from space "Personal" using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
Expand Down Expand Up @@ -365,7 +365,7 @@ Feature: check activities
Given user "Alice" has uploaded file with content "ownCloud test text file" to "textfile.txt"
And we save it into "FILEID"
And user "Alice" has created folder "New Folder"
And user "Alice" has moved file "textfile.txt" into "New Folder/textfile.txt" inside space "Personal" using file-id "<<FILEID>>"
And user "Alice" has moved file "textfile.txt" into "New Folder" inside space "Personal" using file-id "<<FILEID>>"
When user "Alice" lists the activities of file "New Folder/textfile.txt" from space "Personal" using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
Expand Down Expand Up @@ -478,8 +478,8 @@ Feature: check activities
Given user "Alice" has uploaded file with content "ownCloud test text file" to "textfile.txt"
And we save it into "FILEID"
And user "Alice" has created folder "FOLDER"
And user "Alice" has moved file "textfile.txt" into "FOLDER/textfile.txt" inside space "Personal" using file-id "<<FILEID>>"
When user "Alice" lists the activities of file "FOLDER" from space "Personal" using the Graph API
And user "Alice" has moved file "textfile.txt" into "FOLDER" inside space "Personal" using file-id "<<FILEID>>"
When user "Alice" lists the activities of folder "FOLDER" from space "Personal" using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
Expand Down Expand Up @@ -591,7 +591,7 @@ Feature: check activities
Given user "Alice" has uploaded file "filesForUpload/zerobyte.txt" to "zerobyte.txt"
And we save it into "FILEID"
And user "Alice" has created folder "FOLDER"
And user "Alice" has moved file "zerobyte.txt" into "FOLDER/zerobyte.txt" inside space "Personal" using file-id "<<FILEID>>"
And user "Alice" has moved file "zerobyte.txt" into "FOLDER" inside space "Personal" using file-id "<<FILEID>>"
When user "Alice" lists the activities of file "FOLDER/zerobyte.txt" from space "Personal" using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
Expand Down Expand Up @@ -698,7 +698,7 @@ Feature: check activities
}
}
"""
When user "Alice" lists the activities of file "FOLDER" from space "Personal" using the Graph API
When user "Alice" lists the activities of folder "FOLDER" from space "Personal" using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
Expand Down Expand Up @@ -926,7 +926,7 @@ Feature: check activities
}
}
"""
When user "Alice" lists the activities of file "FOLDER" from space "Personal" using the Graph API
When user "Alice" lists the activities of folder "FOLDER" from space "Personal" using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
Expand Down Expand Up @@ -1163,7 +1163,7 @@ Feature: check activities
}
}
"""
When user "Alice" lists the activities of file "FOLDER" from space "Personal" using the Graph API
When user "Alice" lists the activities of folder "FOLDER" from space "Personal" using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
Expand Down

0 comments on commit e422655

Please sign in to comment.