Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 23 additions & 9 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,18 @@ public function userHasCreatedFolder(
continue;
}
$fullFolderString .= "/" . trim($folder);
// check if the file or folder already exists
if ($this->fileOrFolderExists($user, $fullFolderString)) {
continue;
}
$this->response = $this->makeDavRequest(
$user,
$this->regularUserPassword,
"MKCOL",
$fullFolderString
);
$this->theHTTPStatusCodeShouldBe(
["201","405"], // 405 is returned if the folder already exists
["201"],
"HTTP status code was not 201 while trying to create folder '$fullFolderString' for user '$user'"
);
}
Expand Down Expand Up @@ -457,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 @@ -469,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 @@ -584,7 +588,7 @@ public function uploadFileWithContent(
[],
$content
);
return $this->getIdOfElement($user, $destination);
return $this->getIdOfFileOrFolder($user, $destination);
}


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

public function getIdOfElement(string $user, string $element): int {
$propfindResponse = $this->makeDavRequest(
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 @@ -706,14 +710,24 @@ public function getIdOfElement(string $user, string $element): int {
</d:prop>
</d:propfind>'
);
$xmlBody = $propfindResponse->getBody()->getContents();
$responseXmlObject = new SimpleXMLElement($xmlBody);
}

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(
'oc',
'http://owncloud.org/ns'
);
return (int)(string)$responseXmlObject->xpath('//oc:fileid')[0];
}

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

/**
* @param string $path
* @param string $method
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