summaryrefslogtreecommitdiffstats
path: root/build/integration/features/bootstrap
diff options
context:
space:
mode:
authorJonas Meurer <jonas@freesources.org>2021-10-19 10:56:07 +0200
committerJonas Meurer <jonas@freesources.org>2021-10-25 11:37:44 +0200
commite838e63b8872a0f67443a6086a2e0e415da3c8cb (patch)
treef6aed93a3599172065b10cb5935cf44ea5cf2f92 /build/integration/features/bootstrap
parent02ce5c8f7d4f27d31acbab37fe539215585c6fe8 (diff)
downloadnextcloud-server-e838e63b8872a0f67443a6086a2e0e415da3c8cb.tar.gz
nextcloud-server-e838e63b8872a0f67443a6086a2e0e415da3c8cb.zip
Add integration tests for user_status API
Signed-off-by: Jonas Meurer <jonas@freesources.org>
Diffstat (limited to 'build/integration/features/bootstrap')
-rw-r--r--build/integration/features/bootstrap/CollaborationContext.php91
-rw-r--r--build/integration/features/bootstrap/Provisioning.php1
2 files changed, 92 insertions, 0 deletions
diff --git a/build/integration/features/bootstrap/CollaborationContext.php b/build/integration/features/bootstrap/CollaborationContext.php
index cdba167e677..57fd02e3053 100644
--- a/build/integration/features/bootstrap/CollaborationContext.php
+++ b/build/integration/features/bootstrap/CollaborationContext.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
+use GuzzleHttp\Client;
use PHPUnit\Framework\Assert;
require __DIR__ . '/../../vendor/autoload.php';
@@ -69,4 +70,94 @@ class CollaborationContext implements Context {
$this->deleteServerConfig('core', 'shareapi_restrict_user_enumeration_full_match');
$this->deleteServerConfig('core', 'shareapi_only_share_with_group_members');
}
+
+ /**
+ * @Given /^user "([^"]*)" has status "([^"]*)"$/
+ * @param string $user
+ * @param string $status
+ */
+ public function assureUserHasStatus($user, $status) {
+ $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/user_status/api/v1/user_status/status";
+ $client = new Client();
+ $options = [
+ 'headers' => [
+ 'OCS-APIREQUEST' => 'true',
+ ],
+ ];
+ if ($user === 'admin') {
+ $options['auth'] = $this->adminUser;
+ } else {
+ $options['auth'] = [$user, $this->regularUser];
+ }
+
+ $options['form_params'] = [
+ 'statusType' => $status
+ ];
+
+ $this->response = $client->put($fullUrl, $options);
+ $this->theHTTPStatusCodeShouldBe(200);
+
+ $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/user_status/api/v1/user_status";
+ unset($options['form_params']);
+ $this->response = $client->get($fullUrl, $options);
+ $this->theHTTPStatusCodeShouldBe(200);
+
+ $returnedStatus = json_decode(json_encode(simplexml_load_string($this->response->getBody()->getContents())->data), true)['status'];
+ Assert::assertEquals($status, $returnedStatus);
+ }
+
+ /**
+ * @param string $user
+ * @return null|array
+ */
+ public function getStatusList(string $user): ?array {
+ $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/user_status/api/v1/statuses";
+ $client = new Client();
+ $options = [
+ 'headers' => [
+ 'OCS-APIREQUEST' => 'true',
+ ],
+ ];
+ if ($user === 'admin') {
+ $options['auth'] = $this->adminUser;
+ } else {
+ $options['auth'] = [$user, $this->regularUser];
+ }
+
+ $this->response = $client->get($fullUrl, $options);
+ $this->theHTTPStatusCodeShouldBe(200);
+
+ $contents = $this->response->getBody()->getContents();
+ return json_decode(json_encode(simplexml_load_string($contents)->data), true);
+ }
+
+ /**
+ * @Given /^user statuses for "([^"]*)" list "([^"]*)" with status "([^"]*)"$/
+ * @param string $user
+ * @param string $statusUser
+ * @param string $status
+ */
+ public function assertStatusesList(string $user, string $statusUser, string $status): void {
+ $statusList = $this->getStatusList($user);
+ Assert::assertArrayHasKey('element', $statusList, 'Returned status list empty or broken');
+ if (array_key_exists('userId', $statusList['element'])) {
+ // If only one user has a status set, the API returns their status directly
+ Assert::assertArrayHasKey('status', $statusList['element'], 'Returned status list empty or broken');
+ $filteredStatusList = [ $statusList['element']['userId'] => $statusList['element']['status'] ];
+ } else {
+ // If more than one user have their status set, the API returns an array of their statuses
+ $filteredStatusList = array_column($statusList['element'], 'status', 'userId');
+ }
+ Assert::assertArrayHasKey($statusUser, $filteredStatusList, 'User not listed in statuses: ' . $statusUser);
+ Assert::assertEquals($status, $filteredStatusList[$statusUser]);
+ }
+
+ /**
+ * @Given /^user statuses for "([^"]*)" are empty$/
+ * @param string $user
+ */
+ public function assertStatusesEmpty(string $user): void {
+ $statusList = $this->getStatusList($user);
+ Assert::assertEmpty($statusList);
+ }
}
diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php
index d613986df60..305dd4d061b 100644
--- a/build/integration/features/bootstrap/Provisioning.php
+++ b/build/integration/features/bootstrap/Provisioning.php
@@ -13,6 +13,7 @@
* @author Sergio Bertolín <sbertolin@solidgear.es>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Vincent Petry <vincent@nextcloud.com>
+ * @author Jonas Meurer <jonas@freesources.org>
*
* @license GNU AGPL version 3 or any later version
*