aboutsummaryrefslogtreecommitdiffstats
path: root/build/integration/features/bootstrap/ConversionsContext.php
blob: 099a22636303a46bbbf15808084a2a90e2307a3e (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
<?php
/**
 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
require __DIR__ . '/../../vendor/autoload.php';

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\TableNode;

class ConversionsContext implements Context, SnippetAcceptingContext {
	use AppConfiguration;
	use BasicStructure;
	use WebDav;

	/** @BeforeScenario */
	public function setUpScenario() {
		$this->asAn('admin');
		$this->setStatusTestingApp(true);
	}

	/** @AfterScenario */
	public function tearDownScenario() {
		$this->asAn('admin');
		$this->setStatusTestingApp(false);
	}

	protected function resetAppConfigs() {
	}

	/**
	 * @When /^user "([^"]*)" converts file "([^"]*)" to "([^"]*)"$/
	 */
	public function userConvertsTheSavedFileId(string $user, string $path, string $mime) {
		$this->userConvertsTheSavedFileIdTo($user, $path, $mime, null);
	}

	/**
	 * @When /^user "([^"]*)" converts file "([^"]*)" to "([^"]*)" and saves it to "([^"]*)"$/
	 */
	public function userConvertsTheSavedFileIdTo(string $user, string $path, string $mime, ?string $destination) {
		try {
			$fileId = $this->getFileIdForPath($user, $path);
		} catch (Exception $e) {
			// return a fake value to keep going and be able to test the error
			$fileId = 0;
		}

		$data = [['fileId', $fileId], ['targetMimeType', $mime]];
		if ($destination !== null) {
			$data[] = ['destination', $destination];
		}

		$this->asAn($user);
		$this->sendingToWith('post', '/apps/files/api/v1/convert', new TableNode($data));
	}
}