rename variable name and remove unwanted function

This commit is contained in:
amrita
2024-11-29 13:19:54 +05:45
parent e76ba90bee
commit e83b63ffe6
13 changed files with 238 additions and 398 deletions

View File

@@ -32,7 +32,7 @@ class WebDav extends Assert {
*
* @param string|null $element exception|message|reason
* @param string|null $expectedValue
* @param array|null $responseXml
* @param array|null $responseXmlArray
* @param string|null $extraErrorText
*
* @return void
@@ -40,7 +40,7 @@ class WebDav extends Assert {
public static function assertDavResponseElementIs(
?string $element,
?string $expectedValue,
?array $responseXml,
?array $responseXmlArray,
?string $extraErrorText = ''
):void {
if ($extraErrorText !== '') {
@@ -48,15 +48,15 @@ class WebDav extends Assert {
}
self::assertArrayHasKey(
'value',
$responseXml,
$responseXmlArray,
$extraErrorText . "responseXml does not have key 'value'"
);
if ($element === "exception") {
$result = $responseXml['value'][0]['value'];
$result = $responseXmlArray['value'][0]['value'];
} elseif ($element === "message") {
$result = $responseXml['value'][1]['value'];
$result = $responseXmlArray['value'][1]['value'];
} elseif ($element === "reason") {
$result = $responseXml['value'][3]['value'];
$result = $responseXmlArray['value'][3]['value'];
} else {
self::fail(__METHOD__ . " element must be one of exception, response or reason. But '$element' was passed in.");
}

View File

@@ -214,9 +214,10 @@ class CapabilitiesContext implements Context {
$response = $this->userGetsCapabilities($this->getAdminUsernameForCapabilitiesCheck());
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__)->data->capabilities;
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__)->data->capabilities;
$edition = $this->getParameterValueFromXml(
$responseXml,
$responseXmlObject,
'core',
'status@@@edition'
);
@@ -228,7 +229,7 @@ class CapabilitiesContext implements Context {
}
$product = $this->getParameterValueFromXml(
$responseXml,
$responseXmlObject,
'core',
'status@@@product'
);
@@ -239,7 +240,7 @@ class CapabilitiesContext implements Context {
}
$productName = $this->getParameterValueFromXml(
$responseXml,
$responseXmlObject,
'core',
'status@@@productname'
);
@@ -257,7 +258,7 @@ class CapabilitiesContext implements Context {
// We are on oCIS or reva or some other implementation. We cannot do "occ status".
// So get the expected version values by looking in the capabilities response.
$version = $this->getParameterValueFromXml(
$responseXml,
$responseXmlObject,
'core',
'status@@@version'
);
@@ -269,7 +270,7 @@ class CapabilitiesContext implements Context {
}
$versionString = $this->getParameterValueFromXml(
$responseXml,
$responseXmlObject,
'core',
'status@@@versionstring'
);
@@ -323,7 +324,7 @@ class CapabilitiesContext implements Context {
Assert::assertStringStartsWith(
$majorMinorPatchVersion,
$versionString,
"versionstring should start with $majorMinorPatchVersion but is $versionString"
"version string should start with $majorMinorPatchVersion but is $versionString"
);
}
}

View File

@@ -148,23 +148,23 @@ class CollaborationContext implements Context {
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function createFile(string $file, string $password, string $folder = ""): void {
$token = $this->featureContext->shareNgGetLastCreatedLinkShareToken();
$baseUrl = $this->featureContext->getBaseUrl();
$davPath = WebDavHelper::getDavPath(WebDavHelper::DAV_VERSION_NEW, $token, "public-files");
$response = HttpRequestHelper::sendRequest(
"$baseUrl/$davPath/$folder",
$this->featureContext->getStepLineRef(),
"PROPFIND",
"public",
$this->featureContext->getActualPassword($password)
$responseXmlObject = HttpRequestHelper::getResponseXml(
HttpRequestHelper::sendRequest(
"$baseUrl/$davPath/$folder",
$this->featureContext->getStepLineRef(),
"PROPFIND",
"public",
$this->featureContext->getActualPassword($password)
)
);
$responseXml = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$xmlPart = $responseXml->xpath("//d:prop/oc:fileid");
$xmlPart = $responseXmlObject->xpath("//d:prop/oc:fileid");
$parentContainerId = (string) $xmlPart[0];
$headers = [

View File

@@ -54,7 +54,6 @@ use Swaggest\JsonSchema\Exception\NumericException;
use Swaggest\JsonSchema\Exception\ObjectException;
use Swaggest\JsonSchema\Exception\StringException;
use Swaggest\JsonSchema\Exception\TypeException;
use Swaggest\JsonSchema\Exception\Error as JsonSchemaError;
require_once 'bootstrap.php';
@@ -998,11 +997,6 @@ class FeatureContext extends BehatVariablesContext {
string $username = ""
): void {
$this->response = $response;
//after a new response reset the response xml
$this->responseXml = [];
//after a new response reset the response xml object
$this->responseXmlObject = null;
// remember the user that received the response
$this->responseUser = $username;
}
@@ -2591,30 +2585,6 @@ class FeatureContext extends BehatVariablesContext {
return $this->acceptanceTestsDirLocation() . $this->temporaryStorageSubfolderName() . "/";
}
/**
* Parse list of config keys from the given XML response
*
* @param SimpleXMLElement $responseXml
*
* @return array
*/
public function parseConfigListFromResponseXml(SimpleXMLElement $responseXml): array {
$configkeyData = \json_decode(\json_encode($responseXml->data), true);
if (isset($configkeyData['element'])) {
$configkeyData = $configkeyData['element'];
} else {
// There are no keys for the app
return [];
}
if (isset($configkeyData[0])) {
$configkeyValues = $configkeyData;
} else {
// There is just 1 key for the app
$configkeyValues[0] = $configkeyData;
}
return $configkeyValues;
}
/**
* This will run before EVERY scenario.
* It will set the properties for this object.

View File

@@ -219,11 +219,11 @@ class FilesVersionsContext implements Context {
$fileId = $this->featureContext->getFileIdForPath($user, $path);
Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $path user $user not found (the file may not exist)");
$response = $this->listVersionFolder($user, $fileId, 1);
$responseXml = HttpRequestHelper::getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$xmlPart = $responseXml->xpath("//d:response/d:href");
$xmlPart = $responseXmlObject->xpath("//d:response/d:href");
//restoring the version only works with DAV path v2
$destinationUrl = $this->featureContext->getBaseUrl() . "/" .
WebDavHelper::getDavPath(WebDavHelper::DAV_VERSION_NEW, $user) . \trim($path, "/");
@@ -281,18 +281,18 @@ class FilesVersionsContext implements Context {
*/
public function assertFileVersionsCount(string $user, string $fileId, int $expectedCount):void {
$response = $this->listVersionFolder($user, $fileId, 1);
$responseXml = HttpRequestHelper::getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$actualCount = \count($responseXml->xpath("//d:prop/d:getetag")) - 1;
$actualCount = \count($responseXmlObject->xpath("//d:prop/d:getetag")) - 1;
if ($actualCount === -1) {
$actualCount = 0;
}
Assert::assertEquals(
$expectedCount,
$actualCount,
"Expected $expectedCount versions but found $actualCount in \n" . $responseXml->asXML()
"Expected $expectedCount versions but found $actualCount in \n" . $responseXmlObject->asXML()
);
}
@@ -356,11 +356,11 @@ class FilesVersionsContext implements Context {
$fileId = $this->featureContext->getFileIdForPath($user, $path);
Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $path user $user not found (the file may not exist)");
$response = $this->listVersionFolder($user, $fileId, 1, ['d:getcontentlength']);
$responseXml = HttpRequestHelper::getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$xmlPart = $responseXml->xpath("//d:prop/d:getcontentlength");
$xmlPart = $responseXmlObject->xpath("//d:prop/d:getcontentlength");
Assert::assertEquals(
$length,
(int) $xmlPart[$index],
@@ -422,8 +422,8 @@ class FilesVersionsContext implements Context {
if ($response->getStatusCode() === 403) {
return $response;
}
$responseXml = new SimpleXMLElement($response->getBody()->getContents());
$xmlPart = $responseXml->xpath("//d:response/d:href");
$responseXmlObject = new SimpleXMLElement($response->getBody()->getContents());
$xmlPart = $responseXmlObject->xpath("//d:response/d:href");
if (!isset($xmlPart[$index])) {
Assert::fail(
'could not find version of path "' . $path . '" with index "' . $index . '"'
@@ -519,11 +519,6 @@ class FilesVersionsContext implements Context {
null
);
$this->featureContext->setResponse($response);
$responseXml = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$this->featureContext->setResponseXmlObject($responseXml);
}
/**

View File

@@ -565,13 +565,11 @@ class OCSContext implements Context {
return (string) $jsonResponse->ocs->meta->statuscode;
}
// go to xml response when json response is null (it means not formatted and get status code)
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
if (isset($responseXml->meta[0], $responseXml->meta[0]->statuscode)) {
return (string) $responseXml->meta[0]->statuscode;
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
if (isset($responseXmlObject->meta[0], $responseXmlObject->meta[0]->statuscode)) {
return (string) $responseXmlObject->meta[0]->statuscode;
}
throw new Exception(
"No OCS status code found in response"
);
Assert::fail("No OCS status code found in response");
}
/**
@@ -583,13 +581,11 @@ class OCSContext implements Context {
* @throws Exception
*/
public function getOCSResponseData(ResponseInterface $response): SimpleXMLElement {
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
if (isset($responseXml->data)) {
return $responseXml->data;
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
if (isset($responseXmlObject->data)) {
return $responseXmlObject->data;
}
throw new Exception(
"No OCS data items found in responseXml"
);
Assert::fail("No OCS data items found in response");
}
/**

View File

@@ -1905,8 +1905,7 @@ trait Provisioning {
* @throws Exception
*/
public function getArrayOfUsersResponded(ResponseInterface $resp):array {
$listCheckedElements
= $this->getResponseXml($resp, __METHOD__)->data[0]->users[0]->element;
$listCheckedElements = HttpRequestHelper::getResponseXml($resp, __METHOD__)->data[0]->users[0]->element;
return \json_decode(\json_encode($listCheckedElements), true);
}
@@ -1920,7 +1919,7 @@ trait Provisioning {
*/
public function getArrayOfGroupsResponded(ResponseInterface $resp):array {
$listCheckedElements
= $this->getResponseXml($resp, __METHOD__)->data[0]->groups[0]->element;
= HttpRequestHelper::getResponseXml($resp, __METHOD__)->data[0]->groups[0]->element;
return \json_decode(\json_encode($listCheckedElements), true);
}
@@ -1933,8 +1932,7 @@ trait Provisioning {
* @throws Exception
*/
public function getArrayOfAppsResponded(ResponseInterface $resp):array {
$listCheckedElements
= $this->getResponseXml($resp, __METHOD__)->data[0]->apps[0]->element;
$listCheckedElements = HttpRequestHelper::getResponseXml($resp, __METHOD__)->data[0]->apps[0]->element;
return \json_decode(\json_encode($listCheckedElements), true);
}
@@ -1945,7 +1943,7 @@ trait Provisioning {
* @throws Exception
*/
public function theApiShouldNotReturnAnyData():void {
$responseData = $this->getResponseXml(null, __METHOD__)->data[0];
$responseData = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0];
Assert::assertEmpty(
$responseData,
"Response data is not empty but it should be empty"

View File

@@ -271,7 +271,7 @@ trait Sharing {
* @throws Exception
*/
public function getServerShareTimeFromLastResponse():int {
$stime = $this->getResponseXml(null, __METHOD__)->xpath("//stime");
$stime = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->xpath("//stime");
if ($stime) {
return (int) $stime[0];
}
@@ -921,13 +921,13 @@ trait Sharing {
if (($response->getStatusCode() === 200)
&& \in_array($this->ocsContext->getOCSResponseStatusCode($response), ['100', '200'])
) {
$xmlResponse = $this->getResponseXml($response);
if (isset($xmlResponse->data)) {
$shareData = $xmlResponse->data;
$responseXmlObject = HttpRequestHelper::getResponseXml($response);
if (isset($responseXmlObject->data)) {
$shareData = $responseXmlObject->data;
if ($shareType === 'public_link') {
$this->addToCreatedPublicShares($shareData);
} else {
$sharer = (string) $xmlResponse->data->uid_owner;
$sharer = (string) $responseXmlObject->data->uid_owner;
$this->addToCreatedUserGroupshares($sharer, $shareData);
}
}
@@ -981,7 +981,7 @@ trait Sharing {
*/
public function isFieldInResponse(string $field, ?string $contentExpected, bool $expectSuccess = true, ?SimpleXMLElement $data = null):bool {
if ($data === null) {
$data = $this->getResponseXml(null, __METHOD__)->data[0];
$data = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0];
}
Assert::assertIsObject($data, __METHOD__ . " data not found in response XML");
@@ -1053,7 +1053,7 @@ trait Sharing {
* @return void
*/
public function checkNoFilesFoldersInResponse():void {
$data = $this->getResponseXml(null, __METHOD__)->data[0];
$data = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0];
Assert::assertIsObject($data, __METHOD__ . " data not found in response XML");
Assert::assertCount(0, $data);
}
@@ -1067,7 +1067,7 @@ trait Sharing {
*/
public function checkCountFilesFoldersInResponse(string $count):void {
$count = (int) $count;
$data = $this->getResponseXml(null, __METHOD__)->data[0];
$data = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0];
Assert::assertIsObject($data, __METHOD__ . " data not found in response XML");
Assert::assertCount($count, $data, __METHOD__ . " the response does not contain $count entries");
}
@@ -2212,7 +2212,7 @@ trait Sharing {
* @return void
*/
public function responseShouldNotContainAnyShareIds(ResponseInterface $response):void {
$data = $this->getResponseXml($response, __METHOD__)->data[0];
$data = HttpRequestHelper::getResponseXml($response, __METHOD__)->data[0];
$fieldIsSet = false;
$receivedShareCount = 0;
@@ -2275,7 +2275,7 @@ trait Sharing {
* @return void
*/
public function checkingTheResponseEntriesCount(int $count):void {
$actualCount = \count($this->getResponseXml(null, __METHOD__)->data[0]);
$actualCount = \count(HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0]);
Assert::assertEquals(
$count,
$actualCount,
@@ -2305,7 +2305,7 @@ trait Sharing {
*/
public function checkTheFields(string $user, ?TableNode $body, ?ResponseInterface $response = null):void {
$response = $response ?? $this->getResponse();
$data = $this->getResponseXml($response, __METHOD__)->data[0];
$data = HttpRequestHelper::getResponseXml($response, __METHOD__)->data[0];
$this->verifyTableNodeColumnsCount($body, 2);
$bodyRows = $body->getRowsHash();
$userRelatedFieldNames = [
@@ -2359,7 +2359,7 @@ trait Sharing {
"space_id"
];
$response = $this->getResponseXml(null, __METHOD__);
$response = HttpRequestHelper::getResponseXml($this->response, __METHOD__);
$this->addToCreatedPublicShares($response->data);
foreach ($bodyRows as $field => $value) {
if (\in_array($field, $userRelatedFieldNames)) {
@@ -2440,7 +2440,7 @@ trait Sharing {
* @return void
*/
public function theFieldsOfTheLastResponseShouldBeEmpty():void {
$data = $this->getResponseXml(null, __METHOD__)->data[0];
$data = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0];
Assert::assertEquals(
\count($data->element),
0,
@@ -2455,8 +2455,8 @@ trait Sharing {
* @throws Exception
*/
public function getSharingAttributesFromLastResponse():string {
$responseXml = $this->getResponseXml(null, __METHOD__)->data[0];
$actualAttributesElement = $responseXml->xpath('//attributes');
$responseXmlObject = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0];
$actualAttributesElement = $responseXmlObject->xpath('//attributes');
if ($actualAttributesElement) {
$actualAttributes = (array) $actualAttributesElement[0];
@@ -2543,7 +2543,7 @@ trait Sharing {
public function userDownloadsFailWithMessage(string $fileName, string $user, PyStringNode $errorMessage):void {
$user = $this->getActualUsername($user);
$response = $this->downloadFileAsUserUsingPassword($user, $fileName);
$receivedErrorMessage = $this->getResponseXml($response, __METHOD__)->xpath('//s:message');
$receivedErrorMessage = HttpRequestHelper::getResponseXml($response, __METHOD__)->xpath('//s:message');
Assert::assertEquals(
$errorMessage,
(string) $receivedErrorMessage[0],
@@ -2600,7 +2600,7 @@ trait Sharing {
[],
$this->ocsApiVersion
);
return $this->getResponseXml($response, __METHOD__)->data->element;
return HttpRequestHelper::getResponseXml($response, __METHOD__)->data->element;
}
/**

View File

@@ -129,22 +129,6 @@ class SpacesContext implements Context {
$this->availableSpaces = $availableSpaces;
}
/**
* response content parsed from XML to an array
*
* @var array
*/
private array $responseXml = [];
/**
* @param array $responseXml
*
* @return void
*/
public function setResponseXml(array $responseXml): void {
$this->responseXml = $responseXml;
}
/**
* Get SpaceId by Name
*
@@ -362,8 +346,8 @@ class SpacesContext implements Context {
);
$this->featureContext->theHttpStatusCodeShouldBe(207, '', $response);
$xmlResponse = HttpRequestHelper::getResponseXml($response, __METHOD__);
$fileId = $xmlResponse->xpath("//d:response/d:propstat/d:prop/oc:fileid")[0];
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
$fileId = $responseXmlObject->xpath("//d:response/d:propstat/d:prop/oc:fileid")[0];
return $fileId->__toString();
}
@@ -2417,9 +2401,9 @@ class SpacesContext implements Context {
$body,
$this->featureContext->getStepLineRef()
);
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
$sharer = (string) $responseXml->data->uid_owner;
$this->featureContext->addToCreatedUserGroupshares($sharer, $responseXml->data);
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
$sharer = (string) $responseXmlObject->data->uid_owner;
$this->featureContext->addToCreatedUserGroupshares($sharer, $responseXmlObject->data);
return $response;
}
@@ -2580,8 +2564,8 @@ class SpacesContext implements Context {
$this->featureContext->getStepLineRef()
);
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
$this->featureContext->addToCreatedPublicShares($responseXml->data);
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
$this->featureContext->addToCreatedPublicShares($responseXmlObject->data);
return $response;
}
@@ -3565,8 +3549,7 @@ class SpacesContext implements Context {
$this->featureContext->getStepLineRef()
);
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
$this->featureContext->addToCreatedPublicShares($responseXml->data);
$this->featureContext->addToCreatedPublicShares(HttpRequestHelper::getResponseXml($response, __METHOD__)->data);
return $response;
}
@@ -3830,7 +3813,7 @@ class SpacesContext implements Context {
*/
public function searchResultShouldContainSpace(string $user, string $spaceName): void {
// get a response after a Report request (called in the core)
$responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->xpath("//d:response/d:href")), true, 512, JSON_THROW_ON_ERROR);
$responseArray = json_decode(json_encode(HttpRequestHelper::getResponseXml($this->featureContext->getResponse())->xpath("//d:response/d:href")), true, 512, JSON_THROW_ON_ERROR);
Assert::assertNotEmpty($responseArray, "search result is empty");
// for mountpoint, id looks a little different than for project space
@@ -4017,16 +4000,16 @@ class SpacesContext implements Context {
}
/**
* @param string $resource // can be resource name, space id or file id
* @param array $properties // ["key" => "value"]
* @param string $resource // can be resource name, space id or file id
* @param array $properties // ["key" => "value"]
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function theXMLResponseShouldContain(string $resource, array $properties): void {
$xmlResponse = HttpRequestHelper::getResponseXml($response, __METHOD__);
$hrefs = array_map(fn ($href) => $href->__toString(), $xmlResponse->xpath("//d:response/d:href"));
$responseXmlObject = HttpRequestHelper::getResponseXml($this->featureContext->getResponse(), __METHOD__);
$hrefs = array_map(fn ($href) => $href->__toString(), $responseXmlObject->xpath("//d:response/d:href"));
$currentHref = '';
foreach ($hrefs as $href) {
@@ -4062,14 +4045,14 @@ class SpacesContext implements Context {
// check every xpath
foreach ($xpaths as $key => $path) {
$xpath = "{$path}{$itemToFind}";
$foundXmlItem = $xmlResponse->xpath($xpath);
$foundXmlItem = $responseXmlObject->xpath($xpath);
$xpaths[$key] = $xpath;
if (\count($foundXmlItem)) {
break;
}
}
} else {
$foundXmlItem = $xmlResponse->xpath($xpath);
$foundXmlItem = $responseXmlObject->xpath($xpath);
$xpaths[] = $xpath;
}
@@ -4079,7 +4062,7 @@ class SpacesContext implements Context {
"Using xpaths:\n\t- " . \join("\n\t- ", $xpaths)
. "\n"
. "Could not find '<$itemToFind>' element in the XML response\n\t"
. "'" . \trim($xmlResponse->asXML()) . "'"
. "'" . \trim($responseXmlObject->asXML()) . "'"
);
$actualValue = $foundXmlItem[0]->__toString();
@@ -4144,8 +4127,8 @@ class SpacesContext implements Context {
* @throws GuzzleException
*/
public function asUserTheKeyFromPropfindResponseShouldMatchWithSharedwithmeDriveitemidOfShare(string $user, string $key, string $resource): void {
$xmlResponse = HttpRequestHelper::getResponseXml($response, __METHOD__);
$fileId = $xmlResponse->xpath("//oc:name[text()='$resource']/preceding-sibling::$key")[0]->__toString();
$responseXmlObject = HttpRequestHelper::getResponseXml($this->featureContext->getResponse(), __METHOD__);
$fileId = $responseXmlObject->xpath("//oc:name[text()='$resource']/preceding-sibling::$key")[0]->__toString();
$jsonResponse = GraphHelper::getSharesSharedWithMe(
$this->featureContext->getBaseUrl(),
@@ -4172,25 +4155,30 @@ class SpacesContext implements Context {
* @param string $resource
*
* @return void
* @throws GuzzleException|JsonException
* @throws GuzzleException
* @throws Exception
*/
public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $resource) {
$token = ($this->featureContext->isUsingSharingNG()) ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() : $this->featureContext->getLastCreatedPublicShareToken();
$response = $this->featureContext->listFolderAndReturnResponseXml(
$token,
$resource,
'0',
['oc:fileid'],
"public-files"
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->featureContext->listFolder(
$token,
$resource,
'0',
['oc:fileid'],
null,
"public-files"
)
);
$resourceId = json_decode(json_encode($response->xpath("//d:response/d:propstat/d:prop/oc:fileid")), true, 512, JSON_THROW_ON_ERROR);
$resourceId = $responseXmlObject->xpath("//d:response/d:propstat/d:prop/oc:fileid");
$queryString = 'public-token=' . $token . '&id=' . $resourceId[0][0];
$this->featureContext->setResponse(
HttpRequestHelper::get(
$this->archiverContext->getArchiverUrl($queryString),
$this->featureContext->getStepLineRef(),
'',
'',
''
)
);
}
@@ -4211,11 +4199,9 @@ class SpacesContext implements Context {
$quotaAmount,
"Expected relative quota amount to be $quotaAmount but found to be $data->quota->relative"
);
} else {
throw new Exception(
"No relative quota amount found in responseXml"
);
return;
}
Assert::fail("No relative quota amount found in response");
}
/**

View File

@@ -85,12 +85,12 @@ class TrashbinContext implements Context {
/**
* Get files list from the response from trashbin api
*
* @param SimpleXMLElement|null $responseXml
* @param SimpleXMLElement|null $responseXmlObject
*
* @return array
*/
public function getTrashbinContentFromResponseXml(?SimpleXMLElement $responseXml): array {
$xmlElements = $responseXml->xpath('//d:response');
public function getTrashbinContentFromResponseXml(?SimpleXMLElement $responseXmlObject): array {
$xmlElements = $responseXmlObject->xpath('//d:response');
$files = \array_map(
static function (SimpleXMLElement $element) {
$href = $element->xpath('./d:href')[0];
@@ -178,13 +178,13 @@ class TrashbinContext implements Context {
$davPathVersion
);
$this->featureContext->setResponse($response);
$responseXml = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$this->featureContext->setResponseXmlObject($responseXml);
$files = $this->getTrashbinContentFromResponseXml($responseXml);
$files = $this->getTrashbinContentFromResponseXml(
HttpRequestHelper::getResponseXml(
$response,
__METHOD__
)
);
// filter root element
$files = \array_filter(
$files,
@@ -253,13 +253,13 @@ class TrashbinContext implements Context {
$respBody = $response->getBody()->getContents();
Assert::assertEquals("207", $statusCode, "Expected status code to be '207' but got $statusCode \nResponse\n$respBody");
$responseXml = HttpRequestHelper::getResponseXml(
$response,
__METHOD__ . " $collectionPath"
$files = $this->getTrashbinContentFromResponseXml(
HttpRequestHelper::getResponseXml(
$response,
__METHOD__ . " $collectionPath"
)
);
$files = $this->getTrashbinContentFromResponseXml($responseXml);
$suffixPath = $user;
if ($davPathVersion === WebDavHelper::DAV_VERSION_SPACES) {
$suffixPath = WebDavHelper::getPersonalSpaceIdForUser(
@@ -345,8 +345,7 @@ class TrashbinContext implements Context {
*/
public function theTrashbinDavResponseShouldNotContainTheseNodes(TableNode $table):void {
$this->featureContext->verifyTableNodeColumns($table, ['name']);
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
$files = $this->getTrashbinContentFromResponseXml($responseXml);
$files = $this->getTrashbinContentFromResponseXml(HttpRequestHelper::getResponseXml($this->featureContext->getResponse(), __METHOD__));
foreach ($table->getHash() as $row) {
$path = trim((string)$row['name'], "/");
@@ -368,9 +367,8 @@ class TrashbinContext implements Context {
*/
public function theTrashbinDavResponseShouldContainTheseNodes(TableNode $table):void {
$this->featureContext->verifyTableNodeColumns($table, ['name']);
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
$files = $this->getTrashbinContentFromResponseXml($responseXml);
$files = $this->getTrashbinContentFromResponseXml(HttpRequestHelper::getResponseXml($this->featureContext->getResponse(), __METHOD__));
foreach ($table->getHash() as $row) {
$path = trim($row['name'], "/");
@@ -484,7 +482,7 @@ class TrashbinContext implements Context {
* @throws Exception
*/
public function theLastWebdavResponseShouldNotContainFollowingElements(TableNode $elements):void {
$files = $this->getTrashbinContentFromResponseXml($this->featureContext->getResponseXml());
$files = $this->getTrashbinContentFromResponseXml(HttpRequestHelper::getResponseXml($this->featureContext->getResponse()));
// 'user' is also allowed in the table even though it is not used anywhere
// This for better readability in feature files
@@ -869,44 +867,29 @@ class TrashbinContext implements Context {
* @param $user string
* @param $originalPath string
*
* @return ResponseInterface
* @return void
* @throws Exception
*/
public function userRestoresResourceWithOriginalPathWithoutSpecifyingDestinationUsingTrashbinApi(string $user, string $originalPath):ResponseInterface {
$asUser = $asUser ?? $user;
public function userRestoresResourceWithOriginalPathWithoutSpecifyingDestinationUsingTrashbinApi(string $user, string $originalPath):void {
$listing = $this->listTrashbinFolder($user);
$originalPath = \trim($originalPath, '/');
foreach ($listing as $entry) {
if ($entry['original-location'] === $originalPath) {
$trashItemHRef = $this->convertTrashbinHref($entry['href']);
$response = $this->featureContext->makeDavRequest(
$asUser,
'MOVE',
$trashItemHRef,
[],
null,
null,
'trash-bin'
$this->featureContext->setResponse(
$this->featureContext->makeDavRequest(
$user,
'MOVE',
$trashItemHRef,
[],
null,
null,
'trash-bin'
)
);
$this->featureContext->setResponse($response);
// this gives empty response in ocis
try {
$responseXml = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$this->featureContext->setResponseXmlObject($responseXml);
} catch (Exception $e) {
}
return $response;
}
}
throw new \Exception(
__METHOD__
. " cannot restore from trashbin because no element was found for user $user at original path $originalPath"
);
}
/**
@@ -1150,7 +1133,7 @@ class TrashbinContext implements Context {
*/
public function theDeletedFileFolderShouldHaveCorrectDeletionMtimeInTheResponse(string $resource):void {
$files = $this->getTrashbinContentFromResponseXml(
$this->featureContext->getResponseXml()
HttpRequestHelper::getResponseXml($this->featureContext->getResponse())
);
$found = false;

View File

@@ -53,11 +53,6 @@ trait WebDav {
private ?int $lastUploadDeleteTime = null;
/**
* response content parsed from XML to an array
*/
private array $responseXml = [];
/**
* add resource created by admin in an array
* This array is used while cleaning up the resource created by admin during test run
@@ -140,13 +135,6 @@ trait WebDav {
return $this->lastUploadDeleteTime;
}
/**
* @return void
*/
public function clearResponseXmlObject():void {
$this->responseXmlObject = null;
}
/**
* @param string $fileID
*
@@ -169,7 +157,7 @@ trait WebDav {
* @return string the etag or an empty string if the getetag property does not exist
*/
public function getEtagFromResponseXmlObject(?SimpleXMLElement $xmlObject = null): string {
$xmlObject = $xmlObject ?? $this->getResponseXml();
$xmlObject = $xmlObject ?? HttpRequestHelper::getResponseXml($this->getResponse());
$xmlPart = $xmlObject->xpath("//d:prop/d:getetag");
if (!\is_array($xmlPart) || (\count($xmlPart) === 0)) {
return '';
@@ -192,15 +180,6 @@ trait WebDav {
}
}
/**
* @param array $responseXml
*
* @return void
*/
public function setResponseXml(array $responseXml):void {
$this->responseXml = $responseXml;
}
/**
* @Given /^using (old|new|spaces) DAV path$/
*
@@ -435,15 +414,8 @@ trait WebDav {
* @throws Exception
*/
public function theNumberOfVersionsShouldBe(int $number):void {
$resXml = $this->getResponseXml();
if ($resXml === null) {
$resXml = HttpRequestHelper::getResponseXml(
$this->getResponse(),
__METHOD__
);
$this->setResponseXmlObject($resXml);
}
$xmlPart = $resXml->xpath("//d:getlastmodified");
$responseXmlObject = HttpRequestHelper::getResponseXml($this->getResponse(), __METHOD__);
$xmlPart = $responseXmlObject->xpath("//d:getlastmodified");
$actualNumber = \count($xmlPart);
Assert::assertEquals(
$number,
@@ -461,14 +433,8 @@ trait WebDav {
* @throws Exception
*/
public function theNumberOfEtagElementInTheResponseShouldBe(int $number):void {
$resXml = $this->getResponseXml();
if ($resXml === null) {
$resXml = HttpRequestHelper::getResponseXml(
$this->getResponse(),
__METHOD__
);
}
$xmlPart = $resXml->xpath("//d:getetag");
$responseXmlObject = HttpRequestHelper::getResponseXml($this->getResponse());
$xmlPart = $responseXmlObject->xpath("//d:getetag");
$actualNumber = \count($xmlPart);
Assert::assertEquals(
$number,
@@ -965,8 +931,7 @@ trait WebDav {
* @return void
*/
public function contentOfFileForUserShouldBe(string $fileName, string $user, string $content):void {
$user = $this->getActualUsername($user);
$response = $this->downloadFileAsUserUsingPassword($user, $fileName);
$response = $this->downloadFileAsUserUsingPassword($this->getActualUsername($user), $fileName);
$actualStatus = $response->getStatusCode();
if ($actualStatus !== 200) {
throw new Exception(
@@ -1150,11 +1115,11 @@ trait WebDav {
* @throws Exception
*/
public function theSizeOfTheFileShouldBe(string $size):void {
$responseXml = HttpRequestHelper::getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->response,
__METHOD__
);
$xmlPart = $responseXml->xpath("//d:prop/d:getcontentlength");
$xmlPart = $responseXmlObject->xpath("//d:prop/d:getcontentlength");
$actualSize = (string) $xmlPart[0];
Assert::assertEquals(
$size,
@@ -1268,7 +1233,7 @@ trait WebDav {
$statusCode = $response->getStatusCode();
if ($statusCode < 400 || $statusCode > 499) {
try {
$responseXml = HttpRequestHelper::getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
@@ -1278,10 +1243,10 @@ trait WebDav {
);
}
Assert::assertTrue(
$this->isEtagValid($this->getEtagFromResponseXmlObject($responseXml)),
$this->isEtagValid($this->getEtagFromResponseXmlObject($responseXmlObject)),
"$entry '$path' should not exist. But API returned $statusCode without an etag in the body"
);
$isCollection = $responseXml->xpath("//d:prop/d:resourcetype/d:collection");
$isCollection = $responseXmlObject->xpath("//d:prop/d:resourcetype/d:collection");
if (\count($isCollection) === 0) {
$actualResourceType = "file";
} else {
@@ -1345,6 +1310,7 @@ trait WebDav {
* @param string|null $type
*
* @return void
* @throws Exception
*/
public function checkFileOrFolderExistsForUser(
string $user,
@@ -1354,18 +1320,22 @@ trait WebDav {
):void {
$user = $this->getActualUsername($user);
$path = $this->substituteInLineCodes($path);
$responseXml = $this->listFolderAndReturnResponseXml(
$user,
$path,
'0',
null,
$type
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->listFolder(
$user,
$path,
'0',
null,
null,
$type
)
);
Assert::assertTrue(
$this->isEtagValid($this->getEtagFromResponseXmlObject($responseXml)),
$this->isEtagValid($this->getEtagFromResponseXmlObject($responseXmlObject)),
"$entry '$path' expected to exist for user $user but not found"
);
$isCollection = $responseXml->xpath("//d:prop/d:resourcetype/d:collection");
$isCollection = $responseXmlObject->xpath("//d:prop/d:resourcetype/d:collection");
if ($entry === "folder") {
Assert::assertEquals(\count($isCollection), 1, "Unexpectedly, `$path` is not a folder");
} elseif ($entry === "file") {
@@ -1454,37 +1424,6 @@ trait WebDav {
);
}
/**
*
* @param string $user
* @param string $path
* @param string $folderDepth requires 1 to see elements without children
* @param array|null $properties
* @param string $type
*
* @return SimpleXMLElement
* @throws Exception
*/
public function listFolderAndReturnResponseXml(
string $user,
string $path,
string $folderDepth,
?array $properties = null,
string $type = "files"
):SimpleXMLElement {
return HttpRequestHelper::getResponseXml(
$this->listFolder(
$user,
$path,
$folderDepth,
$properties,
null,
$type
),
__METHOD__
);
}
/**
* @Then /^user "([^"]*)" should (not|)\s?see the following elements$/
*
@@ -1525,10 +1464,12 @@ trait WebDav {
if ($this->davPropfindDepthInfinityIsEnabled()) {
// get a full "infinite" list of the user's root folder in one request
// and process that to check the elements (resources)
$responseXmlObject = $this->listFolderAndReturnResponseXml(
$user,
"/",
"infinity"
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->listFolder(
$user,
"/",
"infinity"
)
);
foreach ($elementsSimplified as $expectedElement) {
// Allow the table of expected elements to have entries that do
@@ -1566,10 +1507,12 @@ trait WebDav {
// /some-folder%20with%20spaces/sub-folder
// So we need both $elementToRequest and $expectedElement
$expectedElement = $this->encodePath($elementToRequest);
$responseXmlObject = $this->listFolderAndReturnResponseXml(
$user,
$elementToRequest,
"1"
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->listFolder(
$user,
$elementToRequest,
'1'
)
);
$webdavPath = "/" . $this->getFullDavFilesPath($user) . $expectedElement;
@@ -1650,11 +1593,8 @@ trait WebDav {
):void {
$response = $this->uploadFile($user, $source, $destination);
$this->setResponse($response);
$this->setResponseXml(
HttpRequestHelper::parseResponseAsXml($response)
);
$this->pushToLastHttpStatusCodesArray(
(string) $this->getResponse()->getStatusCode()
(string) $response->getStatusCode()
);
}
@@ -1701,7 +1641,6 @@ trait WebDav {
$chunkingVersion = null;
}
try {
$this->responseXml = [];
$this->pauseUploadDelete();
$this->response = UploadHelper::upload(
$this->getBaseUrl(),
@@ -3562,6 +3501,7 @@ trait WebDav {
* @param boolean $checkEachDelete
*
* @return void
* @throws Exception
*/
public function deleteEverythingInFolder(
string $user,
@@ -3569,10 +3509,12 @@ trait WebDav {
bool $checkEachDelete = false
):void {
$user = $this->getActualUsername($user);
$responseXmlObject = $this->listFolderAndReturnResponseXml(
$user,
$folder,
'1'
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->listFolder(
$user,
$folder,
'1'
)
);
$elementList = $responseXmlObject->xpath("//d:response/d:href");
if (\is_array($elementList) && \count($elementList)) {
@@ -3944,9 +3886,8 @@ trait WebDav {
*/
public function theDownloadedPreviewContentShouldMatchWithFixturesPreviewContentFor(string $filename):void {
$expectedPreview = \file_get_contents(__DIR__ . "/../fixtures/" . $filename);
$response = $response ?? $this->getResponse();
$response->getBody()->rewind();
$responseBodyContent = $response->getBody()->getContents();
$this->getResponse()->getBody()->rewind();
$responseBodyContent = $this->getResponse()->getBody()->getContents();
Assert::assertEquals($expectedPreview, $responseBodyContent);
}
@@ -4072,11 +4013,11 @@ trait WebDav {
* @throws Exception
*/
public function theDavElementShouldBe(string $element, string $message):void {
$resXmlArray = HttpRequestHelper::parseResponseAsXml($this->getResponse());
$responseXmlArray = HttpRequestHelper::parseResponseAsXml($this->getResponse());
WebDavAssert::assertDavResponseElementIs(
$element,
$message,
$resXmlArray,
$responseXmlArray,
__METHOD__
);
}
@@ -4211,23 +4152,18 @@ trait WebDav {
* @return void
*/
public function checkIFResponseContainsNumberEntries(int $numFiles):void {
//if we are using that step the second time in a scenario e.g. 'But ... should not'
//then don't parse the result again, because the result in a ResponseInterface
if (empty($this->responseXml)) {
$this->setResponseXml(
HttpRequestHelper::parseResponseAsXml($this->response)
);
}
$responseXmlArray = HttpRequestHelper::parseResponseAsXml($this->response);
Assert::assertIsArray(
$this->responseXml,
__METHOD__ . " responseXml is not an array"
$responseXmlArray,
__METHOD__ . " is not an array"
);
Assert::assertArrayHasKey(
"value",
$this->responseXml,
__METHOD__ . " responseXml does not have key 'value'"
$responseXmlArray,
__METHOD__ . " does not have key 'value'"
);
$multistatusResults = $this->responseXml["value"];
$multistatusResults = $responseXmlArray["value"];
if ($multistatusResults === null) {
$multistatusResults = [];
}
@@ -4333,7 +4269,6 @@ trait WebDav {
$depth
);
$this->setResponse($response);
$this->setResponseXml(HttpRequestHelper::parseResponseAsXml($this->response));
}
/**
@@ -4420,16 +4355,16 @@ trait WebDav {
*/
public function thePublicListsTheResourcesInTheLastCreatedPublicLinkWithDepthUsingTheWebdavApi(string $depth):void {
$token = ($this->isUsingSharingNG()) ? $this->shareNgGetLastCreatedLinkShareToken() : $this->getLastCreatedPublicShareToken();
$response = $this->listFolder(
$token,
'/',
$depth,
null,
null,
"public-files"
$this->setResponse(
$this->listFolder(
$token,
'/',
$depth,
null,
null,
"public-files"
)
);
$this->setResponse($response);
$this->setResponseXml(HttpRequestHelper::parseResponseAsXml($this->response));
}
/**
@@ -4438,7 +4373,7 @@ trait WebDav {
* @return array
*/
public function findEntryFromReportResponse(?string $user):array {
$responseXmlObj = $this->getResponseXml();
$responseXmlObj = HttpRequestHelper::getResponseXml($this->getResponse());
$responseResources = [];
$hrefs = $responseXmlObj->xpath('//d:href');
foreach ($hrefs as $href) {
@@ -4479,28 +4414,22 @@ trait WebDav {
public function getMultiStatusResultFromPropfindResult(
?string $user = null
):array {
//if we are using that step the second time in a scenario e.g. 'But ... should not'
//then don't parse the result again, because the result in a ResponseInterface
if (empty($this->responseXml)) {
$this->setResponseXml(
HttpRequestHelper::parseResponseAsXml($this->response)
);
}
Assert::assertNotEmpty($this->responseXml, __METHOD__ . ' Response is empty');
$responseXmlArray = HttpRequestHelper::parseResponseAsXml($this->response);
Assert::assertNotEmpty($responseXmlArray, __METHOD__ . ' Response is empty');
if ($user === null) {
$user = $this->getCurrentUser();
}
Assert::assertIsArray(
$this->responseXml,
__METHOD__ . " responseXml for user $user is not an array"
$responseXmlArray,
__METHOD__ . " response for user $user is not an array"
);
Assert::assertArrayHasKey(
"value",
$this->responseXml,
__METHOD__ . " responseXml for user $user does not have key 'value'"
$responseXmlArray,
__METHOD__ . " response for user $user does not have key 'value'"
);
$multistatus = $this->responseXml["value"];
$multistatus = $responseXmlArray["value"];
if ($multistatus == null) {
$multistatus = [];
}
@@ -4564,7 +4493,9 @@ trait WebDav {
default:
throw new Exception("error");
}
$multistatusResults = $this->getMultiStatusResultFromPropfindResult($user);
$results = [];
foreach ($multistatusResults as $multistatusResult) {
$entryPath = $multistatusResult['value'][0]['value'];
@@ -4618,7 +4549,8 @@ trait WebDav {
}
$hrefRegex = "/^" . $hrefRegex . "/";
$searchResults = $this->getResponseXml()->xpath("//d:multistatus/d:response");
$searchResults = HttpRequestHelper::getResponseXml($this->getResponse())->xpath("//d:multistatus/d:response");
$results = [];
foreach ($searchResults as $item) {
$href = (string)$item->xpath("d:href")[0];
@@ -4698,17 +4630,13 @@ trait WebDav {
*/
public function checkAuthorOfAVersionOfFile(string $index, string $expectedUsername):void {
$expectedUserDisplayName = $this->getUserDisplayName($expectedUsername);
$resXml = $this->getResponseXml();
if ($resXml === null) {
$resXml = HttpRequestHelper::getResponseXml(
$this->getResponse(),
__METHOD__
);
$this->setResponseXmlObject($resXml);
}
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->getResponse(),
__METHOD__
);
// the username should be in oc:meta-version-edited-by
$xmlPart = $resXml->xpath("//oc:meta-version-edited-by");
$xmlPart = $responseXmlObject->xpath("//oc:meta-version-edited-by");
$authors = [];
foreach ($xmlPart as $idx => $author) {
// The first element is the root path element which is not a version
@@ -4730,7 +4658,7 @@ trait WebDav {
);
// the user's display name should be in oc:meta-version-edited-by-name
$xmlPart = $resXml->xpath("//oc:meta-version-edited-by-name");
$xmlPart = $responseXmlObject->xpath("//oc:meta-version-edited-by-name");
$displaynames = [];
foreach ($xmlPart as $idx => $displayname) {
// The first element is the root path element which is not a version

View File

@@ -123,8 +123,8 @@ class WebDavLockingContext implements Context {
);
}
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
$xmlPart = $responseXml->xpath("//d:locktoken/d:href");
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
$xmlPart = $responseXmlObject->xpath("//d:locktoken/d:href");
if (isset($xmlPart[0])) {
$this->tokenOfLastLock[$user][$file] = (string) $xmlPart[0];
} else {
@@ -556,8 +556,8 @@ class WebDavLockingContext implements Context {
$body,
$this->featureContext->getDavPathVersion()
);
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
$xmlPart = $responseXml->xpath("//d:response//d:lockdiscovery/d:activelock");
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
$xmlPart = $responseXmlObject->xpath("//d:response//d:lockdiscovery/d:activelock");
if (\is_array($xmlPart)) {
return \count($xmlPart);
} else {
@@ -904,8 +904,8 @@ class WebDavLockingContext implements Context {
public function numberOfLockShouldBeReportedInProjectSpace(int $count, string $file, string $spaceName, string $user) {
$response = $this->spacesContext->sendPropfindRequestToSpace($user, $spaceName, $file, null, '0');
$this->featureContext->theHTTPStatusCodeShouldBe(207, "", $response);
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
$xmlPart = $responseXml->xpath("//d:response//d:lockdiscovery/d:activelock");
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
$xmlPart = $responseXmlObject->xpath("//d:response//d:lockdiscovery/d:activelock");
if (\is_array($xmlPart)) {
$lockCount = \count($xmlPart);
} else {

View File

@@ -443,7 +443,7 @@ class WebDavPropertiesContext implements Context {
*/
public function theResponseShouldContainCustomPropertyWithValue(string $propertyName, string $propertyValue): void {
$propertyValue = \str_replace('\"', '"', $propertyValue);
$responseXmlObject = $this->featureContext->getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->featureContext->getResponse(),
__METHOD__
);
@@ -480,7 +480,7 @@ class WebDavPropertiesContext implements Context {
):void {
// let's unescape quotes first
$propertyValue = \str_replace('\"', '"', $propertyValue);
$responseXmlObject = $this->featureContext->getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->featureContext->getResponse(),
__METHOD__
);
@@ -519,7 +519,7 @@ class WebDavPropertiesContext implements Context {
string $property,
string $childProperty
):void {
$xmlPart = $this->featureContext->getResponseXml()->xpath(
$xmlPart = HttpRequestHelper::getResponseXml($this->featureContext->getResponse())->xpath(
"//d:prop/$property/$childProperty"
);
Assert::assertTrue(
@@ -761,11 +761,11 @@ class WebDavPropertiesContext implements Context {
* @return void
*/
public function assertValueOfItemInResponseAboutUserIs(string $xpath, ?string $user, string $expectedValue):void {
$resXml = $this->featureContext->getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->featureContext->getResponse(),
__METHOD__
);
$value = $this->getXmlItemByXpath($resXml, $xpath);
$value = $this->getXmlItemByXpath($responseXmlObject, $xpath);
$user = $this->featureContext->getActualUsername($user);
$expectedValue = $this->featureContext->substituteInLineCodes(
$expectedValue,
@@ -798,11 +798,11 @@ class WebDavPropertiesContext implements Context {
if (!$expectedValue2) {
$expectedValue2 = $expectedValue1;
}
$resXml = $this->featureContext->getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->featureContext->getResponse(),
__METHOD__
);
$value = $this->getXmlItemByXpath($resXml, $xpath);
$value = $this->getXmlItemByXpath($responseXmlObject, $xpath);
$user = $this->featureContext->getActualUsername($user);
$expectedValue1 = $this->featureContext->substituteInLineCodes(
$expectedValue1,
@@ -824,16 +824,16 @@ class WebDavPropertiesContext implements Context {
}
/**
* @param SimpleXMLElement $xmlResponse
* @param SimpleXMLElement $responseXmlObject
* @param string $xpath
*
* @return string
*/
public function getXmlItemByXpath(
SimpleXMLElement $xmlResponse,
SimpleXMLElement $responseXmlObject,
string $xpath
): string {
$xmlPart = $xmlResponse->xpath($xpath);
$xmlPart = $responseXmlObject->xpath($xpath);
Assert::assertTrue(
isset($xmlPart[0]),
"Cannot find item with xpath \"$xpath\""
@@ -852,7 +852,7 @@ class WebDavPropertiesContext implements Context {
*/
public function assertValueOfItemInResponseRegExp(string $xpath, string $pattern):void {
$this->assertXpathValueMatchesPattern(
$this->featureContext->getResponseXml(),
HttpRequestHelper::getResponseXml($this->featureContext->getResponse()),
$xpath,
$pattern
);
@@ -889,7 +889,7 @@ class WebDavPropertiesContext implements Context {
* @throws Exception
*/
public function assertEntryWithHrefMatchingRegExpInResponseToUser(string $expectedHref, string $user):void {
$resXml = $this->featureContext->getResponseXml(
$responseXmlObject = HttpRequestHelper::getResponseXml(
$this->featureContext->getResponse(),
__METHOD__
);
@@ -906,7 +906,7 @@ class WebDavPropertiesContext implements Context {
while (true) {
$index++;
$xpath = "//d:response[$index]/d:href";
$xmlPart = $resXml->xpath($xpath);
$xmlPart = $responseXmlObject->xpath($xpath);
// If we have run out of entries in the response, then fail the test
Assert::assertTrue(
isset($xmlPart[0]),
@@ -939,16 +939,16 @@ class WebDavPropertiesContext implements Context {
}
/**
* @param SimpleXMLElement $responseXml
* @param SimpleXMLElement $responseXmlObject
* @param string $xpath
* @param string $pattern
* @param string|null $user
*
* @return void
* @throws Exception
* @throws JsonException
*/
public function assertXpathValueMatchesPattern(SimpleXMLElement $responseXml, string $xpath, string $pattern, ?string $user = null): void {
$xmlPart = $responseXml->xpath($xpath);
public function assertXpathValueMatchesPattern(SimpleXMLElement $responseXmlObject, string $xpath, string $pattern, ?string $user = null): void {
$xmlPart = $responseXmlObject->xpath($xpath);
Assert::assertTrue(
isset($xmlPart[0]),
"Cannot find item with xpath \"$xpath\""
@@ -985,22 +985,6 @@ class WebDavPropertiesContext implements Context {
);
}
/**
* @Then the value of the item :xpath in the response to user :user should match :value
*
* @param string $xpath
* @param string|null $user
* @param string $pattern
* @param SimpleXMLElement|null $responseXml
*
* @return void
* @throws Exception
*/
public function theValueOfItemInResponseToUserShouldMatch(string $xpath, ?string $user, string $pattern, ?SimpleXMLElement $responseXml = null):void {
$resXml = $this->featureContext->getResponseXml();
$this->assertXpathValueMatchesPattern($resXml, $xpath, $pattern, $user);
}
/**
* @Then /^as user "([^"]*)" the lock discovery property "([^"]*)" of the (?:file|folder|entry) "([^"]*)" should match "([^"]*)"$/
*
@@ -1038,7 +1022,7 @@ class WebDavPropertiesContext implements Context {
* @throws Exception
*/
public function assertItemInResponseDoesNotExist(string $xpath):void {
$xmlPart = $this->featureContext->getResponseXml()->xpath($xpath);
$xmlPart = HttpRequestHelper::getResponseXml($this->featureContext->getResponse())->xpath($xpath);
Assert::assertFalse(
isset($xmlPart[0]),
"Found item with xpath \"$xpath\" but it should not exist"
@@ -1116,7 +1100,7 @@ class WebDavPropertiesContext implements Context {
string $key,
string $regex
):void {
$xmlPart = $this->featureContext->getResponseXml()->xpath(
$xmlPart = HttpRequestHelper::getResponseXml($this->featureContext->getResponse())->xpath(
"//d:prop/$key"
);
Assert::assertTrue(
@@ -1142,7 +1126,7 @@ class WebDavPropertiesContext implements Context {
public function theResponseShouldContainAShareTypesPropertyWith(TableNode $table):void {
$this->featureContext->verifyTableNodeColumnsCount($table, 1);
WebdavTest::assertResponseContainsShareTypes(
$this->featureContext->getResponseXml(),
HttpRequestHelper::getResponseXml($this->featureContext->getResponse()),
$table->getRows()
);
}
@@ -1156,7 +1140,7 @@ class WebDavPropertiesContext implements Context {
* @throws Exception
*/
public function theResponseShouldContainAnEmptyProperty(string $property):void {
$xmlPart = $this->featureContext->getResponseXml()->xpath(
$xmlPart = HttpRequestHelper::getResponseXml($this->featureContext->getResponse())->xpath(
"//d:prop/$property"
);
Assert::assertCount(
@@ -1304,9 +1288,8 @@ class WebDavPropertiesContext implements Context {
* @throws Exception
*/
public function theResponseShouldHavePropertyWithValue(string $username, TableNode $expectedPropTable):void {
$username = $this->featureContext->getActualUsername($username);
$this->featureContext->verifyTableNodeColumns($expectedPropTable, ['resource', 'propertyName', 'propertyValue']);
$responseXmlObject = $this->featureContext->getResponseXml();
$responseXmlObject = HttpRequestHelper::getResponseXml($this->featureContext->getResponse());
$href = (string)$responseXmlObject->xpath("//d:href")[0];
$hrefBase = $this->parseBaseDavPathFromXMLHref($href);