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

DownloadCest.php « api « tests - github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bd0e0e4f2994ce81acf44f29ba247d1fc4f56155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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['testimage.jpg'];
		$url = $this->apiUrl . '/' . $file['id'];
		$I->sendGET($url);
		$I->downloadAFile($file, 'testimage.jpg');
	}

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