Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions build/integration/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,13 @@ public function checkPublicSharedFile($filename) {
$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;
Expand All @@ -126,14 +118,30 @@ public function checkPublicSharedFileWithPassword($filename, $password) {
}

$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));
}
}

Expand Down