Skip to content

Commit

Permalink
Merge pull request #4510 from owncloud/reuseCodeForLockFromCore
Browse files Browse the repository at this point in the history
[tests-only][full-ci]Reuse locking method from core
  • Loading branch information
phil-davis authored Sep 5, 2022
2 parents e27e5a2 + 23196c7 commit ac0b659
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 55 deletions.
4 changes: 4 additions & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ default:
- PublicWebDavContext:
- TrashbinContext:
- WebDavPropertiesContext:
- WebDavLockingContext:

apiSpaces:
paths:
- '%paths.base%/../features/apiSpaces'
Expand All @@ -46,6 +48,7 @@ default:
- SearchContext:
- TrashbinContext:
- WebDavPropertiesContext:
- WebDavLockingContext:
- TusContext:

apiArchiver:
Expand All @@ -64,6 +67,7 @@ default:
- FavoritesContext:
- TrashbinContext:
- WebDavPropertiesContext:
- WebDavLockingContext:

apiGraph:
paths:
Expand Down
63 changes: 8 additions & 55 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class SpacesContext implements Context {
*/
private FavoritesContext $favoritesContext;

/**
* @var WebDavLockingContext
*/
private WebDavLockingContext $webDavLockingContext;

/**
* @var string
*/
Expand Down Expand Up @@ -451,6 +456,7 @@ public function setUpScenario(BeforeScenarioScope $scope): void {
$this->trashbinContext = $environment->getContext('TrashbinContext');
$this->webDavPropertiesContext = $environment->getContext('WebDavPropertiesContext');
$this->favoritesContext = $environment->getContext('FavoritesContext');
$this->webDavLockingContext = $environment->getContext('WebDavLockingContext');
// Run the BeforeScenario function in OCSContext to set it up correctly
$this->ocsContext->before($scope);
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");
Expand Down Expand Up @@ -2986,60 +2992,6 @@ public function userHasStoredEtagOfElementOnPathFromSpace($user, $path, $storePa
}
}

/**
* Request to lock the resource inside of space
*
* @param string $user
* @param string $resource
* @param TableNode $properties
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function sendRequestToLockResouceInsideOfSpace(string $user, string $resource, TableNode $properties, string $spaceName):void {
$body
= "<?xml version='1.0' encoding='UTF-8'?>" .
"<d:lockinfo xmlns:d='DAV:'> ";
$headers = [];
$this->featureContext->verifyTableNodeRows($properties, [], ['lockscope', 'depth', 'timeout']);
$propertiesRows = $properties->getRowsHash();
foreach ($propertiesRows as $property => $value) {
if ($property === "depth" || $property === "timeout") {
//properties that are set in the header not in the xml
$headers[$property] = $value;
} else {
$body .= "<d:$property><d:$value/></d:$property>";
}
}
$body .= "</d:lockinfo>";
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $space['root']['webDavUrl'] . '/' . ltrim($resource, '/');
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
"",
'LOCK',
$user,
$this->featureContext->getPasswordForUser($user),
[],
$body
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
__METHOD__ . " Failed to lock the resource $resource"
);
$responseXml = $this->featureContext->getResponseXml(null, __METHOD__);
$this->featureContext->setResponseXmlObject($responseXml);
$xmlPart = $responseXml->xpath("//d:locktoken/d:href");
if (\is_array($xmlPart) && isset($xmlPart[0])) {
$this->tokenOfLastLock[$user][$resource] = (string) $xmlPart[0];
} else {
Assert::fail("could not find lock token after trying to lock '$resource'");
}
}

/**
* @Given /^user "([^"]*)" has locked folder "([^"]*)" inside space "([^"]*)" setting the following properties$/
*
Expand All @@ -3051,7 +3003,8 @@ public function sendRequestToLockResouceInsideOfSpace(string $user, string $reso
* @throws Exception | GuzzleException
*/
public function userHasLockedResourceOfSpace(string $user, string $resource, TableNode $properties, string $spaceName) {
$this->sendRequestToLockResouceInsideOfSpace($user, $resource, $properties, $spaceName);
$this->setSpaceIDByName($user, $spaceName);
$this->webDavLockingContext->lockFileUsingWebDavAPI($user, $resource, $properties);
}

/**
Expand Down

0 comments on commit ac0b659

Please sign in to comment.