From 0423f2ea4d0ad99334187db9c1e1b0822c640af9 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Mon, 6 May 2019 10:51:13 +0545 Subject: [PATCH] Test Helper to read file from server --- tests/TestHelpers/SetupHelper.php | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/TestHelpers/SetupHelper.php b/tests/TestHelpers/SetupHelper.php index 1a757ac34211..67affb19cec6 100644 --- a/tests/TestHelpers/SetupHelper.php +++ b/tests/TestHelpers/SetupHelper.php @@ -470,6 +470,46 @@ public static function deleteFileOnServer( } } + /** + * @param string $fileInCore e.g. 'app2/myapp/appinfo/info.xml' + * @param string|null $baseUrl + * @param string|null $adminUsername + * @param string|null $adminPassword + * + * @return string + * @throws Exception + */ + public static function readFileFromServer( + $fileInCore, + $baseUrl = null, + $adminUsername = null, + $adminPassword = null + ) { + $baseUrl = self::checkBaseUrl($baseUrl, "readFile"); + $adminUsername = self::checkAdminUsername( + $adminUsername, "readFile" + ); + $adminPassword = self::checkAdminPassword( + $adminPassword, "readFile" + ); + + $response = OcsApiHelper::sendRequest( + $baseUrl, + $adminUsername, + $adminPassword, + 'GET', + "/apps/testing/api/v1/file?file={$fileInCore}" + ); + self::assertSame( + 200, + $response->getStatusCode(), + "Failed to read the file {$fileInCore}" + ); + $localContent = HttpRequestHelper::getResponseXml($response); + $localContent = (string)$localContent->data->element->contentUrlEncoded; + return \urldecode($localContent); + } + /** * returns the content of a file in a skeleton folder *