Skip to content

Commit e83b63f

Browse files
rename variable name and remove unwanted function
1 parent e76ba90 commit e83b63f

File tree

13 files changed

+238
-398
lines changed

13 files changed

+238
-398
lines changed

tests/acceptance/TestHelpers/Asserts/WebDav.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@ class WebDav extends Assert {
3232
*
3333
* @param string|null $element exception|message|reason
3434
* @param string|null $expectedValue
35-
* @param array|null $responseXml
35+
* @param array|null $responseXmlArray
3636
* @param string|null $extraErrorText
3737
*
3838
* @return void
3939
*/
4040
public static function assertDavResponseElementIs(
4141
?string $element,
4242
?string $expectedValue,
43-
?array $responseXml,
43+
?array $responseXmlArray,
4444
?string $extraErrorText = ''
4545
):void {
4646
if ($extraErrorText !== '') {
4747
$extraErrorText = $extraErrorText . " ";
4848
}
4949
self::assertArrayHasKey(
5050
'value',
51-
$responseXml,
51+
$responseXmlArray,
5252
$extraErrorText . "responseXml does not have key 'value'"
5353
);
5454
if ($element === "exception") {
55-
$result = $responseXml['value'][0]['value'];
55+
$result = $responseXmlArray['value'][0]['value'];
5656
} elseif ($element === "message") {
57-
$result = $responseXml['value'][1]['value'];
57+
$result = $responseXmlArray['value'][1]['value'];
5858
} elseif ($element === "reason") {
59-
$result = $responseXml['value'][3]['value'];
59+
$result = $responseXmlArray['value'][3]['value'];
6060
} else {
6161
self::fail(__METHOD__ . " element must be one of exception, response or reason. But '$element' was passed in.");
6262
}

tests/acceptance/bootstrap/CapabilitiesContext.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
214214

215215
$response = $this->userGetsCapabilities($this->getAdminUsernameForCapabilitiesCheck());
216216
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
217-
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__)->data->capabilities;
217+
218+
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__)->data->capabilities;
218219
$edition = $this->getParameterValueFromXml(
219-
$responseXml,
220+
$responseXmlObject,
220221
'core',
221222
'status@@@edition'
222223
);
@@ -228,7 +229,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
228229
}
229230

230231
$product = $this->getParameterValueFromXml(
231-
$responseXml,
232+
$responseXmlObject,
232233
'core',
233234
'status@@@product'
234235
);
@@ -239,7 +240,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
239240
}
240241

241242
$productName = $this->getParameterValueFromXml(
242-
$responseXml,
243+
$responseXmlObject,
243244
'core',
244245
'status@@@productname'
245246
);
@@ -257,7 +258,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
257258
// We are on oCIS or reva or some other implementation. We cannot do "occ status".
258259
// So get the expected version values by looking in the capabilities response.
259260
$version = $this->getParameterValueFromXml(
260-
$responseXml,
261+
$responseXmlObject,
261262
'core',
262263
'status@@@version'
263264
);
@@ -269,7 +270,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
269270
}
270271

271272
$versionString = $this->getParameterValueFromXml(
272-
$responseXml,
273+
$responseXmlObject,
273274
'core',
274275
'status@@@versionstring'
275276
);
@@ -323,7 +324,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
323324
Assert::assertStringStartsWith(
324325
$majorMinorPatchVersion,
325326
$versionString,
326-
"versionstring should start with $majorMinorPatchVersion but is $versionString"
327+
"version string should start with $majorMinorPatchVersion but is $versionString"
327328
);
328329
}
329330
}

tests/acceptance/bootstrap/CollaborationContext.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,23 @@ public function userCreatesFileInsideFolderInSpaceUsingWopiEndpoint(string $user
148148
*
149149
* @return void
150150
* @throws GuzzleException
151+
* @throws Exception
151152
*/
152153
public function createFile(string $file, string $password, string $folder = ""): void {
153154
$token = $this->featureContext->shareNgGetLastCreatedLinkShareToken();
154155
$baseUrl = $this->featureContext->getBaseUrl();
155156
$davPath = WebDavHelper::getDavPath(WebDavHelper::DAV_VERSION_NEW, $token, "public-files");
156-
$response = HttpRequestHelper::sendRequest(
157-
"$baseUrl/$davPath/$folder",
158-
$this->featureContext->getStepLineRef(),
159-
"PROPFIND",
160-
"public",
161-
$this->featureContext->getActualPassword($password)
162-
);
163-
$responseXml = HttpRequestHelper::getResponseXml(
164-
$response,
165-
__METHOD__
157+
158+
$responseXmlObject = HttpRequestHelper::getResponseXml(
159+
HttpRequestHelper::sendRequest(
160+
"$baseUrl/$davPath/$folder",
161+
$this->featureContext->getStepLineRef(),
162+
"PROPFIND",
163+
"public",
164+
$this->featureContext->getActualPassword($password)
165+
)
166166
);
167-
$xmlPart = $responseXml->xpath("//d:prop/oc:fileid");
167+
$xmlPart = $responseXmlObject->xpath("//d:prop/oc:fileid");
168168
$parentContainerId = (string) $xmlPart[0];
169169

170170
$headers = [

tests/acceptance/bootstrap/FeatureContext.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
use Swaggest\JsonSchema\Exception\ObjectException;
5555
use Swaggest\JsonSchema\Exception\StringException;
5656
use Swaggest\JsonSchema\Exception\TypeException;
57-
use Swaggest\JsonSchema\Exception\Error as JsonSchemaError;
5857

5958
require_once 'bootstrap.php';
6059

@@ -998,11 +997,6 @@ public function setResponse(
998997
string $username = ""
999998
): void {
1000999
$this->response = $response;
1001-
//after a new response reset the response xml
1002-
$this->responseXml = [];
1003-
//after a new response reset the response xml object
1004-
$this->responseXmlObject = null;
1005-
// remember the user that received the response
10061000
$this->responseUser = $username;
10071001
}
10081002

@@ -2591,30 +2585,6 @@ public function workStorageDirLocation(): string {
25912585
return $this->acceptanceTestsDirLocation() . $this->temporaryStorageSubfolderName() . "/";
25922586
}
25932587

2594-
/**
2595-
* Parse list of config keys from the given XML response
2596-
*
2597-
* @param SimpleXMLElement $responseXml
2598-
*
2599-
* @return array
2600-
*/
2601-
public function parseConfigListFromResponseXml(SimpleXMLElement $responseXml): array {
2602-
$configkeyData = \json_decode(\json_encode($responseXml->data), true);
2603-
if (isset($configkeyData['element'])) {
2604-
$configkeyData = $configkeyData['element'];
2605-
} else {
2606-
// There are no keys for the app
2607-
return [];
2608-
}
2609-
if (isset($configkeyData[0])) {
2610-
$configkeyValues = $configkeyData;
2611-
} else {
2612-
// There is just 1 key for the app
2613-
$configkeyValues[0] = $configkeyData;
2614-
}
2615-
return $configkeyValues;
2616-
}
2617-
26182588
/**
26192589
* This will run before EVERY scenario.
26202590
* It will set the properties for this object.

tests/acceptance/bootstrap/FilesVersionsContext.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ public function restoreVersionIndexOfFile(string $user, int $versionIndex, strin
219219
$fileId = $this->featureContext->getFileIdForPath($user, $path);
220220
Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $path user $user not found (the file may not exist)");
221221
$response = $this->listVersionFolder($user, $fileId, 1);
222-
$responseXml = HttpRequestHelper::getResponseXml(
222+
$responseXmlObject = HttpRequestHelper::getResponseXml(
223223
$response,
224224
__METHOD__
225225
);
226-
$xmlPart = $responseXml->xpath("//d:response/d:href");
226+
$xmlPart = $responseXmlObject->xpath("//d:response/d:href");
227227
//restoring the version only works with DAV path v2
228228
$destinationUrl = $this->featureContext->getBaseUrl() . "/" .
229229
WebDavHelper::getDavPath(WebDavHelper::DAV_VERSION_NEW, $user) . \trim($path, "/");
@@ -281,18 +281,18 @@ public function userRestoresVersionIndexOfFile(string $user, int $versionIndex,
281281
*/
282282
public function assertFileVersionsCount(string $user, string $fileId, int $expectedCount):void {
283283
$response = $this->listVersionFolder($user, $fileId, 1);
284-
$responseXml = HttpRequestHelper::getResponseXml(
284+
$responseXmlObject = HttpRequestHelper::getResponseXml(
285285
$response,
286286
__METHOD__
287287
);
288-
$actualCount = \count($responseXml->xpath("//d:prop/d:getetag")) - 1;
288+
$actualCount = \count($responseXmlObject->xpath("//d:prop/d:getetag")) - 1;
289289
if ($actualCount === -1) {
290290
$actualCount = 0;
291291
}
292292
Assert::assertEquals(
293293
$expectedCount,
294294
$actualCount,
295-
"Expected $expectedCount versions but found $actualCount in \n" . $responseXml->asXML()
295+
"Expected $expectedCount versions but found $actualCount in \n" . $responseXmlObject->asXML()
296296
);
297297
}
298298

@@ -356,11 +356,11 @@ public function theContentLengthOfFileForUserInVersionsFolderIs(
356356
$fileId = $this->featureContext->getFileIdForPath($user, $path);
357357
Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $path user $user not found (the file may not exist)");
358358
$response = $this->listVersionFolder($user, $fileId, 1, ['d:getcontentlength']);
359-
$responseXml = HttpRequestHelper::getResponseXml(
359+
$responseXmlObject = HttpRequestHelper::getResponseXml(
360360
$response,
361361
__METHOD__
362362
);
363-
$xmlPart = $responseXml->xpath("//d:prop/d:getcontentlength");
363+
$xmlPart = $responseXmlObject->xpath("//d:prop/d:getcontentlength");
364364
Assert::assertEquals(
365365
$length,
366366
(int) $xmlPart[$index],
@@ -422,8 +422,8 @@ public function downloadVersion(string $user, string $path, string $index, ?stri
422422
if ($response->getStatusCode() === 403) {
423423
return $response;
424424
}
425-
$responseXml = new SimpleXMLElement($response->getBody()->getContents());
426-
$xmlPart = $responseXml->xpath("//d:response/d:href");
425+
$responseXmlObject = new SimpleXMLElement($response->getBody()->getContents());
426+
$xmlPart = $responseXmlObject->xpath("//d:response/d:href");
427427
if (!isset($xmlPart[$index])) {
428428
Assert::fail(
429429
'could not find version of path "' . $path . '" with index "' . $index . '"'
@@ -519,11 +519,6 @@ public function userGetMetaInfo(string $user, string $fileOrFileId, string $path
519519
null
520520
);
521521
$this->featureContext->setResponse($response);
522-
$responseXml = HttpRequestHelper::getResponseXml(
523-
$response,
524-
__METHOD__
525-
);
526-
$this->featureContext->setResponseXmlObject($responseXml);
527522
}
528523

529524
/**

tests/acceptance/bootstrap/OCSContext.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,11 @@ public function getOCSResponseStatusCode(ResponseInterface $response):string {
565565
return (string) $jsonResponse->ocs->meta->statuscode;
566566
}
567567
// go to xml response when json response is null (it means not formatted and get status code)
568-
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
569-
if (isset($responseXml->meta[0], $responseXml->meta[0]->statuscode)) {
570-
return (string) $responseXml->meta[0]->statuscode;
568+
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
569+
if (isset($responseXmlObject->meta[0], $responseXmlObject->meta[0]->statuscode)) {
570+
return (string) $responseXmlObject->meta[0]->statuscode;
571571
}
572-
throw new Exception(
573-
"No OCS status code found in response"
574-
);
572+
Assert::fail("No OCS status code found in response");
575573
}
576574

577575
/**
@@ -583,13 +581,11 @@ public function getOCSResponseStatusCode(ResponseInterface $response):string {
583581
* @throws Exception
584582
*/
585583
public function getOCSResponseData(ResponseInterface $response): SimpleXMLElement {
586-
$responseXml = HttpRequestHelper::getResponseXml($response, __METHOD__);
587-
if (isset($responseXml->data)) {
588-
return $responseXml->data;
584+
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
585+
if (isset($responseXmlObject->data)) {
586+
return $responseXmlObject->data;
589587
}
590-
throw new Exception(
591-
"No OCS data items found in responseXml"
592-
);
588+
Assert::fail("No OCS data items found in response");
593589
}
594590

595591
/**

tests/acceptance/bootstrap/Provisioning.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,8 +1905,7 @@ function ($user) {
19051905
* @throws Exception
19061906
*/
19071907
public function getArrayOfUsersResponded(ResponseInterface $resp):array {
1908-
$listCheckedElements
1909-
= $this->getResponseXml($resp, __METHOD__)->data[0]->users[0]->element;
1908+
$listCheckedElements = HttpRequestHelper::getResponseXml($resp, __METHOD__)->data[0]->users[0]->element;
19101909
return \json_decode(\json_encode($listCheckedElements), true);
19111910
}
19121911

@@ -1920,7 +1919,7 @@ public function getArrayOfUsersResponded(ResponseInterface $resp):array {
19201919
*/
19211920
public function getArrayOfGroupsResponded(ResponseInterface $resp):array {
19221921
$listCheckedElements
1923-
= $this->getResponseXml($resp, __METHOD__)->data[0]->groups[0]->element;
1922+
= HttpRequestHelper::getResponseXml($resp, __METHOD__)->data[0]->groups[0]->element;
19241923
return \json_decode(\json_encode($listCheckedElements), true);
19251924
}
19261925

@@ -1933,8 +1932,7 @@ public function getArrayOfGroupsResponded(ResponseInterface $resp):array {
19331932
* @throws Exception
19341933
*/
19351934
public function getArrayOfAppsResponded(ResponseInterface $resp):array {
1936-
$listCheckedElements
1937-
= $this->getResponseXml($resp, __METHOD__)->data[0]->apps[0]->element;
1935+
$listCheckedElements = HttpRequestHelper::getResponseXml($resp, __METHOD__)->data[0]->apps[0]->element;
19381936
return \json_decode(\json_encode($listCheckedElements), true);
19391937
}
19401938

@@ -1945,7 +1943,7 @@ public function getArrayOfAppsResponded(ResponseInterface $resp):array {
19451943
* @throws Exception
19461944
*/
19471945
public function theApiShouldNotReturnAnyData():void {
1948-
$responseData = $this->getResponseXml(null, __METHOD__)->data[0];
1946+
$responseData = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0];
19491947
Assert::assertEmpty(
19501948
$responseData,
19511949
"Response data is not empty but it should be empty"

0 commit comments

Comments
 (0)