aboutsummaryrefslogtreecommitdiffstats
path: root/build/integration/features/bootstrap/Theming.php
blob: f44a6533a1bdab696a53735e123dd9b5fb8f3eb1 (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
<?php

/**
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
require __DIR__ . '/../../vendor/autoload.php';

trait Theming {

	private bool $undoAllThemingChangesAfterScenario = false;

	/**
	 * @AfterScenario
	 */
	public function undoAllThemingChanges() {
		if (!$this->undoAllThemingChangesAfterScenario) {
			return;
		}

		$this->loggingInUsingWebAs('admin');
		$this->sendingAToWithRequesttoken('POST', '/index.php/apps/theming/ajax/undoAllChanges');

		$this->undoAllThemingChangesAfterScenario = false;
	}

	/**
	 * @When logged in admin uploads theming image for :key from file :source
	 *
	 * @param string $key
	 * @param string $source
	 */
	public function loggedInAdminUploadsThemingImageForFromFile(string $key, string $source) {
		$this->undoAllThemingChangesAfterScenario = true;

		$file = \GuzzleHttp\Psr7\Utils::streamFor(fopen($source, 'r'));

		$this->sendingAToWithRequesttoken('POST', '/index.php/apps/theming/ajax/uploadImage?key=' . $key,
			[
				'multipart' => [
					[
						'name' => 'image',
						'contents' => $file
					]
				]
			]);
		$this->theHTTPStatusCodeShouldBe('200');
	}
}