Skip to content

Commit 4271705

Browse files
committed
chore: add file conversion integration tests
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 55337af commit 4271705

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

build/integration/config/behat.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ default:
110110
baseUrl: http://localhost:8080
111111
- ChecksumsContext:
112112
baseUrl: http://localhost:8080
113+
- ConversionsContext:
114+
baseUrl: http://localhost:8080
113115
- CommandLineContext:
114116
baseUrl: http://localhost:8080
115117
ocPath: ../../

build/integration/data/clouds.jpg

526 KB
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SPDX-FileCopyrightText: 2019 CHUTTERSNAP <https://unsplash.com/@chuttersnap> <https://unsplash.com/photos/blue-clouds-under-white-sky-9AqIdzEc9pY>"
2+
SPDX-License-Identifier: LicenseRef-Unsplash
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
require __DIR__ . '/../../vendor/autoload.php';
8+
9+
use Behat\Behat\Context\Context;
10+
use Behat\Behat\Context\SnippetAcceptingContext;
11+
use Behat\Gherkin\Node\TableNode;
12+
use GuzzleHttp\Client;
13+
14+
class ConversionsContext implements Context, SnippetAcceptingContext {
15+
use WebDav;
16+
17+
public function __construct(string $baseUrl) {
18+
$this->baseUrl = $baseUrl;
19+
20+
// in case of ci deployment we take the server url from the environment
21+
$testServerUrl = getenv('TEST_SERVER_URL');
22+
if ($testServerUrl !== false) {
23+
$this->baseUrl = substr($testServerUrl, 0, -5);
24+
}
25+
}
26+
27+
/** @BeforeScenario */
28+
public function setUpScenario() {
29+
$this->client = new Client();
30+
}
31+
32+
/** @AfterScenario */
33+
public function tearDownScenario() {
34+
}
35+
36+
/**
37+
* @When /^user "([^"]*)" converts file "([^"]*)" to "([^"]*)"$/
38+
*/
39+
public function userConvertsTheSavedFileId(string $user, string $path, string $mime) {
40+
$this->userConvertsTheSavedFileIdTo($user, $path, $mime, null);
41+
42+
}
43+
44+
/**
45+
* @When /^user "([^"]*)" converts file "([^"]*)" to "([^"]*)" as "([^"]*)"$/
46+
*/
47+
public function userConvertsTheSavedFileIdTo(string $user, string $path, string $mime, ?string $destination) {
48+
$fileId = $this->getFileIdForPath($user, $path);
49+
$body = new TableNode([['fileId', $fileId], ['mime', $mime], ['destination', $destination]]);
50+
$this->sendingToWith('post', "/ocs/v2.php/apps/files/api/v1/convert", $body);
51+
}
52+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: AGPL-3.0-only
3+
4+
Feature: conversions
5+
Background:
6+
Given using api version "1"
7+
Given using new dav path
8+
Given user "user0" exists
9+
10+
Scenario: Converting a file works
11+
Given user "user0" uploads file "data/clouds.jpg" to "/clouds.jpg"
12+
Then as "user0" the file "/clouds.jpg" exists
13+
When user "user0" converts file "/clouds.jpg" to "image/png"
14+
Then the HTTP status code should be "200"
15+
Then the OCS status code should be "200"
16+
Then as "user0" the file "/clouds.png" exists

0 commit comments

Comments
 (0)