Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests/api
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-08-19 02:52:12 +0300
committerOlivier Paroz <github@oparoz.com>2015-08-19 02:52:13 +0300
commit7d393650e7e231a68038ccb9fd069cd95746806b (patch)
tree1ff0b8eab9bc03c84d995269b00afd40d928e0d8 /tests/api
parent8a002c4633c896c531d60d4042fe5276172bb157 (diff)
Add download API
Diffstat (limited to 'tests/api')
-rw-r--r--tests/api/DownloadCest.php66
-rw-r--r--tests/api/DownloadWithTokenCest.php74
-rw-r--r--tests/api/GetPreviewCest.php13
3 files changed, 143 insertions, 10 deletions
diff --git a/tests/api/DownloadCest.php b/tests/api/DownloadCest.php
new file mode 100644
index 00000000..a1ef12dd
--- /dev/null
+++ b/tests/api/DownloadCest.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * ownCloud - gallery
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Olivier Paroz <owncloud@interfasys.ch>
+ *
+ * @copyright Olivier Paroz 2015
+ */
+
+use Page\Gallery as GalleryApp;
+
+/**
+ * Class DownloadCest
+ */
+class DownloadCest {
+
+ private $apiUrl;
+
+ /**
+ * Sets up the environment for this series of tests
+ *
+ * @param ApiTester $I
+ */
+ public function _before(ApiTester $I) {
+ $this->apiUrl = GalleryApp::$URL . 'api/files/download';
+ }
+
+ public function _after(ApiTester $I) {
+ }
+
+ /**
+ * Connects to the API as an anonymous user
+ *
+ * @param \Step\Api\Anonymous $I
+ */
+ public function unauthorizedAccess(\Step\Api\Anonymous $I) {
+ $I->connectToTheApi($this->apiUrl. '/9999999', 'the download API');
+ }
+
+ public function downloadFile(\Step\Api\User $I) {
+ $I->am('an app');
+ $I->wantTo('download a file');
+
+ $I->getUserCredentialsAndUseHttpAuthentication();
+ $data = $I->getFilesDataForFolder('');
+ $file = $data[0];
+ $url = $this->apiUrl . '/' . $file['id'];
+ $I->sendGET($url);
+ $I->downloadAFile($file);
+ }
+
+ public function fileNotFoundPage(\Step\Api\User $I) {
+ $I->am('an app');
+ $I->wantTo('download a file without a valid fileId');
+ $I->amGoingTo("send a fileId which doesn't exist");
+ $I->expectTo("be redirected to an error 404 page");
+ $I->getUserCredentialsAndUseHttpAuthentication();
+ $url = $this->apiUrl . '/9999999';
+ $I->sendGET($url);
+ $I->seeResponseCodeIs(404);
+ $I->seeHttpHeader('Content-type', 'text/html; charset=UTF-8');
+ }
+}
diff --git a/tests/api/DownloadWithTokenCest.php b/tests/api/DownloadWithTokenCest.php
new file mode 100644
index 00000000..f2f12a0c
--- /dev/null
+++ b/tests/api/DownloadWithTokenCest.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * ownCloud - gallery
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Olivier Paroz <owncloud@interfasys.ch>
+ *
+ * @copyright Olivier Paroz 2015
+ */
+
+use Page\Gallery as GalleryApp;
+
+/**
+ * Class DownloadWithTokenCest
+ */
+class DownloadWithTokenCest {
+
+ private $apiUrl;
+ private $browserHeader = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
+
+ /**
+ * Sets up the environment for this series of tests
+ *
+ * @param ApiTester $I
+ */
+ public function _before(\Step\Api\TokenUser $I) {
+ $this->apiUrl = GalleryApp::$URL . 's/';
+ $I->haveHttpHeader('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
+ }
+
+ public function _after(ApiTester $I) {
+ }
+
+ public function downloadFile(\Step\Api\TokenUser $I) {
+ $I->am('a file owner');
+ $I->wantTo('insert a file in a forum');
+
+ $fileMetaData = $I->getSharedFileInformation();
+ $I->haveHttpHeader('Accept',$this->browserHeader);
+ $I->sendGET($this->apiUrl . $fileMetaData['token']);
+ $I->downloadAFile($fileMetaData);
+ }
+
+ public function downloadFileWithCustomFilename(\Step\Api\TokenUser $I) {
+ $I->am('a file owner');
+ $I->wantTo('insert a file in a forum');
+
+ $fileMetaData = $I->getSharedFileInformation();
+ // Note: The share file is a PNG
+ $filename = 'jackinabox.png';
+ $url = $this->apiUrl . $fileMetaData['token'] . '/' . $filename;
+ $I->haveHttpHeader('Accept',$this->browserHeader);
+ $I->sendGET($url);
+ $I->downloadAFile($fileMetaData, $filename);
+ }
+
+ /**
+ * When a token is not valid we get an error 400, NOT 404
+ *
+ * @param \Step\Api\TokenUser $I
+ */
+ public function fileNotFoundPage(\Step\Api\TokenUser $I) {
+ $I->am('a file owner');
+ $I->wantTo('insert a file in a forum');
+ $I->amGoingTo("send a bogus token");
+ $I->expectTo("be redirected to an error 400 page");
+ $I->haveHttpHeader('Accept',$this->browserHeader);
+ $I->sendGET($this->apiUrl . '1AmaW1cK3d70k3N');
+ $I->seeResponseCodeIs(400);
+ $I->seeHttpHeader('Content-type', 'text/html; charset=UTF-8');
+ }
+}
diff --git a/tests/api/GetPreviewCest.php b/tests/api/GetPreviewCest.php
index 2b205b57..8846725b 100644
--- a/tests/api/GetPreviewCest.php
+++ b/tests/api/GetPreviewCest.php
@@ -37,7 +37,7 @@ class GetPreviewCest {
* @param \Step\Api\Anonymous $I
*/
public function unauthorizedAccess(\Step\Api\Anonymous $I) {
- $I->connectToTheApi($this->apiUrl. '/12345/1920/1080', 'the preview API');
+ $I->connectToTheApi($this->apiUrl. '/9999999/1920/1080', 'the preview API');
}
public function getPreview(\Step\Api\User $I) {
@@ -48,15 +48,8 @@ class GetPreviewCest {
$data = $I->getFilesDataForFolder('');
$file = $data[0];
$url = $this->apiUrl . '/' . $file['id'] . '/1920/1080';
- $filename = urlencode($file['name']);
$I->sendGET($url);
- $I->seeResponseCodeIs(200);
- $I->seeHttpHeader('Content-type', $file['mediatype'] . '; charset=utf-8');
- $I->seeHttpHeader(
- 'Content-Disposition', 'attachment; filename*=UTF-8\'\'' . $filename . '; filename="'
- . $filename . '"'
- );
-
+ $I->downloadAFile($file);
}
public function emptyResponse(\Step\Api\User $I) {
@@ -65,7 +58,7 @@ class GetPreviewCest {
$I->amGoingTo("send a fileId which doesn't exist");
$I->expectTo("receive a 404");
$I->getUserCredentialsAndUseHttpAuthentication();
- $url = $this->apiUrl . '/0/1920/1080';
+ $url = $this->apiUrl . '/9999999/1920/1080';
$I->sendGET($url);
$I->seeResponseCodeIs(404);
}