Skip to content

Commit 58410b0

Browse files
authored
Merge pull request #10680 from owncloud/remove-duplicated-method
[tests-only][full-ci]Remove duplicate function
2 parents 68b64ea + e83b63f commit 58410b0

14 files changed

+254
-445
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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use PHPUnit\Framework\Assert;
3030
use TestHelpers\OcsApiHelper;
3131
use TestHelpers\BehatHelper;
32+
use TestHelpers\HttpRequestHelper;
3233

3334
require_once 'bootstrap.php';
3435

@@ -213,9 +214,10 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
213214

214215
$response = $this->userGetsCapabilities($this->getAdminUsernameForCapabilitiesCheck());
215216
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
216-
$responseXml = $this->featureContext->getResponseXml($response)->data->capabilities;
217+
218+
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__)->data->capabilities;
217219
$edition = $this->getParameterValueFromXml(
218-
$responseXml,
220+
$responseXmlObject,
219221
'core',
220222
'status@@@edition'
221223
);
@@ -227,7 +229,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
227229
}
228230

229231
$product = $this->getParameterValueFromXml(
230-
$responseXml,
232+
$responseXmlObject,
231233
'core',
232234
'status@@@product'
233235
);
@@ -238,7 +240,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
238240
}
239241

240242
$productName = $this->getParameterValueFromXml(
241-
$responseXml,
243+
$responseXmlObject,
242244
'core',
243245
'status@@@productname'
244246
);
@@ -256,7 +258,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
256258
// We are on oCIS or reva or some other implementation. We cannot do "occ status".
257259
// So get the expected version values by looking in the capabilities response.
258260
$version = $this->getParameterValueFromXml(
259-
$responseXml,
261+
$responseXmlObject,
260262
'core',
261263
'status@@@version'
262264
);
@@ -268,7 +270,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
268270
}
269271

270272
$versionString = $this->getParameterValueFromXml(
271-
$responseXml,
273+
$responseXmlObject,
272274
'core',
273275
'status@@@versionstring'
274276
);
@@ -322,7 +324,7 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected): void
322324
Assert::assertStringStartsWith(
323325
$majorMinorPatchVersion,
324326
$versionString,
325-
"versionstring should start with $majorMinorPatchVersion but is $versionString"
327+
"version string should start with $majorMinorPatchVersion but is $versionString"
326328
);
327329
}
328330
}

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 & 50 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

@@ -1032,26 +1026,6 @@ public function usingServer(?string $server): string {
10321026
return $previousServer;
10331027
}
10341028

1035-
/**
1036-
* Parses the response as XML
1037-
*
1038-
* @param ResponseInterface|null $response
1039-
* @param string|null $exceptionText text to put at the front of exception messages
1040-
*
1041-
* @return SimpleXMLElement
1042-
* @throws Exception
1043-
*/
1044-
public function getResponseXml(?ResponseInterface $response = null, ?string $exceptionText = ''): SimpleXMLElement {
1045-
if ($response === null) {
1046-
$response = $this->response;
1047-
}
1048-
1049-
if ($exceptionText === '') {
1050-
$exceptionText = __METHOD__;
1051-
}
1052-
return HttpRequestHelper::getResponseXml($response, $exceptionText);
1053-
}
1054-
10551029
/**
10561030
* @param JsonSchema $schemaObj
10571031
*
@@ -2611,30 +2585,6 @@ public function workStorageDirLocation(): string {
26112585
return $this->acceptanceTestsDirLocation() . $this->temporaryStorageSubfolderName() . "/";
26122586
}
26132587

2614-
/**
2615-
* Parse list of config keys from the given XML response
2616-
*
2617-
* @param SimpleXMLElement $responseXml
2618-
*
2619-
* @return array
2620-
*/
2621-
public function parseConfigListFromResponseXml(SimpleXMLElement $responseXml): array {
2622-
$configkeyData = \json_decode(\json_encode($responseXml->data), true);
2623-
if (isset($configkeyData['element'])) {
2624-
$configkeyData = $configkeyData['element'];
2625-
} else {
2626-
// There are no keys for the app
2627-
return [];
2628-
}
2629-
if (isset($configkeyData[0])) {
2630-
$configkeyValues = $configkeyData;
2631-
} else {
2632-
// There is just 1 key for the app
2633-
$configkeyValues[0] = $configkeyData;
2634-
}
2635-
return $configkeyValues;
2636-
}
2637-
26382588
/**
26392589
* This will run before EVERY scenario.
26402590
* 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: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Behat\Gherkin\Node\TableNode;
2727
use Psr\Http\Message\ResponseInterface;
2828
use PHPUnit\Framework\Assert;
29+
use TestHelpers\HttpRequestHelper;
2930
use TestHelpers\OcsApiHelper;
3031
use TestHelpers\TranslationHelper;
3132
use TestHelpers\BehatHelper;
@@ -564,13 +565,11 @@ public function getOCSResponseStatusCode(ResponseInterface $response):string {
564565
return (string) $jsonResponse->ocs->meta->statuscode;
565566
}
566567
// go to xml response when json response is null (it means not formatted and get status code)
567-
$responseXml = $this->featureContext->getResponseXml($response, __METHOD__);
568-
if (isset($responseXml->meta[0], $responseXml->meta[0]->statuscode)) {
569-
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;
570571
}
571-
throw new Exception(
572-
"No OCS status code found in response"
573-
);
572+
Assert::fail("No OCS status code found in response");
574573
}
575574

576575
/**
@@ -582,13 +581,11 @@ public function getOCSResponseStatusCode(ResponseInterface $response):string {
582581
* @throws Exception
583582
*/
584583
public function getOCSResponseData(ResponseInterface $response): SimpleXMLElement {
585-
$responseXml = $this->featureContext->getResponseXml($response, __METHOD__);
586-
if (isset($responseXml->data)) {
587-
return $responseXml->data;
584+
$responseXmlObject = HttpRequestHelper::getResponseXml($response, __METHOD__);
585+
if (isset($responseXmlObject->data)) {
586+
return $responseXmlObject->data;
588587
}
589-
throw new Exception(
590-
"No OCS data items found in responseXml"
591-
);
588+
Assert::fail("No OCS data items found in response");
592589
}
593590

594591
/**
@@ -600,7 +597,7 @@ public function getOCSResponseData(ResponseInterface $response): SimpleXMLElemen
600597
* @return string
601598
*/
602599
public function getOCSResponseStatusMessage(ResponseInterface $response):string {
603-
return (string) $this->featureContext->getResponseXml($response, __METHOD__)->meta[0]->message;
600+
return (string) HttpRequestHelper::getResponseXml($response, __METHOD__)->meta[0]->message;
604601
}
605602

606603
/**

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"

tests/acceptance/bootstrap/ShareesContext.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Psr\Http\Message\ResponseInterface;
2929
use PHPUnit\Framework\Assert;
3030
use TestHelpers\BehatHelper;
31+
use TestHelpers\HttpRequestHelper;
3132

3233
require_once 'bootstrap.php';
3334

@@ -155,7 +156,7 @@ public function getArrayOfShareesResponded(
155156
ResponseInterface $response,
156157
string $shareeType
157158
):array {
158-
$elements = $this->featureContext->getResponseXml($response, __METHOD__)->data;
159+
$elements = HttpRequestHelper::getResponseXml($response, __METHOD__)->data;
159160
$elements = \json_decode(\json_encode($elements), true);
160161
if (\strpos($shareeType, 'exact ') === 0) {
161162
$elements = $elements['exact'];

0 commit comments

Comments
 (0)