diff options
author | Olivier Paroz <github@oparoz.com> | 2015-08-18 01:51:49 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-08-18 01:51:49 +0300 |
commit | b9035581998136c19cf4bcb31fedd7f244d48bec (patch) | |
tree | e4a4165899029808742417ba4b2b1252f0b42104 /tests/api | |
parent | 73563afdb879b28e95ed437326e6284c076a6c31 (diff) |
Add Preview API
Diffstat (limited to 'tests/api')
-rw-r--r-- | tests/api/GetConfigCest.php | 32 | ||||
-rw-r--r-- | tests/api/GetFilesCest.php | 32 | ||||
-rw-r--r-- | tests/api/GetPreviewCest.php | 72 |
3 files changed, 102 insertions, 34 deletions
diff --git a/tests/api/GetConfigCest.php b/tests/api/GetConfigCest.php index 41647060..17e5e6c2 100644 --- a/tests/api/GetConfigCest.php +++ b/tests/api/GetConfigCest.php @@ -19,24 +19,22 @@ use Page\Gallery as GalleryApp; */ class GetConfigCest { - private $userId; - private $password; - private $configApi; + private $apiUrl; public function _before(ApiTester $I) { - $this->configApi = GalleryApp::$URL . 'api/config'; - list ($this->userId, $this->password) = $I->getUserCredentials(); + $this->apiUrl = GalleryApp::$URL . 'api/config'; } public function _after(ApiTester $I) { } - public function unauthorizedAccess(ApiTester $I) { - $I->am('an app'); - $I->wantTo('connect to the Config API without credentials'); - $I->sendGET($this->configApi); - $I->seeResponseCodeIs(401); - $I->seeResponseIsJson(); + /** + * Connects to the API as an anonymous user + * + * @param \Step\Api\Anonymous $I + */ + public function unauthorizedAccess(\Step\Api\Anonymous $I) { + $I->connectToTheApi($this->apiUrl, 'the config API'); } /** @@ -47,13 +45,13 @@ class GetConfigCest { * * @param ApiTester $I */ - public function getConfig(ApiTester $I) { + public function getConfig(\Step\Api\User $I) { $I->am('an app'); $I->wantTo('get the current Gallery configuration'); - $I->amHttpAuthenticated($this->userId, $this->password); + $I->getUserCredentialsAndUseHttpAuthentication(); $params = ['extramediatypes' => false]; - $I->sendGET($this->configApi, $params); + $I->sendGET($this->apiUrl, $params); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); @@ -81,13 +79,13 @@ class GetConfigCest { * @param ApiTester $I * @param $scenario */ - public function getConfigWithExtraMediaTypes(ApiTester $I, \Codeception\Scenario $scenario) { + public function getConfigWithExtraMediaTypes(\Step\Api\User $I, \Codeception\Scenario $scenario) { $I->am('an app'); $I->wantTo('get the current Gallery configuration which should include extra media types'); - $I->amHttpAuthenticated($this->userId, $this->password); + $I->getUserCredentialsAndUseHttpAuthentication(); $params = ['extramediatypes' => true]; - $I->sendGET($this->configApi, $params); + $I->sendGET($this->apiUrl, $params); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); diff --git a/tests/api/GetFilesCest.php b/tests/api/GetFilesCest.php index 5c69409e..c2eb5031 100644 --- a/tests/api/GetFilesCest.php +++ b/tests/api/GetFilesCest.php @@ -19,9 +19,7 @@ use Page\Gallery as GalleryApp; */ class GetFilesCest { - private $userId; - private $password; - private $filesApi; + private $apiUrl; private $params; /** @@ -33,8 +31,7 @@ class GetFilesCest { * @param ApiTester $I */ public function _before(ApiTester $I) { - $this->filesApi = GalleryApp::$URL . 'api/files/list'; - list ($this->userId, $this->password) = $I->getUserCredentials(); + $this->apiUrl = GalleryApp::$URL . 'api/files/list'; list($mediaTypes) = $I->getMediaTypes(); $this->params = [ 'mediatypes' => implode(';', $mediaTypes) @@ -44,22 +41,23 @@ class GetFilesCest { public function _after(ApiTester $I) { } - public function unauthorizedAccess(ApiTester $I) { - $I->am('an app'); - $I->wantTo('connect to the Files API without credentials'); - $I->sendGET($this->filesApi, $this->params); - $I->seeResponseCodeIs(401); - $I->seeResponseIsJson(); + /** + * Connects to the API as an anonymous user + * + * @param \Step\Api\Anonymous $I + */ + public function unauthorizedAccess(\Step\Api\Anonymous $I) { + $I->connectToTheApi($this->apiUrl, 'the files/list API'); } - public function getStandardList(ApiTester $I) { + public function getStandardList(\Step\Api\User $I) { $I->am('an app'); $I->wantTo( 'get the list of available media files' ); - $I->amHttpAuthenticated($this->userId, $this->password); - $I->sendGET($this->filesApi, $this->params); + $I->getUserCredentialsAndUseHttpAuthentication(); + $I->sendGET($this->apiUrl, $this->params); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); @@ -79,15 +77,15 @@ class GetFilesCest { * * @param ApiTester $I */ - public function getListWithNativeSvgEnabled(ApiTester $I) { + public function getListWithNativeSvgEnabled(\Step\Api\User $I) { $mediaTypes = $this->params['mediatypes']; $params = ['mediatypes' => $mediaTypes . ';image/svg+xml']; $I->am('an app'); $I->wantTo('get the list of available media files which should include SVGs'); - $I->amHttpAuthenticated($this->userId, $this->password); - $I->sendGET($this->filesApi, $params); + $I->getUserCredentialsAndUseHttpAuthentication(); + $I->sendGET($this->apiUrl, $params); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['path' => 'folder2/testimagelarge.svg']); diff --git a/tests/api/GetPreviewCest.php b/tests/api/GetPreviewCest.php new file mode 100644 index 00000000..2b205b57 --- /dev/null +++ b/tests/api/GetPreviewCest.php @@ -0,0 +1,72 @@ +<?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 GetPreviewCest + */ +class GetPreviewCest { + + private $apiUrl; + + /** + * Sets up the environment for this series of tests + * + * @param ApiTester $I + */ + public function _before(ApiTester $I) { + $this->apiUrl = GalleryApp::$URL . 'api/preview'; + } + + 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. '/12345/1920/1080', 'the preview API'); + } + + public function getPreview(\Step\Api\User $I) { + $I->am('an app'); + $I->wantTo('get the preview of a file'); + + $I->getUserCredentialsAndUseHttpAuthentication(); + $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 . '"' + ); + + } + + public function emptyResponse(\Step\Api\User $I) { + $I->am('an app'); + $I->wantTo('get the preview of a file without a valid fileId'); + $I->amGoingTo("send a fileId which doesn't exist"); + $I->expectTo("receive a 404"); + $I->getUserCredentialsAndUseHttpAuthentication(); + $url = $this->apiUrl . '/0/1920/1080'; + $I->sendGET($url); + $I->seeResponseCodeIs(404); + } +} |