diff --git a/tests/acceptance/features/bootstrap/DirectUploadContext.php b/tests/acceptance/features/bootstrap/DirectUploadContext.php index 512dd11f3..0c1313018 100644 --- a/tests/acceptance/features/bootstrap/DirectUploadContext.php +++ b/tests/acceptance/features/bootstrap/DirectUploadContext.php @@ -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); } diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index c4efd05e6..4f95fa2b7 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -345,6 +345,10 @@ 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, @@ -352,7 +356,7 @@ public function userHasCreatedFolder( $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'" ); } @@ -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', @@ -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, @@ -584,7 +588,7 @@ public function uploadFileWithContent( [], $content ); - return $this->getIdOfElement($user, $destination); + return $this->getIdOfFileOrFolder($user, $destination); } @@ -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, ' @@ -706,14 +710,24 @@ public function getIdOfElement(string $user, string $element): int { ' ); - $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 diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index 0852cb918..ee533885d 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -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); } diff --git a/tests/acceptance/features/bootstrap/GroupfoldersContext.php b/tests/acceptance/features/bootstrap/GroupfoldersContext.php index cdf92bcc7..9dad408f7 100644 --- a/tests/acceptance/features/bootstrap/GroupfoldersContext.php +++ b/tests/acceptance/features/bootstrap/GroupfoldersContext.php @@ -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" ); }