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 *