Completed
Push — master ( 8e04af...dc97bc )
by John
36:14 queued 10s
created
apps/files_reminders/lib/Controller/ApiController.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -25,111 +25,111 @@
 block discarded – undo
25 25
 use Psr\Log\LoggerInterface;
26 26
 
27 27
 class ApiController extends OCSController {
28
-	public function __construct(
29
-		string $appName,
30
-		IRequest $request,
31
-		protected ReminderService $reminderService,
32
-		protected IUserSession $userSession,
33
-		protected LoggerInterface $logger,
34
-	) {
35
-		parent::__construct($appName, $request);
36
-	}
28
+    public function __construct(
29
+        string $appName,
30
+        IRequest $request,
31
+        protected ReminderService $reminderService,
32
+        protected IUserSession $userSession,
33
+        protected LoggerInterface $logger,
34
+    ) {
35
+        parent::__construct($appName, $request);
36
+    }
37 37
 
38
-	/**
39
-	 * Get a reminder
40
-	 *
41
-	 * @param int $fileId ID of the file
42
-	 * @return DataResponse<Http::STATUS_OK, array{dueDate: ?string}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, list<empty>, array{}>
43
-	 *
44
-	 * 200: Reminder returned
45
-	 * 401: Account not found
46
-	 */
47
-	#[NoAdminRequired]
48
-	public function get(int $fileId): DataResponse {
49
-		$user = $this->userSession->getUser();
50
-		if ($user === null) {
51
-			return new DataResponse([], Http::STATUS_UNAUTHORIZED);
52
-		}
38
+    /**
39
+     * Get a reminder
40
+     *
41
+     * @param int $fileId ID of the file
42
+     * @return DataResponse<Http::STATUS_OK, array{dueDate: ?string}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, list<empty>, array{}>
43
+     *
44
+     * 200: Reminder returned
45
+     * 401: Account not found
46
+     */
47
+    #[NoAdminRequired]
48
+    public function get(int $fileId): DataResponse {
49
+        $user = $this->userSession->getUser();
50
+        if ($user === null) {
51
+            return new DataResponse([], Http::STATUS_UNAUTHORIZED);
52
+        }
53 53
 
54
-		try {
55
-			$reminder = $this->reminderService->getDueForUser($user, $fileId);
56
-			if ($reminder === null) {
57
-				return new DataResponse(['dueDate' => null], Http::STATUS_OK);
58
-			}
59
-			return new DataResponse([
60
-				'dueDate' => $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601
61
-			], Http::STATUS_OK);
62
-		} catch (NodeNotFoundException $e) {
63
-			return new DataResponse(['dueDate' => null], Http::STATUS_OK);
64
-		}
65
-	}
54
+        try {
55
+            $reminder = $this->reminderService->getDueForUser($user, $fileId);
56
+            if ($reminder === null) {
57
+                return new DataResponse(['dueDate' => null], Http::STATUS_OK);
58
+            }
59
+            return new DataResponse([
60
+                'dueDate' => $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601
61
+            ], Http::STATUS_OK);
62
+        } catch (NodeNotFoundException $e) {
63
+            return new DataResponse(['dueDate' => null], Http::STATUS_OK);
64
+        }
65
+    }
66 66
 
67
-	/**
68
-	 * Set a reminder
69
-	 *
70
-	 * @param int $fileId ID of the file
71
-	 * @param string $dueDate ISO 8601 formatted date time string
72
-	 *
73
-	 * @return DataResponse<Http::STATUS_OK|Http::STATUS_CREATED|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, list<empty>, array{}>
74
-	 *
75
-	 * 200: Reminder updated
76
-	 * 201: Reminder created successfully
77
-	 * 400: Creating reminder is not possible
78
-	 * 401: Account not found
79
-	 * 404: File not found
80
-	 */
81
-	#[NoAdminRequired]
82
-	public function set(int $fileId, string $dueDate): DataResponse {
83
-		try {
84
-			$dueDate = (new DateTime($dueDate))->setTimezone(new DateTimeZone('UTC'));
85
-			$nowDate = (new DateTime('now'))->setTimezone(new DateTimeZone('UTC'));
86
-			if ($dueDate <= $nowDate) {
87
-				return new DataResponse([], Http::STATUS_BAD_REQUEST);
88
-			}
89
-		} catch (Exception $e) {
90
-			$this->logger->error($e->getMessage(), ['exception' => $e]);
91
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
92
-		}
67
+    /**
68
+     * Set a reminder
69
+     *
70
+     * @param int $fileId ID of the file
71
+     * @param string $dueDate ISO 8601 formatted date time string
72
+     *
73
+     * @return DataResponse<Http::STATUS_OK|Http::STATUS_CREATED|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, list<empty>, array{}>
74
+     *
75
+     * 200: Reminder updated
76
+     * 201: Reminder created successfully
77
+     * 400: Creating reminder is not possible
78
+     * 401: Account not found
79
+     * 404: File not found
80
+     */
81
+    #[NoAdminRequired]
82
+    public function set(int $fileId, string $dueDate): DataResponse {
83
+        try {
84
+            $dueDate = (new DateTime($dueDate))->setTimezone(new DateTimeZone('UTC'));
85
+            $nowDate = (new DateTime('now'))->setTimezone(new DateTimeZone('UTC'));
86
+            if ($dueDate <= $nowDate) {
87
+                return new DataResponse([], Http::STATUS_BAD_REQUEST);
88
+            }
89
+        } catch (Exception $e) {
90
+            $this->logger->error($e->getMessage(), ['exception' => $e]);
91
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
92
+        }
93 93
 
94
-		$user = $this->userSession->getUser();
95
-		if ($user === null) {
96
-			return new DataResponse([], Http::STATUS_UNAUTHORIZED);
97
-		}
94
+        $user = $this->userSession->getUser();
95
+        if ($user === null) {
96
+            return new DataResponse([], Http::STATUS_UNAUTHORIZED);
97
+        }
98 98
 
99
-		try {
100
-			$created = $this->reminderService->createOrUpdate($user, $fileId, $dueDate);
101
-			if ($created) {
102
-				return new DataResponse([], Http::STATUS_CREATED);
103
-			}
104
-			return new DataResponse([], Http::STATUS_OK);
105
-		} catch (NodeNotFoundException $e) {
106
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
107
-		}
108
-	}
99
+        try {
100
+            $created = $this->reminderService->createOrUpdate($user, $fileId, $dueDate);
101
+            if ($created) {
102
+                return new DataResponse([], Http::STATUS_CREATED);
103
+            }
104
+            return new DataResponse([], Http::STATUS_OK);
105
+        } catch (NodeNotFoundException $e) {
106
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
107
+        }
108
+    }
109 109
 
110
-	/**
111
-	 * Remove a reminder
112
-	 *
113
-	 * @param int $fileId ID of the file
114
-	 *
115
-	 * @return DataResponse<Http::STATUS_OK|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, list<empty>, array{}>
116
-	 *
117
-	 * 200: Reminder deleted successfully
118
-	 * 401: Account not found
119
-	 * 404: Reminder not found
120
-	 */
121
-	#[NoAdminRequired]
122
-	public function remove(int $fileId): DataResponse {
123
-		$user = $this->userSession->getUser();
124
-		if ($user === null) {
125
-			return new DataResponse([], Http::STATUS_UNAUTHORIZED);
126
-		}
110
+    /**
111
+     * Remove a reminder
112
+     *
113
+     * @param int $fileId ID of the file
114
+     *
115
+     * @return DataResponse<Http::STATUS_OK|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, list<empty>, array{}>
116
+     *
117
+     * 200: Reminder deleted successfully
118
+     * 401: Account not found
119
+     * 404: Reminder not found
120
+     */
121
+    #[NoAdminRequired]
122
+    public function remove(int $fileId): DataResponse {
123
+        $user = $this->userSession->getUser();
124
+        if ($user === null) {
125
+            return new DataResponse([], Http::STATUS_UNAUTHORIZED);
126
+        }
127 127
 
128
-		try {
129
-			$this->reminderService->remove($user, $fileId);
130
-			return new DataResponse([], Http::STATUS_OK);
131
-		} catch (NodeNotFoundException|ReminderNotFoundException $e) {
132
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
133
-		}
134
-	}
128
+        try {
129
+            $this->reminderService->remove($user, $fileId);
130
+            return new DataResponse([], Http::STATUS_OK);
131
+        } catch (NodeNotFoundException|ReminderNotFoundException $e) {
132
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
133
+        }
134
+    }
135 135
 }
Please login to merge, or discard this patch.
build/integration/features/bootstrap/BasicStructure.php 2 patches
Indentation   +552 added lines, -552 removed lines patch added patch discarded remove patch
@@ -16,556 +16,556 @@
 block discarded – undo
16 16
 require __DIR__ . '/../../vendor/autoload.php';
17 17
 
18 18
 trait BasicStructure {
19
-	use Auth;
20
-	use Avatar;
21
-	use Download;
22
-	use Mail;
23
-	use Theming;
24
-
25
-	/** @var string */
26
-	private $currentUser = '';
27
-
28
-	/** @var string */
29
-	private $currentServer = '';
30
-
31
-	/** @var string */
32
-	private $baseUrl = '';
33
-
34
-	/** @var int */
35
-	private $apiVersion = 1;
36
-
37
-	/** @var ResponseInterface */
38
-	private $response = null;
39
-
40
-	/** @var CookieJar */
41
-	private $cookieJar;
42
-
43
-	/** @var string */
44
-	private $requestToken;
45
-
46
-	protected $adminUser;
47
-	protected $regularUser;
48
-	protected $localBaseUrl;
49
-	protected $remoteBaseUrl;
50
-
51
-	public function __construct($baseUrl, $admin, $regular_user_password) {
52
-		// Initialize your context here
53
-		$this->baseUrl = $baseUrl;
54
-		$this->adminUser = $admin;
55
-		$this->regularUser = $regular_user_password;
56
-		$this->localBaseUrl = $this->baseUrl;
57
-		$this->remoteBaseUrl = $this->baseUrl;
58
-		$this->currentServer = 'LOCAL';
59
-		$this->cookieJar = new CookieJar();
60
-
61
-		// in case of ci deployment we take the server url from the environment
62
-		$testServerUrl = getenv('TEST_SERVER_URL');
63
-		if ($testServerUrl !== false) {
64
-			$this->baseUrl = $testServerUrl;
65
-			$this->localBaseUrl = $testServerUrl;
66
-		}
67
-
68
-		// federated server url from the environment
69
-		$testRemoteServerUrl = getenv('TEST_SERVER_FED_URL');
70
-		if ($testRemoteServerUrl !== false) {
71
-			$this->remoteBaseUrl = $testRemoteServerUrl;
72
-		}
73
-	}
74
-
75
-	/**
76
-	 * @Given /^using api version "(\d+)"$/
77
-	 * @param string $version
78
-	 */
79
-	public function usingApiVersion($version) {
80
-		$this->apiVersion = (int)$version;
81
-	}
82
-
83
-	/**
84
-	 * @Given /^As an "([^"]*)"$/
85
-	 * @param string $user
86
-	 */
87
-	public function asAn($user) {
88
-		$this->currentUser = $user;
89
-	}
90
-
91
-	/**
92
-	 * @Given /^Using server "(LOCAL|REMOTE)"$/
93
-	 * @param string $server
94
-	 * @return string Previous used server
95
-	 */
96
-	public function usingServer($server) {
97
-		$previousServer = $this->currentServer;
98
-		if ($server === 'LOCAL') {
99
-			$this->baseUrl = $this->localBaseUrl;
100
-			$this->currentServer = 'LOCAL';
101
-			return $previousServer;
102
-		} else {
103
-			$this->baseUrl = $this->remoteBaseUrl;
104
-			$this->currentServer = 'REMOTE';
105
-			return $previousServer;
106
-		}
107
-	}
108
-
109
-	/**
110
-	 * @When /^sending "([^"]*)" to "([^"]*)"$/
111
-	 * @param string $verb
112
-	 * @param string $url
113
-	 */
114
-	public function sendingTo($verb, $url) {
115
-		$this->sendingToWith($verb, $url, null);
116
-	}
117
-
118
-	/**
119
-	 * Parses the xml or json answer to get ocs response which doesn't match with
120
-	 * http one in v1 of the api.
121
-	 *
122
-	 * @param ResponseInterface $response
123
-	 * @return string
124
-	 */
125
-	public function getOCSResponseCode($response): int {
126
-		if ($response === null) {
127
-			throw new \RuntimeException('No response available');
128
-		}
129
-
130
-		$body = (string)$response->getBody();
131
-		if (str_starts_with($body, '<')) {
132
-			$body = simplexml_load_string($body);
133
-			if ($body === false) {
134
-				throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
135
-			}
136
-			return (int)$body->meta[0]->statuscode;
137
-		}
138
-
139
-		return json_decode($body, true)['ocs']['meta']['statuscode'];
140
-	}
141
-
142
-	/**
143
-	 * This function is needed to use a vertical fashion in the gherkin tables.
144
-	 *
145
-	 * @param array $arrayOfArrays
146
-	 * @return array
147
-	 */
148
-	public function simplifyArray($arrayOfArrays) {
149
-		$a = array_map(function ($subArray) {
150
-			return $subArray[0];
151
-		}, $arrayOfArrays);
152
-		return $a;
153
-	}
154
-
155
-	/**
156
-	 * @When /^sending "([^"]*)" to "([^"]*)" with$/
157
-	 * @param string $verb
158
-	 * @param string $url
159
-	 * @param TableNode $body
160
-	 */
161
-	public function sendingToWith($verb, $url, $body) {
162
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url;
163
-		$client = new Client();
164
-		$options = [];
165
-		if ($this->currentUser === 'admin') {
166
-			$options['auth'] = $this->adminUser;
167
-		} elseif (strpos($this->currentUser, 'anonymous') !== 0) {
168
-			$options['auth'] = [$this->currentUser, $this->regularUser];
169
-		}
170
-		$options['headers'] = [
171
-			'OCS-APIRequest' => 'true'
172
-		];
173
-		if ($body instanceof TableNode) {
174
-			$fd = $body->getRowsHash();
175
-			$options['form_params'] = $fd;
176
-		}
177
-
178
-		// TODO: Fix this hack!
179
-		if ($verb === 'PUT' && $body === null) {
180
-			$options['form_params'] = [
181
-				'foo' => 'bar',
182
-			];
183
-		}
184
-
185
-		try {
186
-			$this->response = $client->request($verb, $fullUrl, $options);
187
-		} catch (ClientException $ex) {
188
-			$this->response = $ex->getResponse();
189
-		} catch (ServerException $ex) {
190
-			$this->response = $ex->getResponse();
191
-		}
192
-	}
193
-
194
-	/**
195
-	 * @param string $verb
196
-	 * @param string $url
197
-	 * @param TableNode|array|null $body
198
-	 * @param array $headers
199
-	 */
200
-	protected function sendRequestForJSON(string $verb, string $url, $body = null, array $headers = []): void {
201
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url;
202
-		$client = new Client();
203
-		$options = [];
204
-		if ($this->currentUser === 'admin') {
205
-			$options['auth'] = ['admin', 'admin'];
206
-		} elseif (strpos($this->currentUser, 'anonymous') !== 0) {
207
-			$options['auth'] = [$this->currentUser, $this->regularUser];
208
-		}
209
-		if ($body instanceof TableNode) {
210
-			$fd = $body->getRowsHash();
211
-			$options['form_params'] = $fd;
212
-		} elseif (is_array($body)) {
213
-			$options['form_params'] = $body;
214
-		}
215
-
216
-		$options['headers'] = array_merge($headers, [
217
-			'OCS-ApiRequest' => 'true',
218
-			'Accept' => 'application/json',
219
-		]);
220
-
221
-		try {
222
-			$this->response = $client->{$verb}($fullUrl, $options);
223
-		} catch (ClientException $ex) {
224
-			$this->response = $ex->getResponse();
225
-		}
226
-	}
227
-
228
-	/**
229
-	 * @When /^sending "([^"]*)" with exact url to "([^"]*)"$/
230
-	 * @param string $verb
231
-	 * @param string $url
232
-	 */
233
-	public function sendingToDirectUrl($verb, $url) {
234
-		$this->sendingToWithDirectUrl($verb, $url, null);
235
-	}
236
-
237
-	public function sendingToWithDirectUrl($verb, $url, $body) {
238
-		$fullUrl = substr($this->baseUrl, 0, -5) . $url;
239
-		$client = new Client();
240
-		$options = [];
241
-		if ($this->currentUser === 'admin') {
242
-			$options['auth'] = $this->adminUser;
243
-		} elseif (strpos($this->currentUser, 'anonymous') !== 0) {
244
-			$options['auth'] = [$this->currentUser, $this->regularUser];
245
-		}
246
-		if ($body instanceof TableNode) {
247
-			$fd = $body->getRowsHash();
248
-			$options['form_params'] = $fd;
249
-		}
250
-
251
-		try {
252
-			$this->response = $client->request($verb, $fullUrl, $options);
253
-		} catch (ClientException $ex) {
254
-			$this->response = $ex->getResponse();
255
-		}
256
-	}
257
-
258
-	public function isExpectedUrl($possibleUrl, $finalPart) {
259
-		$baseUrlChopped = substr($this->baseUrl, 0, -4);
260
-		$endCharacter = strlen($baseUrlChopped) + strlen($finalPart);
261
-		return (substr($possibleUrl, 0, $endCharacter) == "$baseUrlChopped" . "$finalPart");
262
-	}
263
-
264
-	/**
265
-	 * @Then /^the OCS status code should be "([^"]*)"$/
266
-	 * @param int $statusCode
267
-	 */
268
-	public function theOCSStatusCodeShouldBe($statusCode) {
269
-		Assert::assertEquals($statusCode, $this->getOCSResponseCode($this->response));
270
-	}
271
-
272
-	/**
273
-	 * @Then /^the HTTP status code should be "([^"]*)"$/
274
-	 * @param int $statusCode
275
-	 */
276
-	public function theHTTPStatusCodeShouldBe($statusCode) {
277
-		Assert::assertEquals($statusCode, $this->response->getStatusCode());
278
-	}
279
-
280
-	/**
281
-	 * @Then /^the Content-Type should be "([^"]*)"$/
282
-	 * @param string $contentType
283
-	 */
284
-	public function theContentTypeShouldbe($contentType) {
285
-		Assert::assertEquals($contentType, $this->response->getHeader('Content-Type')[0]);
286
-	}
287
-
288
-	/**
289
-	 * @param ResponseInterface $response
290
-	 */
291
-	private function extracRequestTokenFromResponse(ResponseInterface $response) {
292
-		$this->requestToken = substr(preg_replace('/(.*)data-requesttoken="(.*)">(.*)/sm', '\2', $response->getBody()->getContents()), 0, 89);
293
-	}
294
-
295
-	/**
296
-	 * @Given Logging in using web as :user
297
-	 * @param string $user
298
-	 */
299
-	public function loggingInUsingWebAs($user) {
300
-		$baseUrl = substr($this->baseUrl, 0, -5);
301
-		$loginUrl = $baseUrl . '/index.php/login';
302
-		// Request a new session and extract CSRF token
303
-		$client = new Client();
304
-		$response = $client->get(
305
-			$loginUrl,
306
-			[
307
-				'cookies' => $this->cookieJar,
308
-			]
309
-		);
310
-		$this->extracRequestTokenFromResponse($response);
311
-
312
-		// Login and extract new token
313
-		$password = ($user === 'admin') ? 'admin' : '123456';
314
-		$client = new Client();
315
-		$response = $client->post(
316
-			$loginUrl,
317
-			[
318
-				'form_params' => [
319
-					'user' => $user,
320
-					'password' => $password,
321
-					'requesttoken' => $this->requestToken,
322
-				],
323
-				'cookies' => $this->cookieJar,
324
-				'headers' => [
325
-					'Origin' => $baseUrl,
326
-				],
327
-			]
328
-		);
329
-		$this->extracRequestTokenFromResponse($response);
330
-	}
331
-
332
-	/**
333
-	 * @When Sending a :method to :url with requesttoken
334
-	 * @param string $method
335
-	 * @param string $url
336
-	 * @param TableNode|array|null $body
337
-	 */
338
-	public function sendingAToWithRequesttoken($method, $url, $body = null) {
339
-		$baseUrl = substr($this->baseUrl, 0, -5);
340
-
341
-		$options = [
342
-			'cookies' => $this->cookieJar,
343
-			'headers' => [
344
-				'requesttoken' => $this->requestToken
345
-			],
346
-		];
347
-
348
-		if ($body instanceof TableNode) {
349
-			$fd = $body->getRowsHash();
350
-			$options['form_params'] = $fd;
351
-		} elseif ($body) {
352
-			$options = array_merge_recursive($options, $body);
353
-		}
354
-
355
-		$client = new Client();
356
-		try {
357
-			$this->response = $client->request(
358
-				$method,
359
-				$baseUrl . $url,
360
-				$options
361
-			);
362
-		} catch (ClientException $e) {
363
-			$this->response = $e->getResponse();
364
-		}
365
-	}
366
-
367
-	/**
368
-	 * @When Sending a :method to :url without requesttoken
369
-	 * @param string $method
370
-	 * @param string $url
371
-	 */
372
-	public function sendingAToWithoutRequesttoken($method, $url) {
373
-		$baseUrl = substr($this->baseUrl, 0, -5);
374
-
375
-		$client = new Client();
376
-		try {
377
-			$this->response = $client->request(
378
-				$method,
379
-				$baseUrl . $url,
380
-				[
381
-					'cookies' => $this->cookieJar
382
-				]
383
-			);
384
-		} catch (ClientException $e) {
385
-			$this->response = $e->getResponse();
386
-		}
387
-	}
388
-
389
-	public static function removeFile($path, $filename) {
390
-		if (file_exists("$path" . "$filename")) {
391
-			unlink("$path" . "$filename");
392
-		}
393
-	}
394
-
395
-	/**
396
-	 * @Given User :user modifies text of :filename with text :text
397
-	 * @param string $user
398
-	 * @param string $filename
399
-	 * @param string $text
400
-	 */
401
-	public function modifyTextOfFile($user, $filename, $text) {
402
-		self::removeFile($this->getDataDirectory() . "/$user/files", "$filename");
403
-		file_put_contents($this->getDataDirectory() . "/$user/files" . "$filename", "$text");
404
-	}
405
-
406
-	private function getDataDirectory() {
407
-		// Based on "runOcc" from CommandLine trait
408
-		$args = ['config:system:get', 'datadirectory'];
409
-		$args = array_map(function ($arg) {
410
-			return escapeshellarg($arg);
411
-		}, $args);
412
-		$args[] = '--no-ansi --no-warnings';
413
-		$args = implode(' ', $args);
414
-
415
-		$descriptor = [
416
-			0 => ['pipe', 'r'],
417
-			1 => ['pipe', 'w'],
418
-			2 => ['pipe', 'w'],
419
-		];
420
-		$process = proc_open('php console.php ' . $args, $descriptor, $pipes, $ocPath = '../..');
421
-		$lastStdOut = stream_get_contents($pipes[1]);
422
-		proc_close($process);
423
-
424
-		return trim($lastStdOut);
425
-	}
426
-
427
-	/**
428
-	 * @Given file :filename is created :times times in :user user data
429
-	 * @param string $filename
430
-	 * @param string $times
431
-	 * @param string $user
432
-	 */
433
-	public function fileIsCreatedTimesInUserData($filename, $times, $user) {
434
-		for ($i = 0; $i < $times; $i++) {
435
-			file_put_contents($this->getDataDirectory() . "/$user/files" . "$filename-$i", "content-$i");
436
-		}
437
-	}
438
-
439
-	public function createFileSpecificSize($name, $size) {
440
-		$file = fopen('work/' . "$name", 'w');
441
-		fseek($file, $size - 1, SEEK_CUR);
442
-		fwrite($file, 'a'); // write a dummy char at SIZE position
443
-		fclose($file);
444
-	}
445
-
446
-	public function createFileWithText($name, $text) {
447
-		$file = fopen('work/' . "$name", 'w');
448
-		fwrite($file, $text);
449
-		fclose($file);
450
-	}
451
-
452
-	/**
453
-	 * @Given file :filename of size :size is created in local storage
454
-	 * @param string $filename
455
-	 * @param string $size
456
-	 */
457
-	public function fileIsCreatedInLocalStorageWithSize($filename, $size) {
458
-		$this->createFileSpecificSize("local_storage/$filename", $size);
459
-	}
460
-
461
-	/**
462
-	 * @Given file :filename with text :text is created in local storage
463
-	 * @param string $filename
464
-	 * @param string $text
465
-	 */
466
-	public function fileIsCreatedInLocalStorageWithText($filename, $text) {
467
-		$this->createFileWithText("local_storage/$filename", $text);
468
-	}
469
-
470
-	/**
471
-	 * @When Sleep for :seconds seconds
472
-	 * @param int $seconds
473
-	 */
474
-	public function sleepForSeconds($seconds) {
475
-		sleep((int)$seconds);
476
-	}
477
-
478
-	/**
479
-	 * @BeforeSuite
480
-	 */
481
-	public static function addFilesToSkeleton() {
482
-		for ($i = 0; $i < 5; $i++) {
483
-			file_put_contents('../../core/skeleton/' . 'textfile' . "$i" . '.txt', "Nextcloud test text file\n");
484
-		}
485
-		if (!file_exists('../../core/skeleton/FOLDER')) {
486
-			mkdir('../../core/skeleton/FOLDER', 0777, true);
487
-		}
488
-		if (!file_exists('../../core/skeleton/PARENT')) {
489
-			mkdir('../../core/skeleton/PARENT', 0777, true);
490
-		}
491
-		file_put_contents('../../core/skeleton/PARENT/' . 'parent.txt', "Nextcloud test text file\n");
492
-		if (!file_exists('../../core/skeleton/PARENT/CHILD')) {
493
-			mkdir('../../core/skeleton/PARENT/CHILD', 0777, true);
494
-		}
495
-		file_put_contents('../../core/skeleton/PARENT/CHILD/' . 'child.txt', "Nextcloud test text file\n");
496
-	}
497
-
498
-	/**
499
-	 * @AfterSuite
500
-	 */
501
-	public static function removeFilesFromSkeleton() {
502
-		for ($i = 0; $i < 5; $i++) {
503
-			self::removeFile('../../core/skeleton/', 'textfile' . "$i" . '.txt');
504
-		}
505
-		if (is_dir('../../core/skeleton/FOLDER')) {
506
-			rmdir('../../core/skeleton/FOLDER');
507
-		}
508
-		self::removeFile('../../core/skeleton/PARENT/CHILD/', 'child.txt');
509
-		if (is_dir('../../core/skeleton/PARENT/CHILD')) {
510
-			rmdir('../../core/skeleton/PARENT/CHILD');
511
-		}
512
-		self::removeFile('../../core/skeleton/PARENT/', 'parent.txt');
513
-		if (is_dir('../../core/skeleton/PARENT')) {
514
-			rmdir('../../core/skeleton/PARENT');
515
-		}
516
-	}
517
-
518
-	/**
519
-	 * @BeforeScenario @local_storage
520
-	 */
521
-	public static function removeFilesFromLocalStorageBefore() {
522
-		$dir = './work/local_storage/';
523
-		$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
524
-		$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
525
-		foreach ($ri as $file) {
526
-			$file->isDir() ? rmdir($file) : unlink($file);
527
-		}
528
-	}
529
-
530
-	/**
531
-	 * @AfterScenario @local_storage
532
-	 */
533
-	public static function removeFilesFromLocalStorageAfter() {
534
-		$dir = './work/local_storage/';
535
-		$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
536
-		$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
537
-		foreach ($ri as $file) {
538
-			$file->isDir() ? rmdir($file) : unlink($file);
539
-		}
540
-	}
541
-
542
-	/**
543
-	 * @Given /^cookies are reset$/
544
-	 */
545
-	public function cookiesAreReset() {
546
-		$this->cookieJar = new CookieJar();
547
-	}
548
-
549
-	/**
550
-	 * @Then The following headers should be set
551
-	 * @param TableNode $table
552
-	 * @throws \Exception
553
-	 */
554
-	public function theFollowingHeadersShouldBeSet(TableNode $table) {
555
-		foreach ($table->getTable() as $header) {
556
-			$headerName = $header[0];
557
-			$expectedHeaderValue = $header[1];
558
-			$returnedHeader = $this->response->getHeader($headerName)[0];
559
-			if ($returnedHeader !== $expectedHeaderValue) {
560
-				throw new \Exception(
561
-					sprintf(
562
-						"Expected value '%s' for header '%s', got '%s'",
563
-						$expectedHeaderValue,
564
-						$headerName,
565
-						$returnedHeader
566
-					)
567
-				);
568
-			}
569
-		}
570
-	}
19
+    use Auth;
20
+    use Avatar;
21
+    use Download;
22
+    use Mail;
23
+    use Theming;
24
+
25
+    /** @var string */
26
+    private $currentUser = '';
27
+
28
+    /** @var string */
29
+    private $currentServer = '';
30
+
31
+    /** @var string */
32
+    private $baseUrl = '';
33
+
34
+    /** @var int */
35
+    private $apiVersion = 1;
36
+
37
+    /** @var ResponseInterface */
38
+    private $response = null;
39
+
40
+    /** @var CookieJar */
41
+    private $cookieJar;
42
+
43
+    /** @var string */
44
+    private $requestToken;
45
+
46
+    protected $adminUser;
47
+    protected $regularUser;
48
+    protected $localBaseUrl;
49
+    protected $remoteBaseUrl;
50
+
51
+    public function __construct($baseUrl, $admin, $regular_user_password) {
52
+        // Initialize your context here
53
+        $this->baseUrl = $baseUrl;
54
+        $this->adminUser = $admin;
55
+        $this->regularUser = $regular_user_password;
56
+        $this->localBaseUrl = $this->baseUrl;
57
+        $this->remoteBaseUrl = $this->baseUrl;
58
+        $this->currentServer = 'LOCAL';
59
+        $this->cookieJar = new CookieJar();
60
+
61
+        // in case of ci deployment we take the server url from the environment
62
+        $testServerUrl = getenv('TEST_SERVER_URL');
63
+        if ($testServerUrl !== false) {
64
+            $this->baseUrl = $testServerUrl;
65
+            $this->localBaseUrl = $testServerUrl;
66
+        }
67
+
68
+        // federated server url from the environment
69
+        $testRemoteServerUrl = getenv('TEST_SERVER_FED_URL');
70
+        if ($testRemoteServerUrl !== false) {
71
+            $this->remoteBaseUrl = $testRemoteServerUrl;
72
+        }
73
+    }
74
+
75
+    /**
76
+     * @Given /^using api version "(\d+)"$/
77
+     * @param string $version
78
+     */
79
+    public function usingApiVersion($version) {
80
+        $this->apiVersion = (int)$version;
81
+    }
82
+
83
+    /**
84
+     * @Given /^As an "([^"]*)"$/
85
+     * @param string $user
86
+     */
87
+    public function asAn($user) {
88
+        $this->currentUser = $user;
89
+    }
90
+
91
+    /**
92
+     * @Given /^Using server "(LOCAL|REMOTE)"$/
93
+     * @param string $server
94
+     * @return string Previous used server
95
+     */
96
+    public function usingServer($server) {
97
+        $previousServer = $this->currentServer;
98
+        if ($server === 'LOCAL') {
99
+            $this->baseUrl = $this->localBaseUrl;
100
+            $this->currentServer = 'LOCAL';
101
+            return $previousServer;
102
+        } else {
103
+            $this->baseUrl = $this->remoteBaseUrl;
104
+            $this->currentServer = 'REMOTE';
105
+            return $previousServer;
106
+        }
107
+    }
108
+
109
+    /**
110
+     * @When /^sending "([^"]*)" to "([^"]*)"$/
111
+     * @param string $verb
112
+     * @param string $url
113
+     */
114
+    public function sendingTo($verb, $url) {
115
+        $this->sendingToWith($verb, $url, null);
116
+    }
117
+
118
+    /**
119
+     * Parses the xml or json answer to get ocs response which doesn't match with
120
+     * http one in v1 of the api.
121
+     *
122
+     * @param ResponseInterface $response
123
+     * @return string
124
+     */
125
+    public function getOCSResponseCode($response): int {
126
+        if ($response === null) {
127
+            throw new \RuntimeException('No response available');
128
+        }
129
+
130
+        $body = (string)$response->getBody();
131
+        if (str_starts_with($body, '<')) {
132
+            $body = simplexml_load_string($body);
133
+            if ($body === false) {
134
+                throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
135
+            }
136
+            return (int)$body->meta[0]->statuscode;
137
+        }
138
+
139
+        return json_decode($body, true)['ocs']['meta']['statuscode'];
140
+    }
141
+
142
+    /**
143
+     * This function is needed to use a vertical fashion in the gherkin tables.
144
+     *
145
+     * @param array $arrayOfArrays
146
+     * @return array
147
+     */
148
+    public function simplifyArray($arrayOfArrays) {
149
+        $a = array_map(function ($subArray) {
150
+            return $subArray[0];
151
+        }, $arrayOfArrays);
152
+        return $a;
153
+    }
154
+
155
+    /**
156
+     * @When /^sending "([^"]*)" to "([^"]*)" with$/
157
+     * @param string $verb
158
+     * @param string $url
159
+     * @param TableNode $body
160
+     */
161
+    public function sendingToWith($verb, $url, $body) {
162
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url;
163
+        $client = new Client();
164
+        $options = [];
165
+        if ($this->currentUser === 'admin') {
166
+            $options['auth'] = $this->adminUser;
167
+        } elseif (strpos($this->currentUser, 'anonymous') !== 0) {
168
+            $options['auth'] = [$this->currentUser, $this->regularUser];
169
+        }
170
+        $options['headers'] = [
171
+            'OCS-APIRequest' => 'true'
172
+        ];
173
+        if ($body instanceof TableNode) {
174
+            $fd = $body->getRowsHash();
175
+            $options['form_params'] = $fd;
176
+        }
177
+
178
+        // TODO: Fix this hack!
179
+        if ($verb === 'PUT' && $body === null) {
180
+            $options['form_params'] = [
181
+                'foo' => 'bar',
182
+            ];
183
+        }
184
+
185
+        try {
186
+            $this->response = $client->request($verb, $fullUrl, $options);
187
+        } catch (ClientException $ex) {
188
+            $this->response = $ex->getResponse();
189
+        } catch (ServerException $ex) {
190
+            $this->response = $ex->getResponse();
191
+        }
192
+    }
193
+
194
+    /**
195
+     * @param string $verb
196
+     * @param string $url
197
+     * @param TableNode|array|null $body
198
+     * @param array $headers
199
+     */
200
+    protected function sendRequestForJSON(string $verb, string $url, $body = null, array $headers = []): void {
201
+        $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url;
202
+        $client = new Client();
203
+        $options = [];
204
+        if ($this->currentUser === 'admin') {
205
+            $options['auth'] = ['admin', 'admin'];
206
+        } elseif (strpos($this->currentUser, 'anonymous') !== 0) {
207
+            $options['auth'] = [$this->currentUser, $this->regularUser];
208
+        }
209
+        if ($body instanceof TableNode) {
210
+            $fd = $body->getRowsHash();
211
+            $options['form_params'] = $fd;
212
+        } elseif (is_array($body)) {
213
+            $options['form_params'] = $body;
214
+        }
215
+
216
+        $options['headers'] = array_merge($headers, [
217
+            'OCS-ApiRequest' => 'true',
218
+            'Accept' => 'application/json',
219
+        ]);
220
+
221
+        try {
222
+            $this->response = $client->{$verb}($fullUrl, $options);
223
+        } catch (ClientException $ex) {
224
+            $this->response = $ex->getResponse();
225
+        }
226
+    }
227
+
228
+    /**
229
+     * @When /^sending "([^"]*)" with exact url to "([^"]*)"$/
230
+     * @param string $verb
231
+     * @param string $url
232
+     */
233
+    public function sendingToDirectUrl($verb, $url) {
234
+        $this->sendingToWithDirectUrl($verb, $url, null);
235
+    }
236
+
237
+    public function sendingToWithDirectUrl($verb, $url, $body) {
238
+        $fullUrl = substr($this->baseUrl, 0, -5) . $url;
239
+        $client = new Client();
240
+        $options = [];
241
+        if ($this->currentUser === 'admin') {
242
+            $options['auth'] = $this->adminUser;
243
+        } elseif (strpos($this->currentUser, 'anonymous') !== 0) {
244
+            $options['auth'] = [$this->currentUser, $this->regularUser];
245
+        }
246
+        if ($body instanceof TableNode) {
247
+            $fd = $body->getRowsHash();
248
+            $options['form_params'] = $fd;
249
+        }
250
+
251
+        try {
252
+            $this->response = $client->request($verb, $fullUrl, $options);
253
+        } catch (ClientException $ex) {
254
+            $this->response = $ex->getResponse();
255
+        }
256
+    }
257
+
258
+    public function isExpectedUrl($possibleUrl, $finalPart) {
259
+        $baseUrlChopped = substr($this->baseUrl, 0, -4);
260
+        $endCharacter = strlen($baseUrlChopped) + strlen($finalPart);
261
+        return (substr($possibleUrl, 0, $endCharacter) == "$baseUrlChopped" . "$finalPart");
262
+    }
263
+
264
+    /**
265
+     * @Then /^the OCS status code should be "([^"]*)"$/
266
+     * @param int $statusCode
267
+     */
268
+    public function theOCSStatusCodeShouldBe($statusCode) {
269
+        Assert::assertEquals($statusCode, $this->getOCSResponseCode($this->response));
270
+    }
271
+
272
+    /**
273
+     * @Then /^the HTTP status code should be "([^"]*)"$/
274
+     * @param int $statusCode
275
+     */
276
+    public function theHTTPStatusCodeShouldBe($statusCode) {
277
+        Assert::assertEquals($statusCode, $this->response->getStatusCode());
278
+    }
279
+
280
+    /**
281
+     * @Then /^the Content-Type should be "([^"]*)"$/
282
+     * @param string $contentType
283
+     */
284
+    public function theContentTypeShouldbe($contentType) {
285
+        Assert::assertEquals($contentType, $this->response->getHeader('Content-Type')[0]);
286
+    }
287
+
288
+    /**
289
+     * @param ResponseInterface $response
290
+     */
291
+    private function extracRequestTokenFromResponse(ResponseInterface $response) {
292
+        $this->requestToken = substr(preg_replace('/(.*)data-requesttoken="(.*)">(.*)/sm', '\2', $response->getBody()->getContents()), 0, 89);
293
+    }
294
+
295
+    /**
296
+     * @Given Logging in using web as :user
297
+     * @param string $user
298
+     */
299
+    public function loggingInUsingWebAs($user) {
300
+        $baseUrl = substr($this->baseUrl, 0, -5);
301
+        $loginUrl = $baseUrl . '/index.php/login';
302
+        // Request a new session and extract CSRF token
303
+        $client = new Client();
304
+        $response = $client->get(
305
+            $loginUrl,
306
+            [
307
+                'cookies' => $this->cookieJar,
308
+            ]
309
+        );
310
+        $this->extracRequestTokenFromResponse($response);
311
+
312
+        // Login and extract new token
313
+        $password = ($user === 'admin') ? 'admin' : '123456';
314
+        $client = new Client();
315
+        $response = $client->post(
316
+            $loginUrl,
317
+            [
318
+                'form_params' => [
319
+                    'user' => $user,
320
+                    'password' => $password,
321
+                    'requesttoken' => $this->requestToken,
322
+                ],
323
+                'cookies' => $this->cookieJar,
324
+                'headers' => [
325
+                    'Origin' => $baseUrl,
326
+                ],
327
+            ]
328
+        );
329
+        $this->extracRequestTokenFromResponse($response);
330
+    }
331
+
332
+    /**
333
+     * @When Sending a :method to :url with requesttoken
334
+     * @param string $method
335
+     * @param string $url
336
+     * @param TableNode|array|null $body
337
+     */
338
+    public function sendingAToWithRequesttoken($method, $url, $body = null) {
339
+        $baseUrl = substr($this->baseUrl, 0, -5);
340
+
341
+        $options = [
342
+            'cookies' => $this->cookieJar,
343
+            'headers' => [
344
+                'requesttoken' => $this->requestToken
345
+            ],
346
+        ];
347
+
348
+        if ($body instanceof TableNode) {
349
+            $fd = $body->getRowsHash();
350
+            $options['form_params'] = $fd;
351
+        } elseif ($body) {
352
+            $options = array_merge_recursive($options, $body);
353
+        }
354
+
355
+        $client = new Client();
356
+        try {
357
+            $this->response = $client->request(
358
+                $method,
359
+                $baseUrl . $url,
360
+                $options
361
+            );
362
+        } catch (ClientException $e) {
363
+            $this->response = $e->getResponse();
364
+        }
365
+    }
366
+
367
+    /**
368
+     * @When Sending a :method to :url without requesttoken
369
+     * @param string $method
370
+     * @param string $url
371
+     */
372
+    public function sendingAToWithoutRequesttoken($method, $url) {
373
+        $baseUrl = substr($this->baseUrl, 0, -5);
374
+
375
+        $client = new Client();
376
+        try {
377
+            $this->response = $client->request(
378
+                $method,
379
+                $baseUrl . $url,
380
+                [
381
+                    'cookies' => $this->cookieJar
382
+                ]
383
+            );
384
+        } catch (ClientException $e) {
385
+            $this->response = $e->getResponse();
386
+        }
387
+    }
388
+
389
+    public static function removeFile($path, $filename) {
390
+        if (file_exists("$path" . "$filename")) {
391
+            unlink("$path" . "$filename");
392
+        }
393
+    }
394
+
395
+    /**
396
+     * @Given User :user modifies text of :filename with text :text
397
+     * @param string $user
398
+     * @param string $filename
399
+     * @param string $text
400
+     */
401
+    public function modifyTextOfFile($user, $filename, $text) {
402
+        self::removeFile($this->getDataDirectory() . "/$user/files", "$filename");
403
+        file_put_contents($this->getDataDirectory() . "/$user/files" . "$filename", "$text");
404
+    }
405
+
406
+    private function getDataDirectory() {
407
+        // Based on "runOcc" from CommandLine trait
408
+        $args = ['config:system:get', 'datadirectory'];
409
+        $args = array_map(function ($arg) {
410
+            return escapeshellarg($arg);
411
+        }, $args);
412
+        $args[] = '--no-ansi --no-warnings';
413
+        $args = implode(' ', $args);
414
+
415
+        $descriptor = [
416
+            0 => ['pipe', 'r'],
417
+            1 => ['pipe', 'w'],
418
+            2 => ['pipe', 'w'],
419
+        ];
420
+        $process = proc_open('php console.php ' . $args, $descriptor, $pipes, $ocPath = '../..');
421
+        $lastStdOut = stream_get_contents($pipes[1]);
422
+        proc_close($process);
423
+
424
+        return trim($lastStdOut);
425
+    }
426
+
427
+    /**
428
+     * @Given file :filename is created :times times in :user user data
429
+     * @param string $filename
430
+     * @param string $times
431
+     * @param string $user
432
+     */
433
+    public function fileIsCreatedTimesInUserData($filename, $times, $user) {
434
+        for ($i = 0; $i < $times; $i++) {
435
+            file_put_contents($this->getDataDirectory() . "/$user/files" . "$filename-$i", "content-$i");
436
+        }
437
+    }
438
+
439
+    public function createFileSpecificSize($name, $size) {
440
+        $file = fopen('work/' . "$name", 'w');
441
+        fseek($file, $size - 1, SEEK_CUR);
442
+        fwrite($file, 'a'); // write a dummy char at SIZE position
443
+        fclose($file);
444
+    }
445
+
446
+    public function createFileWithText($name, $text) {
447
+        $file = fopen('work/' . "$name", 'w');
448
+        fwrite($file, $text);
449
+        fclose($file);
450
+    }
451
+
452
+    /**
453
+     * @Given file :filename of size :size is created in local storage
454
+     * @param string $filename
455
+     * @param string $size
456
+     */
457
+    public function fileIsCreatedInLocalStorageWithSize($filename, $size) {
458
+        $this->createFileSpecificSize("local_storage/$filename", $size);
459
+    }
460
+
461
+    /**
462
+     * @Given file :filename with text :text is created in local storage
463
+     * @param string $filename
464
+     * @param string $text
465
+     */
466
+    public function fileIsCreatedInLocalStorageWithText($filename, $text) {
467
+        $this->createFileWithText("local_storage/$filename", $text);
468
+    }
469
+
470
+    /**
471
+     * @When Sleep for :seconds seconds
472
+     * @param int $seconds
473
+     */
474
+    public function sleepForSeconds($seconds) {
475
+        sleep((int)$seconds);
476
+    }
477
+
478
+    /**
479
+     * @BeforeSuite
480
+     */
481
+    public static function addFilesToSkeleton() {
482
+        for ($i = 0; $i < 5; $i++) {
483
+            file_put_contents('../../core/skeleton/' . 'textfile' . "$i" . '.txt', "Nextcloud test text file\n");
484
+        }
485
+        if (!file_exists('../../core/skeleton/FOLDER')) {
486
+            mkdir('../../core/skeleton/FOLDER', 0777, true);
487
+        }
488
+        if (!file_exists('../../core/skeleton/PARENT')) {
489
+            mkdir('../../core/skeleton/PARENT', 0777, true);
490
+        }
491
+        file_put_contents('../../core/skeleton/PARENT/' . 'parent.txt', "Nextcloud test text file\n");
492
+        if (!file_exists('../../core/skeleton/PARENT/CHILD')) {
493
+            mkdir('../../core/skeleton/PARENT/CHILD', 0777, true);
494
+        }
495
+        file_put_contents('../../core/skeleton/PARENT/CHILD/' . 'child.txt', "Nextcloud test text file\n");
496
+    }
497
+
498
+    /**
499
+     * @AfterSuite
500
+     */
501
+    public static function removeFilesFromSkeleton() {
502
+        for ($i = 0; $i < 5; $i++) {
503
+            self::removeFile('../../core/skeleton/', 'textfile' . "$i" . '.txt');
504
+        }
505
+        if (is_dir('../../core/skeleton/FOLDER')) {
506
+            rmdir('../../core/skeleton/FOLDER');
507
+        }
508
+        self::removeFile('../../core/skeleton/PARENT/CHILD/', 'child.txt');
509
+        if (is_dir('../../core/skeleton/PARENT/CHILD')) {
510
+            rmdir('../../core/skeleton/PARENT/CHILD');
511
+        }
512
+        self::removeFile('../../core/skeleton/PARENT/', 'parent.txt');
513
+        if (is_dir('../../core/skeleton/PARENT')) {
514
+            rmdir('../../core/skeleton/PARENT');
515
+        }
516
+    }
517
+
518
+    /**
519
+     * @BeforeScenario @local_storage
520
+     */
521
+    public static function removeFilesFromLocalStorageBefore() {
522
+        $dir = './work/local_storage/';
523
+        $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
524
+        $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
525
+        foreach ($ri as $file) {
526
+            $file->isDir() ? rmdir($file) : unlink($file);
527
+        }
528
+    }
529
+
530
+    /**
531
+     * @AfterScenario @local_storage
532
+     */
533
+    public static function removeFilesFromLocalStorageAfter() {
534
+        $dir = './work/local_storage/';
535
+        $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
536
+        $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
537
+        foreach ($ri as $file) {
538
+            $file->isDir() ? rmdir($file) : unlink($file);
539
+        }
540
+    }
541
+
542
+    /**
543
+     * @Given /^cookies are reset$/
544
+     */
545
+    public function cookiesAreReset() {
546
+        $this->cookieJar = new CookieJar();
547
+    }
548
+
549
+    /**
550
+     * @Then The following headers should be set
551
+     * @param TableNode $table
552
+     * @throws \Exception
553
+     */
554
+    public function theFollowingHeadersShouldBeSet(TableNode $table) {
555
+        foreach ($table->getTable() as $header) {
556
+            $headerName = $header[0];
557
+            $expectedHeaderValue = $header[1];
558
+            $returnedHeader = $this->response->getHeader($headerName)[0];
559
+            if ($returnedHeader !== $expectedHeaderValue) {
560
+                throw new \Exception(
561
+                    sprintf(
562
+                        "Expected value '%s' for header '%s', got '%s'",
563
+                        $expectedHeaderValue,
564
+                        $headerName,
565
+                        $returnedHeader
566
+                    )
567
+                );
568
+            }
569
+        }
570
+    }
571 571
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHPUnit\Framework\Assert;
14 14
 use Psr\Http\Message\ResponseInterface;
15 15
 
16
-require __DIR__ . '/../../vendor/autoload.php';
16
+require __DIR__.'/../../vendor/autoload.php';
17 17
 
18 18
 trait BasicStructure {
19 19
 	use Auth;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	 * @param string $version
78 78
 	 */
79 79
 	public function usingApiVersion($version) {
80
-		$this->apiVersion = (int)$version;
80
+		$this->apiVersion = (int) $version;
81 81
 	}
82 82
 
83 83
 	/**
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 			throw new \RuntimeException('No response available');
128 128
 		}
129 129
 
130
-		$body = (string)$response->getBody();
130
+		$body = (string) $response->getBody();
131 131
 		if (str_starts_with($body, '<')) {
132 132
 			$body = simplexml_load_string($body);
133 133
 			if ($body === false) {
134 134
 				throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
135 135
 			}
136
-			return (int)$body->meta[0]->statuscode;
136
+			return (int) $body->meta[0]->statuscode;
137 137
 		}
138 138
 
139 139
 		return json_decode($body, true)['ocs']['meta']['statuscode'];
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 * @return array
147 147
 	 */
148 148
 	public function simplifyArray($arrayOfArrays) {
149
-		$a = array_map(function ($subArray) {
149
+		$a = array_map(function($subArray) {
150 150
 			return $subArray[0];
151 151
 		}, $arrayOfArrays);
152 152
 		return $a;
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param TableNode $body
160 160
 	 */
161 161
 	public function sendingToWith($verb, $url, $body) {
162
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url;
162
+		$fullUrl = $this->baseUrl."v{$this->apiVersion}.php".$url;
163 163
 		$client = new Client();
164 164
 		$options = [];
165 165
 		if ($this->currentUser === 'admin') {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 * @param array $headers
199 199
 	 */
200 200
 	protected function sendRequestForJSON(string $verb, string $url, $body = null, array $headers = []): void {
201
-		$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php" . $url;
201
+		$fullUrl = $this->baseUrl."v{$this->apiVersion}.php".$url;
202 202
 		$client = new Client();
203 203
 		$options = [];
204 204
 		if ($this->currentUser === 'admin') {
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	}
236 236
 
237 237
 	public function sendingToWithDirectUrl($verb, $url, $body) {
238
-		$fullUrl = substr($this->baseUrl, 0, -5) . $url;
238
+		$fullUrl = substr($this->baseUrl, 0, -5).$url;
239 239
 		$client = new Client();
240 240
 		$options = [];
241 241
 		if ($this->currentUser === 'admin') {
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	public function isExpectedUrl($possibleUrl, $finalPart) {
259 259
 		$baseUrlChopped = substr($this->baseUrl, 0, -4);
260 260
 		$endCharacter = strlen($baseUrlChopped) + strlen($finalPart);
261
-		return (substr($possibleUrl, 0, $endCharacter) == "$baseUrlChopped" . "$finalPart");
261
+		return (substr($possibleUrl, 0, $endCharacter) == "$baseUrlChopped"."$finalPart");
262 262
 	}
263 263
 
264 264
 	/**
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	 */
299 299
 	public function loggingInUsingWebAs($user) {
300 300
 		$baseUrl = substr($this->baseUrl, 0, -5);
301
-		$loginUrl = $baseUrl . '/index.php/login';
301
+		$loginUrl = $baseUrl.'/index.php/login';
302 302
 		// Request a new session and extract CSRF token
303 303
 		$client = new Client();
304 304
 		$response = $client->get(
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		try {
357 357
 			$this->response = $client->request(
358 358
 				$method,
359
-				$baseUrl . $url,
359
+				$baseUrl.$url,
360 360
 				$options
361 361
 			);
362 362
 		} catch (ClientException $e) {
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 		try {
377 377
 			$this->response = $client->request(
378 378
 				$method,
379
-				$baseUrl . $url,
379
+				$baseUrl.$url,
380 380
 				[
381 381
 					'cookies' => $this->cookieJar
382 382
 				]
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 	}
388 388
 
389 389
 	public static function removeFile($path, $filename) {
390
-		if (file_exists("$path" . "$filename")) {
391
-			unlink("$path" . "$filename");
390
+		if (file_exists("$path"."$filename")) {
391
+			unlink("$path"."$filename");
392 392
 		}
393 393
 	}
394 394
 
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
 	 * @param string $text
400 400
 	 */
401 401
 	public function modifyTextOfFile($user, $filename, $text) {
402
-		self::removeFile($this->getDataDirectory() . "/$user/files", "$filename");
403
-		file_put_contents($this->getDataDirectory() . "/$user/files" . "$filename", "$text");
402
+		self::removeFile($this->getDataDirectory()."/$user/files", "$filename");
403
+		file_put_contents($this->getDataDirectory()."/$user/files"."$filename", "$text");
404 404
 	}
405 405
 
406 406
 	private function getDataDirectory() {
407 407
 		// Based on "runOcc" from CommandLine trait
408 408
 		$args = ['config:system:get', 'datadirectory'];
409
-		$args = array_map(function ($arg) {
409
+		$args = array_map(function($arg) {
410 410
 			return escapeshellarg($arg);
411 411
 		}, $args);
412 412
 		$args[] = '--no-ansi --no-warnings';
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 			1 => ['pipe', 'w'],
418 418
 			2 => ['pipe', 'w'],
419 419
 		];
420
-		$process = proc_open('php console.php ' . $args, $descriptor, $pipes, $ocPath = '../..');
420
+		$process = proc_open('php console.php '.$args, $descriptor, $pipes, $ocPath = '../..');
421 421
 		$lastStdOut = stream_get_contents($pipes[1]);
422 422
 		proc_close($process);
423 423
 
@@ -432,19 +432,19 @@  discard block
 block discarded – undo
432 432
 	 */
433 433
 	public function fileIsCreatedTimesInUserData($filename, $times, $user) {
434 434
 		for ($i = 0; $i < $times; $i++) {
435
-			file_put_contents($this->getDataDirectory() . "/$user/files" . "$filename-$i", "content-$i");
435
+			file_put_contents($this->getDataDirectory()."/$user/files"."$filename-$i", "content-$i");
436 436
 		}
437 437
 	}
438 438
 
439 439
 	public function createFileSpecificSize($name, $size) {
440
-		$file = fopen('work/' . "$name", 'w');
440
+		$file = fopen('work/'."$name", 'w');
441 441
 		fseek($file, $size - 1, SEEK_CUR);
442 442
 		fwrite($file, 'a'); // write a dummy char at SIZE position
443 443
 		fclose($file);
444 444
 	}
445 445
 
446 446
 	public function createFileWithText($name, $text) {
447
-		$file = fopen('work/' . "$name", 'w');
447
+		$file = fopen('work/'."$name", 'w');
448 448
 		fwrite($file, $text);
449 449
 		fclose($file);
450 450
 	}
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 	 * @param int $seconds
473 473
 	 */
474 474
 	public function sleepForSeconds($seconds) {
475
-		sleep((int)$seconds);
475
+		sleep((int) $seconds);
476 476
 	}
477 477
 
478 478
 	/**
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 */
481 481
 	public static function addFilesToSkeleton() {
482 482
 		for ($i = 0; $i < 5; $i++) {
483
-			file_put_contents('../../core/skeleton/' . 'textfile' . "$i" . '.txt', "Nextcloud test text file\n");
483
+			file_put_contents('../../core/skeleton/'.'textfile'."$i".'.txt', "Nextcloud test text file\n");
484 484
 		}
485 485
 		if (!file_exists('../../core/skeleton/FOLDER')) {
486 486
 			mkdir('../../core/skeleton/FOLDER', 0777, true);
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 		if (!file_exists('../../core/skeleton/PARENT')) {
489 489
 			mkdir('../../core/skeleton/PARENT', 0777, true);
490 490
 		}
491
-		file_put_contents('../../core/skeleton/PARENT/' . 'parent.txt', "Nextcloud test text file\n");
491
+		file_put_contents('../../core/skeleton/PARENT/'.'parent.txt', "Nextcloud test text file\n");
492 492
 		if (!file_exists('../../core/skeleton/PARENT/CHILD')) {
493 493
 			mkdir('../../core/skeleton/PARENT/CHILD', 0777, true);
494 494
 		}
495
-		file_put_contents('../../core/skeleton/PARENT/CHILD/' . 'child.txt', "Nextcloud test text file\n");
495
+		file_put_contents('../../core/skeleton/PARENT/CHILD/'.'child.txt', "Nextcloud test text file\n");
496 496
 	}
497 497
 
498 498
 	/**
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	 */
501 501
 	public static function removeFilesFromSkeleton() {
502 502
 		for ($i = 0; $i < 5; $i++) {
503
-			self::removeFile('../../core/skeleton/', 'textfile' . "$i" . '.txt');
503
+			self::removeFile('../../core/skeleton/', 'textfile'."$i".'.txt');
504 504
 		}
505 505
 		if (is_dir('../../core/skeleton/FOLDER')) {
506 506
 			rmdir('../../core/skeleton/FOLDER');
Please login to merge, or discard this patch.
build/integration/features/bootstrap/FilesRemindersContext.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -14,83 +14,83 @@
 block discarded – undo
14 14
  * Files reminders context.
15 15
  */
16 16
 class FilesRemindersContext implements Context {
17
-	use BasicStructure;
18
-	use WebDav;
17
+    use BasicStructure;
18
+    use WebDav;
19 19
 
20
-	/**
21
-	 * @When the user sets a reminder for :path with due date :dueDate
22
-	 */
23
-	public function settingAReminderForFileWithDueDate($path, $dueDate) {
24
-		$fileId = $this->getFileIdForPath($this->currentUser, $path);
25
-		$this->sendRequestForJSON(
26
-			'PUT',
27
-			'/apps/files_reminders/api/v1/' . $fileId,
28
-			['dueDate' => $dueDate],
29
-			['OCS-APIREQUEST' => 'true']
30
-		);
31
-	}
20
+    /**
21
+     * @When the user sets a reminder for :path with due date :dueDate
22
+     */
23
+    public function settingAReminderForFileWithDueDate($path, $dueDate) {
24
+        $fileId = $this->getFileIdForPath($this->currentUser, $path);
25
+        $this->sendRequestForJSON(
26
+            'PUT',
27
+            '/apps/files_reminders/api/v1/' . $fileId,
28
+            ['dueDate' => $dueDate],
29
+            ['OCS-APIREQUEST' => 'true']
30
+        );
31
+    }
32 32
 
33
-	/**
34
-	 * @Then the user sees the reminder for :path is set to :dueDate
35
-	 */
36
-	public function retrievingTheReminderForFile($path, $dueDate) {
37
-		$fileId = $this->getFileIdForPath($this->currentUser, $path);
38
-		$this->sendRequestForJSON(
39
-			'GET',
40
-			'/apps/files_reminders/api/v1/' . $fileId,
41
-			null,
42
-			['OCS-APIREQUEST' => 'true']
43
-		);
44
-		$response = $this->getDueDateFromOCSResponse();
45
-		Assert::assertEquals($dueDate, $response);
46
-	}
33
+    /**
34
+     * @Then the user sees the reminder for :path is set to :dueDate
35
+     */
36
+    public function retrievingTheReminderForFile($path, $dueDate) {
37
+        $fileId = $this->getFileIdForPath($this->currentUser, $path);
38
+        $this->sendRequestForJSON(
39
+            'GET',
40
+            '/apps/files_reminders/api/v1/' . $fileId,
41
+            null,
42
+            ['OCS-APIREQUEST' => 'true']
43
+        );
44
+        $response = $this->getDueDateFromOCSResponse();
45
+        Assert::assertEquals($dueDate, $response);
46
+    }
47 47
 
48
-	/**
49
-	 * @Then the user sees the reminder for :path is not set
50
-	 */
51
-	public function retrievingTheReminderForFileIsNotSet($path) {
52
-		$fileId = $this->getFileIdForPath($this->currentUser, $path);
53
-		$this->sendRequestForJSON(
54
-			'GET',
55
-			'/apps/files_reminders/api/v1/' . $fileId,
56
-			null,
57
-			['OCS-APIREQUEST' => 'true']
58
-		);
59
-		$response = $this->getDueDateFromOCSResponse();
60
-		Assert::assertNull($response);
61
-	}
48
+    /**
49
+     * @Then the user sees the reminder for :path is not set
50
+     */
51
+    public function retrievingTheReminderForFileIsNotSet($path) {
52
+        $fileId = $this->getFileIdForPath($this->currentUser, $path);
53
+        $this->sendRequestForJSON(
54
+            'GET',
55
+            '/apps/files_reminders/api/v1/' . $fileId,
56
+            null,
57
+            ['OCS-APIREQUEST' => 'true']
58
+        );
59
+        $response = $this->getDueDateFromOCSResponse();
60
+        Assert::assertNull($response);
61
+    }
62 62
 
63
-	/**
64
-	 * @When the user removes the reminder for :path
65
-	 */
66
-	public function removingTheReminderForFile($path) {
67
-		$fileId = $this->getFileIdForPath($this->currentUser, $path);
68
-		$this->sendRequestForJSON(
69
-			'DELETE',
70
-			'/apps/files_reminders/api/v1/' . $fileId,
71
-			null,
72
-			['OCS-APIREQUEST' => 'true']
73
-		);
74
-	}
63
+    /**
64
+     * @When the user removes the reminder for :path
65
+     */
66
+    public function removingTheReminderForFile($path) {
67
+        $fileId = $this->getFileIdForPath($this->currentUser, $path);
68
+        $this->sendRequestForJSON(
69
+            'DELETE',
70
+            '/apps/files_reminders/api/v1/' . $fileId,
71
+            null,
72
+            ['OCS-APIREQUEST' => 'true']
73
+        );
74
+    }
75 75
 
76
-	/**
77
-	 * Check the due date from OCS response
78
-	 */
79
-	private function getDueDateFromOCSResponse(): ?string {
80
-		if ($this->response === null) {
81
-			throw new \RuntimeException('No response available');
82
-		}
76
+    /**
77
+     * Check the due date from OCS response
78
+     */
79
+    private function getDueDateFromOCSResponse(): ?string {
80
+        if ($this->response === null) {
81
+            throw new \RuntimeException('No response available');
82
+        }
83 83
 
84
-		$body = (string)$this->response->getBody();
85
-		if (str_starts_with($body, '<')) {
86
-			$body = simplexml_load_string($body);
87
-			if ($body === false) {
88
-				throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
89
-			}
90
-			return $body->data->dueDate;
91
-		}
84
+        $body = (string)$this->response->getBody();
85
+        if (str_starts_with($body, '<')) {
86
+            $body = simplexml_load_string($body);
87
+            if ($body === false) {
88
+                throw new \RuntimeException('Could not parse OCS response, body is not valid XML');
89
+            }
90
+            return $body->data->dueDate;
91
+        }
92 92
 
93
-		$body = json_decode($body, true);
94
-		return $body['ocs']['data']['dueDate'] ?? null;
95
-	}
93
+        $body = json_decode($body, true);
94
+        return $body['ocs']['data']['dueDate'] ?? null;
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use Behat\Behat\Context\Context;
8 8
 use PHPUnit\Framework\Assert;
9 9
 
10
-require __DIR__ . '/../../vendor/autoload.php';
10
+require __DIR__.'/../../vendor/autoload.php';
11 11
 
12 12
 
13 13
 /**
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 		$fileId = $this->getFileIdForPath($this->currentUser, $path);
25 25
 		$this->sendRequestForJSON(
26 26
 			'PUT',
27
-			'/apps/files_reminders/api/v1/' . $fileId,
27
+			'/apps/files_reminders/api/v1/'.$fileId,
28 28
 			['dueDate' => $dueDate],
29 29
 			['OCS-APIREQUEST' => 'true']
30 30
 		);
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 		$fileId = $this->getFileIdForPath($this->currentUser, $path);
38 38
 		$this->sendRequestForJSON(
39 39
 			'GET',
40
-			'/apps/files_reminders/api/v1/' . $fileId,
40
+			'/apps/files_reminders/api/v1/'.$fileId,
41 41
 			null,
42 42
 			['OCS-APIREQUEST' => 'true']
43 43
 		);
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		$fileId = $this->getFileIdForPath($this->currentUser, $path);
53 53
 		$this->sendRequestForJSON(
54 54
 			'GET',
55
-			'/apps/files_reminders/api/v1/' . $fileId,
55
+			'/apps/files_reminders/api/v1/'.$fileId,
56 56
 			null,
57 57
 			['OCS-APIREQUEST' => 'true']
58 58
 		);
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		$fileId = $this->getFileIdForPath($this->currentUser, $path);
68 68
 		$this->sendRequestForJSON(
69 69
 			'DELETE',
70
-			'/apps/files_reminders/api/v1/' . $fileId,
70
+			'/apps/files_reminders/api/v1/'.$fileId,
71 71
 			null,
72 72
 			['OCS-APIREQUEST' => 'true']
73 73
 		);
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			throw new \RuntimeException('No response available');
82 82
 		}
83 83
 
84
-		$body = (string)$this->response->getBody();
84
+		$body = (string) $this->response->getBody();
85 85
 		if (str_starts_with($body, '<')) {
86 86
 			$body = simplexml_load_string($body);
87 87
 			if ($body === false) {
Please login to merge, or discard this patch.