summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-03-17 09:17:36 +0100
committerGitHub <noreply@github.com>2017-03-17 09:17:36 +0100
commitd504408efd23378140ef7d1491dae555da16e9c4 (patch)
treed959254bd37476364a3038c2a99d4e32fb8f9838 /build
parent51846c95d99f1f4b134a335db795df9bcafe4fbe (diff)
parent3740f9bc2616ee129566c6c075df0fe41b68acd0 (diff)
downloadnextcloud-server-d504408efd23378140ef7d1491dae555da16e9c4.tar.gz
nextcloud-server-d504408efd23378140ef7d1491dae555da16e9c4.zip
Merge pull request #3894 from nextcloud/downstream-27008
Integration test check download without saving file locally
Diffstat (limited to 'build')
-rw-r--r--build/integration/features/bootstrap/Sharing.php42
1 files changed, 25 insertions, 17 deletions
diff --git a/build/integration/features/bootstrap/Sharing.php b/build/integration/features/bootstrap/Sharing.php
index a4a9b846cf4..e5618987069 100644
--- a/build/integration/features/bootstrap/Sharing.php
+++ b/build/integration/features/bootstrap/Sharing.php
@@ -102,21 +102,13 @@ trait Sharing {
$url = $this->lastShareData->data->url;
}
$fullUrl = $url . "/download";
- $options['save_to'] = "./$filename";
- $this->response = $client->get($fullUrl, $options);
- $finfo = new finfo;
- $fileinfo = $finfo->file("./$filename", FILEINFO_MIME_TYPE);
- PHPUnit_Framework_Assert::assertEquals($fileinfo, "text/plain");
- if (file_exists("./$filename")) {
- unlink("./$filename");
- }
+ $this->checkDownload($fullUrl, null, 'text/plain');
}
/**
* @Then /^Public shared file "([^"]*)" with password "([^"]*)" can be downloaded$/
*/
public function checkPublicSharedFileWithPassword($filename, $password) {
- $client = new Client();
$options = [];
if (count($this->lastShareData->data->element) > 0){
$token = $this->lastShareData->data[0]->token;
@@ -126,14 +118,30 @@ trait Sharing {
}
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav";
- $options['auth'] = [$token, $password];
- $options['save_to'] = "./$filename";
- $this->response = $client->get($fullUrl, $options);
- $finfo = new finfo;
- $fileinfo = $finfo->file("./$filename", FILEINFO_MIME_TYPE);
- PHPUnit_Framework_Assert::assertEquals($fileinfo, "text/plain");
- if (file_exists("./$filename")) {
- unlink("./$filename");
+ $this->checkDownload($fullUrl, [$token, $password], 'text/plain');
+ }
+
+ private function checkDownload($url, $auth = null, $mimeType = null) {
+ if ($auth !== null) {
+ $options['auth'] = $auth;
+ }
+ $options['stream'] = true;
+
+ $client = new Client();
+ $this->response = $client->get($url, $options);
+ PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
+
+ $buf = '';
+ $body = $this->response->getBody();
+ while (!$body->eof()) {
+ // read everything
+ $buf .= $body->read(8192);
+ }
+ $body->close();
+
+ if ($mimeType !== null) {
+ $finfo = new finfo;
+ PHPUnit_Framework_Assert::assertEquals($mimeType, $finfo->buffer($buf, FILEINFO_MIME_TYPE));
}
}