Skip to content

Commit

Permalink
review address
Browse files Browse the repository at this point in the history
Signed-off-by: nabim777 <nabinalemagar019@gmail.com>
  • Loading branch information
nabim777 committed Sep 11, 2024
1 parent 70405fb commit 79900cf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getLastCreatedDirectUploadToken(): ?string {
public function userSendsAPOSTRequestToTheEndpointWithTheFileIdOf(
string $user, string $elementName
): void {
$elementId = $this->featureContext->getIdOfElement($user, $elementName);
$elementId = $this->featureContext->getIdOfFileOrFolder($user, $elementName);
$data = json_encode(array('folder_id' => $elementId));
$this->sendRequestToDirectUploadTokenEndpoint($user, $data);
}
Expand Down
21 changes: 11 additions & 10 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function userHasCreatedFolder(
}
$fullFolderString .= "/" . trim($folder);
// check if the file or folder already exists
if ($this->isElementExist($user, $fullFolderString)) {
if ($this->fileOrFolderExists($user, $fullFolderString)) {
continue;
}
$this->response = $this->makeDavRequest(
Expand Down Expand Up @@ -461,7 +461,7 @@ public function userGetsTheInformationOfFile(string $user, string $fileId): void
* @When user :user gets the information of the folder :fileName
*/
public function userGetsTheInformationOfFileWithName(string $user, string $fileName): void {
$fileId = $this->getIdOfElement($user, $fileName);
$fileId = $this->getIdOfFileOrFolder($user, $fileName);
$this->response = $this->sendOCSRequest(
'/apps/integration_openproject/fileinfo/' . $fileId,
'GET',
Expand All @@ -473,7 +473,7 @@ public function userGetsTheInformationOfFileWithName(string $user, string $fileN
* @When user :user gets the information of all files and group folder :groupFolder created in this scenario
*/
public function userGetsTheInformationOfAllCreatedFiles(string $user, string $groupFolder): void {
$this->createdFiles[] = $this->getIdOfElement($user, $groupFolder);
$this->createdFiles[] = $this->getIdOfFileOrFolder($user, $groupFolder);
$body = json_encode(["fileIds" => $this->createdFiles]);
Assert::assertNotFalse(
$body,
Expand Down Expand Up @@ -588,7 +588,7 @@ public function uploadFileWithContent(
[],
$content
);
return $this->getIdOfElement($user, $destination);
return $this->getIdOfFileOrFolder($user, $destination);
}


Expand Down Expand Up @@ -696,12 +696,12 @@ public function verifyTableNodeColumns(TableNode $table, ?array $requiredHeader
}
}

public function getElementResponse(string $user, string $element): ResponseInterface {
public function propfindFileOrFolder(string $user, string $path): ResponseInterface {
return $this->makeDavRequest(
$user,
$this->regularUserPassword,
"PROPFIND",
$element,
$path,
null,
'<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns" xmlns:ocs="http://open-collaboration-services.org/ns">
Expand All @@ -712,8 +712,9 @@ public function getElementResponse(string $user, string $element): ResponseInter
);
}

public function getIdOfElement(string $user, string $element): int {
$propfindResponse = $this->getElementResponse($user, $element);
public function getIdOfFileOrFolder(string $user, string $path): int {
$propfindResponse = $this->propfindFileOrFolder($user, $path);
// Ensure PROPFIND returned status 207
$this->theHTTPStatusCodeShouldBe(207, "", $propfindResponse);
$responseXmlObject = new SimpleXMLElement($propfindResponse->getBody()->getContents());
$responseXmlObject->registerXPathNamespace(
Expand All @@ -723,8 +724,8 @@ public function getIdOfElement(string $user, string $element): int {
return (int)(string)$responseXmlObject->xpath('//oc:fileid')[0];
}

public function isElementExist(string $user, string $element): bool {
return $this->getElementResponse($user, $element)->getStatusCode() === 207;
public function fileOrFolderExists(string $user, string $path): bool {
return $this->propfindFileOrFolder($user, $path)->getStatusCode() === 207;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function theVersionFolderOfFileShouldContainElements(
string $user,
int $count
):void {
$fileId = $this->featureContext->getIdOfElement($user, $path);
$fileId = $this->featureContext->getIdOfFileOrFolder($user, $path);
Assert::assertNotNull($fileId, __METHOD__ . " file $path user $user not found (the file may not exist)");
$this->theVersionFolderOfFileIdShouldContainElements($user, $fileId, $count);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/features/bootstrap/GroupfoldersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public function groupfolderShouldBeManagedByTheUser(string $folderName, string $
* @Then /^user "([^"]*)" should have a folder called "([^"]*)"$/
*/
public function userShouldHaveAFolderCalled(string $user, string $folderName): void {
Assert::assertIsInt(
$this->featureContext->getIdOfElement($user, $folderName),
Assert::assertTrue(
$this->featureContext->fileOrFolderExists($user, $folderName),
"folder $folderName does not exist"
);
}
Expand Down

0 comments on commit 79900cf

Please sign in to comment.