aboutsummaryrefslogtreecommitdiffstats
path: root/build/integration/features/bootstrap/Download.php
diff options
context:
space:
mode:
Diffstat (limited to 'build/integration/features/bootstrap/Download.php')
-rw-r--r--build/integration/features/bootstrap/Download.php73
1 files changed, 43 insertions, 30 deletions
diff --git a/build/integration/features/bootstrap/Download.php b/build/integration/features/bootstrap/Download.php
index 7879159325a..549a033346e 100644
--- a/build/integration/features/bootstrap/Download.php
+++ b/build/integration/features/bootstrap/Download.php
@@ -1,33 +1,16 @@
<?php
+
/**
- * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
- *
- * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
use PHPUnit\Framework\Assert;
+use Psr\Http\Message\StreamInterface;
require __DIR__ . '/../../vendor/autoload.php';
trait Download {
-
- /** @var string **/
+ /** @var string * */
private $downloadedFile;
/** @AfterScenario **/
@@ -39,16 +22,16 @@ trait Download {
* @When user :user downloads zip file for entries :entries in folder :folder
*/
public function userDownloadsZipFileForEntriesInFolder($user, $entries, $folder) {
+ $folder = trim($folder, '/');
$this->asAn($user);
- $this->sendingToDirectUrl('GET', "/index.php/apps/files/ajax/download.php?dir=" . $folder . "&files=[" . $entries . "]");
+ $this->sendingToDirectUrl('GET', "/remote.php/dav/files/$user/$folder?accept=zip&files=[" . $entries . ']');
$this->theHTTPStatusCodeShouldBe('200');
-
- $this->getDownloadedFile();
}
private function getDownloadedFile() {
$this->downloadedFile = '';
+ /** @var StreamInterface */
$body = $this->response->getBody();
while (!$body->eof()) {
$this->downloadedFile .= $body->read(8192);
@@ -57,14 +40,28 @@ trait Download {
}
/**
+ * @Then the downloaded file is a zip file
+ */
+ public function theDownloadedFileIsAZipFile() {
+ $this->getDownloadedFile();
+
+ Assert::assertTrue(
+ strpos($this->downloadedFile, "\x50\x4B\x01\x02") !== false,
+ 'File does not contain the central directory file header'
+ );
+ }
+
+ /**
* @Then the downloaded zip file is a zip32 file
*/
public function theDownloadedZipFileIsAZip32File() {
+ $this->theDownloadedFileIsAZipFile();
+
// assertNotContains is not used to prevent the whole file from being
// printed in case of error.
Assert::assertTrue(
strpos($this->downloadedFile, "\x50\x4B\x06\x06") === false,
- "File contains the zip64 end of central dir signature"
+ 'File contains the zip64 end of central dir signature'
);
}
@@ -72,11 +69,13 @@ trait Download {
* @Then the downloaded zip file is a zip64 file
*/
public function theDownloadedZipFileIsAZip64File() {
+ $this->theDownloadedFileIsAZipFile();
+
// assertNotContains is not used to prevent the whole file from being
// printed in case of error.
Assert::assertTrue(
strpos($this->downloadedFile, "\x50\x4B\x06\x06") !== false,
- "File does not contain the zip64 end of central dir signature"
+ 'File does not contain the zip64 end of central dir signature'
);
}
@@ -96,7 +95,7 @@ trait Download {
// in case of error and to be able to get the extra field length.
Assert::assertEquals(
1, preg_match($fileHeaderRegExp, $this->downloadedFile, $matches),
- "Local header for file did not appear once in zip file"
+ 'Local header for file did not appear once in zip file'
);
$extraFieldLength = unpack('vextraFieldLength', $matches[1])['extraFieldLength'];
@@ -116,7 +115,7 @@ trait Download {
// in case of error.
Assert::assertEquals(
1, preg_match($fileHeaderAndContentRegExp, $this->downloadedFile),
- "Local header and contents for file did not appear once in zip file"
+ 'Local header and contents for file did not appear once in zip file'
);
}
@@ -136,7 +135,21 @@ trait Download {
// in case of error.
Assert::assertEquals(
1, preg_match($folderHeaderRegExp, $this->downloadedFile),
- "Local header for folder did not appear once in zip file"
+ 'Local header for folder did not appear once in zip file'
+ );
+ }
+
+ /**
+ * @Then the downloaded file has the content of :sourceFilename from :user data
+ */
+ public function theDownloadedFileHasContentOfUserFile($sourceFilename, $user) {
+ $this->getDownloadedFile();
+ $expectedFileContents = file_get_contents($this->getDataDirectory() . "/$user/files" . $sourceFilename);
+
+ // prevent the whole file from being printed in case of error.
+ Assert::assertEquals(
+ 0, strcmp($expectedFileContents, $this->downloadedFile),
+ 'Downloaded file content does not match local file content'
);
}
}