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

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;

trait Activity {
	use BasicStructure;

	/**
	 * @Then last activity should be
	 * @param TableNode $activity
	 */
	public function lastActivityIs(TableNode $activity): void {
		$this->sendRequestForJSON('GET', '/apps/activity/api/v2/activity');
		$this->theHTTPStatusCodeShouldBe('200');
		$data = json_decode($this->response->getBody()->getContents(), true);
		$activities = $data['ocs']['data'];
		/* Sort by id */
		uasort($activities, fn ($a, $b) => $a['activity_id'] <=> $b['activity_id']);
		$lastActivity = array_pop($activities);
		foreach ($activity->getRowsHash() as $key => $value) {
			Assert::assertEquals($value, $lastActivity[$key]);
		}
	}
}