Skip to content

Commit 70405fb

Browse files
committed
checks file and folder exists before creation on tests
Signed-off-by: nabim777 <[email protected]>
1 parent e408969 commit 70405fb

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

tests/acceptance/features/api/setup.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ Feature: setup the integration through an API
674674

675675
# user "OpenProject" cannot make api request using the old app password
676676
When user "OpenProject" sends a "PROPFIND" request to "/remote.php/webdav" using old app password
677-
Then the HTTP status code should be "500"
677+
Then the HTTP status code should be "401"
678678

679679

680680
Scenario: check version of uploaded file inside a group folder

tests/acceptance/features/bootstrap/FeatureContext.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,18 @@ public function userHasCreatedFolder(
345345
continue;
346346
}
347347
$fullFolderString .= "/" . trim($folder);
348+
// check if the file or folder already exists
349+
if ($this->isElementExist($user, $fullFolderString)) {
350+
continue;
351+
}
348352
$this->response = $this->makeDavRequest(
349353
$user,
350354
$this->regularUserPassword,
351355
"MKCOL",
352356
$fullFolderString
353357
);
354358
$this->theHTTPStatusCodeShouldBe(
355-
["201","500"], // 405 is returned if the folder already exists
359+
["201"],
356360
"HTTP status code was not 201 while trying to create folder '$fullFolderString' for user '$user'"
357361
);
358362
}
@@ -692,8 +696,8 @@ public function verifyTableNodeColumns(TableNode $table, ?array $requiredHeader
692696
}
693697
}
694698

695-
public function getIdOfElement(string $user, string $element): int {
696-
$propfindResponse = $this->makeDavRequest(
699+
public function getElementResponse(string $user, string $element): ResponseInterface {
700+
return $this->makeDavRequest(
697701
$user,
698702
$this->regularUserPassword,
699703
"PROPFIND",
@@ -706,14 +710,23 @@ public function getIdOfElement(string $user, string $element): int {
706710
</d:prop>
707711
</d:propfind>'
708712
);
709-
$xmlBody = $propfindResponse->getBody()->getContents();
710-
$responseXmlObject = new SimpleXMLElement($xmlBody);
713+
}
714+
715+
public function getIdOfElement(string $user, string $element): int {
716+
$propfindResponse = $this->getElementResponse($user, $element);
717+
$this->theHTTPStatusCodeShouldBe(207, "", $propfindResponse);
718+
$responseXmlObject = new SimpleXMLElement($propfindResponse->getBody()->getContents());
711719
$responseXmlObject->registerXPathNamespace(
712720
'oc',
713721
'http://owncloud.org/ns'
714722
);
715723
return (int)(string)$responseXmlObject->xpath('//oc:fileid')[0];
716724
}
725+
726+
public function isElementExist(string $user, string $element): bool {
727+
return $this->getElementResponse($user, $element)->getStatusCode() === 207;
728+
}
729+
717730
/**
718731
* @param string $path
719732
* @param string $method

0 commit comments

Comments
 (0)