Files

804 lines
21 KiB
PHP
Raw Permalink Normal View History

2022-11-18 17:17:32 +01:00
<?php
2022-11-18 17:17:32 +01:00
declare(strict_types=1);
/**
* ownCloud
*
* @author Viktor Scharf <v.scharf@owncloud.com>
* @copyright Copyright (c) 2022 Viktor Scharf v.scharf@owncloud.com
*/
use Behat\Behat\Context\Context;
use GuzzleHttp\Exception\GuzzleException;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
2024-10-08 12:26:40 +05:45
use Behat\Gherkin\Node\TableNode;
2022-11-18 17:17:32 +01:00
use PHPUnit\Framework\Assert;
2023-06-27 17:02:54 +05:45
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
2024-07-03 12:16:06 +05:45
use TestHelpers\SettingsHelper;
2024-10-08 12:26:40 +05:45
use TestHelpers\BehatHelper;
2022-11-18 17:17:32 +01:00
require_once 'bootstrap.php';
/**
* Context for the TUS-specific steps using the Graph API
*/
class SettingsContext implements Context {
2022-11-18 17:17:32 +01:00
private FeatureContext $featureContext;
2025-06-30 12:19:09 +05:45
private array $autoAcceptSharesSettingIds = [];
2022-11-18 17:17:32 +01:00
/**
* This will run before EVERY scenario.
* It will set the properties for this object.
*
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
*/
public function before(BeforeScenarioScope $scope): void {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
2024-10-08 12:26:40 +05:45
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
2022-11-18 17:17:32 +01:00
}
2025-06-30 12:19:09 +05:45
/**
* @param string $user
*
* @return string
*/
public function getAutoAcceptShareSettingId(string $user): string {
if (!empty($this->autoAcceptSharesSettingIds) && \array_key_exists($user, $this->autoAcceptSharesSettingIds)) {
return $this->autoAcceptSharesSettingIds[$user];
}
return '';
}
/**
* @param string $user
* @param string $id
*
* @return void
*/
public function setAutoAcceptShareSettingId(string $user, string $id): void {
$this->autoAcceptSharesSettingIds[$user] = $id;
}
/**
* @param string $user
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
public function getRoles(string $user): ResponseInterface {
2024-07-03 12:16:06 +05:45
return SettingsHelper::getRolesList(
2024-10-08 12:26:40 +05:45
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
);
}
2022-11-18 17:17:32 +01:00
/**
2025-01-02 17:16:13 +05:45
* @When /^user "([^"]*)" tries to get all existing roles using the settings API$/
2022-11-18 17:17:32 +01:00
*
* @param string $user
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function getAllExistingRoles(string $user): void {
$response = $this->getRoles($user);
$this->featureContext->setResponse($response);
2022-11-18 17:17:32 +01:00
}
/**
* @param string $user
* @param string $userId
* @param string $roleId
*
* @return ResponseInterface
2022-11-18 17:17:32 +01:00
*
* @throws GuzzleException
* @throws Exception
*/
public function assignRoleToUser(string $user, string $userId, string $roleId): ResponseInterface {
2024-07-03 12:16:06 +05:45
return SettingsHelper::assignRoleToUser(
2024-10-08 12:26:40 +05:45
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
2024-07-03 12:16:06 +05:45
$userId,
$roleId,
2022-11-18 17:17:32 +01:00
);
}
/**
* @param string $user
* @param string $userId
*
2024-07-03 12:16:06 +05:45
* @return ResponseInterface
2022-11-18 17:17:32 +01:00
*
* @throws GuzzleException
* @throws Exception
*/
public function getAssignmentsList(string $user, string $userId): ResponseInterface {
2024-07-03 12:16:06 +05:45
return SettingsHelper::getAssignmentsList(
2024-10-08 12:26:40 +05:45
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
2024-07-03 12:16:06 +05:45
$userId,
);
2022-11-18 17:17:32 +01:00
}
/**
* @Given /^the administrator has given "([^"]*)" the role "([^"]*)" using the settings api$/
2022-11-18 17:17:32 +01:00
*
* @param string $user
* @param string $role
*
* @return void
*
* @throws Exception
*/
public function theAdministratorHasGivenUserTheRole(string $user, string $role): void {
$admin = $this->featureContext->getAdminUserName();
$roleId = $this->getRoleIdByRoleName($admin, $role);
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id') ?: $user;
$response = $this->assignRoleToUser($admin, $userId, $roleId);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201",
$response,
);
2022-11-18 17:17:32 +01:00
}
2025-01-02 17:16:13 +05:45
/**
* @When user :assigner assigns the role :role to user :assignee using the settings API
*
* @param string $assigner
* @param string $role
* @param string $assignee
*
* @return void
*
* @throws Exception
*/
public function userAssignsTheRoleToUserUsingTheSettingsApi(
string $assigner,
string $role,
string $assignee,
2025-01-02 17:16:13 +05:45
): void {
$response = $this->assignRoleToUser(
$assigner,
$this->featureContext->getAttributeOfCreatedUser($assignee, 'id'),
$this->getRoleIdByRoleName($assigner, $role),
2025-01-02 17:16:13 +05:45
);
$this->featureContext->setResponse($response);
}
2022-11-18 17:17:32 +01:00
/**
* @param string $user
* @param string $role
*
* @return string
*/
public function getRoleIdByRoleName(string $user, string $role): string {
// Sometimes the response body is not complete and results invalid json.
2024-04-26 15:27:00 +05:45
// So we try again until we get a valid json.
$retried = 0;
do {
$response = $this->getRoles($user);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201",
$response,
);
2025-06-19 12:12:17 +05:45
$rawBody = $response->getBody()->getContents();
try {
$decodedBody = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
$tryAgain = false;
} catch (Exception $e) {
$tryAgain = $retried < HttpRequestHelper::maxHTTPRequestRetries();
if (!$tryAgain) {
throw $e;
}
}
if ($tryAgain) {
$retried += 1;
echo "Invalid json body, retrying ($retried)...\n";
// wait 500ms and try again
\usleep(500 * 1000);
}
} while ($tryAgain);
Assert::assertArrayHasKey(
'bundles',
$decodedBody,
__METHOD__ . " could not find bundles in body",
);
$bundles = $decodedBody["bundles"];
2022-11-18 17:17:32 +01:00
$roleToAssign = "";
foreach ($bundles as $value) {
// find the selected role
if ($value["displayName"] === $role) {
$roleToAssign = $value;
break;
}
}
Assert::assertNotEmpty($roleToAssign, "The selected role $role could not be found");
return $roleToAssign["id"];
}
/**
* @When /^user "([^"]*)" changes his own role to "([^"]*)"$/
*
* @param string $user
* @param string $role
*
* @return void
* @throws GuzzleException
*/
public function userChangeOwnRole(string $user, string $role): void {
// we assume that the user knows uuid role.
$roleId = $this->getRoleIdByRoleName($this->featureContext->getAdminUserName(), $role);
2022-11-18 17:17:32 +01:00
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$response = $this->assignRoleToUser($user, $userId, $roleId);
$this->featureContext->setResponse($response);
2022-11-18 17:17:32 +01:00
}
/**
* @When /^user "([^"]*)" changes the role "([^"]*)" for user "([^"]*)"$/
*
* @param string $user
* @param string $role
* @param string $assignedUser
*
* @return void
* @throws GuzzleException
*/
public function userChangeRoleAnotherUser(string $user, string $role, string $assignedUser): void {
// we assume that the user knows uuid role.
$roleId = $this->getRoleIdByRoleName($this->featureContext->getAdminUserName(), $role);
2022-11-18 17:17:32 +01:00
$userId = $this->featureContext->getAttributeOfCreatedUser($assignedUser, 'id');
$response = $this->assignRoleToUser($user, $userId, $roleId);
$this->featureContext->setResponse($response);
2022-11-18 17:17:32 +01:00
}
/**
2025-01-02 17:16:13 +05:45
* @When /^user "([^"]*)" tries to get list of assignment using the settings API$/
2022-11-18 17:17:32 +01:00
*
* @param string $user
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function userGetAssignmentsList(string $user): void {
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$this->featureContext->setResponse($this->getAssignmentsList($user, $userId));
2022-11-18 17:17:32 +01:00
}
/**
2023-02-20 09:49:05 +05:45
* @Then /^user "([^"]*)" should have the role "([^"]*)"$/
2022-11-18 17:17:32 +01:00
*
* @param string $user
* @param string $role
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function userShouldHaveRole(string $user, string $role): void {
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$response = $this->getAssignmentsList($this->featureContext->getAdminUserName(), $userId);
2023-06-27 17:02:54 +05:45
$assignmentResponse = $this->featureContext->getJsonDecodedResponseBodyContent($response);
if (isset($assignmentResponse->assignments[0]->roleId)) {
$actualRoleId = $assignmentResponse->assignments[0]->roleId;
2024-12-24 09:30:42 +05:45
Assert::assertEquals(
$this->getRoleIdByRoleName($this->featureContext->getAdminUserName(), $role),
$actualRoleId,
"user $user has no role $role",
2024-12-24 09:30:42 +05:45
);
2023-06-27 17:02:54 +05:45
} else {
Assert::fail("Response should contain user role but not found.\n" . json_encode($assignmentResponse));
}
2022-11-18 17:17:32 +01:00
}
2023-02-20 09:49:05 +05:45
/**
* @Then /^the setting API response should have the role "([^"]*)"$/
*
* @param string $role
*
* @return void
*
* @throws Exception
*/
public function theSettingApiResponseShouldHaveTheRole(string $role): void {
2024-12-24 09:30:42 +05:45
$assignmentRoleId = $this->featureContext->getJsonDecodedResponse(
$this->featureContext->getResponse(),
2024-12-24 09:30:42 +05:45
)["assignments"][0]["roleId"];
Assert::assertEquals(
$this->getRoleIdByRoleName($this->featureContext->getAdminUserName(), $role),
$assignmentRoleId,
"user has no role $role",
2024-12-24 09:30:42 +05:45
);
2023-02-20 09:49:05 +05:45
}
/**
* @param string $user
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestGetBundlesList(string $user): ResponseInterface {
2024-07-03 12:16:06 +05:45
return SettingsHelper::getBundlesList(
2024-10-08 12:26:40 +05:45
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
);
}
/**
* @param string $user
* @param string $bundleName
*
* @return array
*
* @throws GuzzleException
* @throws Exception
*/
2024-07-03 12:16:06 +05:45
public function getBundleByName(string $user, string $bundleName): array {
return SettingsHelper::getBundleByName(
2024-10-08 12:26:40 +05:45
$this->featureContext->getBaseUrl(),
2024-07-03 12:16:06 +05:45
$user,
$this->featureContext->getPasswordForUser($user),
$bundleName,
);
}
/**
* @param string $user
2025-06-24 11:39:50 +02:00
* @param array|null $headers
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
2025-06-24 11:39:50 +02:00
public function sendRequestGetSettingsValuesList(string $user, ?array $headers = null): ResponseInterface {
2024-07-03 12:16:06 +05:45
return SettingsHelper::getValuesList(
2024-10-08 12:26:40 +05:45
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$headers,
);
}
/**
* @When /^user "([^"]*)" lists values-list with headers using the Settings API$/
*
* @param string $user
* @param TableNode $headersTable
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserListsAllValuesListWithHeadersUsingSettingsApi(string $user, TableNode $headersTable): void {
$this->featureContext->verifyTableNodeColumns(
$headersTable,
['header', 'value'],
);
2024-04-26 15:27:00 +05:45
$headers = [];
foreach ($headersTable as $row) {
$headers[$row['header']] = $row ['value'];
}
$this->featureContext->setResponse($this->sendRequestGetSettingsValuesList($user, $headers));
}
/**
* @param string $user
* @param string $language
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestToSwitchSystemLanguage(string $user, string $language): ResponseInterface {
2024-07-03 12:16:06 +05:45
$profileBundlesList = $this->getBundleByName($user, "Profile");
Assert::assertNotEmpty($profileBundlesList, "bundles list is empty");
$settingId = '';
foreach ($profileBundlesList["settings"] as $value) {
if ($value["name"] === "language") {
$settingId = $value["id"];
break;
}
}
Assert::assertNotEmpty($settingId, "settingId is empty");
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$body = json_encode(
[
"value" => [
"account_uuid" => "me",
"bundleId" => $profileBundlesList["id"],
"id" => $userId,
"listValue" => [
"values" => [
[
2025-06-19 10:46:56 +05:45
"stringValue" => $language,
],
],
],
"resource" => [
2025-06-19 10:46:56 +05:45
"type" => "TYPE_USER",
],
2025-06-19 10:46:56 +05:45
"settingId" => $settingId,
],
],
JSON_THROW_ON_ERROR,
);
2024-07-03 12:16:06 +05:45
return SettingsHelper::updateSettings(
2024-10-08 12:26:40 +05:45
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
2024-07-03 12:16:06 +05:45
$body,
);
}
/**
* @Given /^user "([^"]*)" has switched the system language to "([^"]*)" using the settings API$/
*
* @param string $user
* @param string $language
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
public function theUserHasSwitchedSystemLanguage(string $user, string $language): void {
$response = $this->sendRequestToSwitchSystemLanguage($user, $language);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201",
$response,
);
}
2025-01-02 17:16:13 +05:45
/**
* @When user :user switches the system language to :language using the settings API
*
* @param string $user
* @param string $language
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
public function userSwitchesTheSystemLanguageUsingTheSettingsApi(string $user, string $language): void {
$response = $this->sendRequestToSwitchSystemLanguage($user, $language);
$this->featureContext->setResponse($response);
}
/**
* @param string $user
2025-05-21 15:28:05 +05:45
* @param bool $status
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
2025-05-21 15:28:05 +05:45
public function toggleAutoAcceptSharesSetting(string $user, bool $status): ResponseInterface {
$body = [
"value" => [
"account_uuid" => "me",
"bundleId" => SettingsHelper::getBundleId(),
"settingId" => SettingsHelper::getSettingIdUsingEventName("Auto Accept Shares"),
"resource" => [
"type" => "TYPE_USER",
2025-06-19 10:46:56 +05:45
],
"boolValue" => $status,
],
];
2025-06-30 12:19:09 +05:45
$autoAcceptSharesSettingId = $this->getAutoAcceptShareSettingId($user);
if ($autoAcceptSharesSettingId) {
// use existing id if available
2025-06-30 12:19:09 +05:45
$body["value"]["id"] = $autoAcceptSharesSettingId;
}
$body = json_encode($body, JSON_THROW_ON_ERROR);
$response = SettingsHelper::updateSettings(
2024-10-08 12:26:40 +05:45
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
2024-07-03 12:16:06 +05:45
$body,
);
2025-06-30 12:19:09 +05:45
if (!$autoAcceptSharesSettingId && $response->getStatusCode() === 201) {
// save id for future use
// updating the setting without id will create a new setting entry
$data = $this->featureContext->getJsonDecodedResponseBodyContent($response);
2025-06-30 12:19:09 +05:45
$this->setAutoAcceptShareSettingId($user, $data->value->value->id);
}
$response->getBody()->rewind();
return $response;
}
/**
* @Given user :user has disabled auto-accepting
2024-02-06 14:36:45 +05:45
* @Given user :user has disabled the auto-sync share
*
* @param string $user
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
public function theUserHasDisabledAutoAccepting(string $user): void {
2025-05-21 15:28:05 +05:45
$response = $this->toggleAutoAcceptSharesSetting($user, false);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201",
$response,
);
2024-04-25 12:15:08 +05:45
$this->featureContext->rememberUserAutoSyncSetting($user, false);
}
2025-01-02 17:16:13 +05:45
/**
2025-05-21 15:28:05 +05:45
* @When /^user "([^"]*)" (disables|enables) the auto-sync share using the settings API$/
2025-01-02 17:16:13 +05:45
*
* @param string $user
2025-05-21 15:28:05 +05:45
* @param string $status
2025-01-02 17:16:13 +05:45
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
2025-05-21 15:28:05 +05:45
public function userEnablesOrDisablesTheAutoSyncShareUsingTheSettingsApi(string $user, string $status): void {
$enable = $status === "enables";
$response = $this->toggleAutoAcceptSharesSetting($user, $enable);
2025-01-02 17:16:13 +05:45
$this->featureContext->setResponse($response);
2025-05-21 15:28:05 +05:45
$this->featureContext->rememberUserAutoSyncSetting($user, $enable);
2025-01-02 17:16:13 +05:45
}
/**
* @When user :user disables email notification using the settings API
*
* @param string $user
*
* @return void
*/
public function userDisablesEmailNotificationUsingTheSettingsAPI(string $user): void {
2025-03-06 09:43:33 +05:45
$body = [
"value" => [
"account_uuid" => "me",
"bundleId" => SettingsHelper::getBundleId(),
"settingId" => SettingsHelper::getSettingIdUsingEventName("Disable Email Notifications"),
"resource" => [
2025-06-19 10:46:56 +05:45
"type" => "TYPE_USER",
2025-03-06 09:43:33 +05:45
],
2025-06-19 10:46:56 +05:45
"boolValue" => true,
],
2025-03-06 09:43:33 +05:45
];
$response = SettingsHelper::updateSettings(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
json_encode($body),
);
$this->featureContext->setResponse($response);
}
/**
* @param string $user
* @param string $enableOrDisable
2025-03-20 18:06:19 +05:45
* @param array $event
*
2025-03-20 18:06:19 +05:45
* @return ResponseInterface
*
* @throws GuzzleException
* @throws JsonException
*/
2025-03-20 18:06:19 +05:45
public function enableOrDisableNotification(
string $user,
string $enableOrDisable,
array $event,
2025-03-20 18:06:19 +05:45
): ResponseInterface {
$body = [
"value" => [
"account_uuid" => "me",
"bundleId" => SettingsHelper::getBundleId(),
2025-03-20 18:06:19 +05:45
"settingId" => SettingsHelper::getSettingIdUsingEventName($event['event']),
"resource" => [
2025-06-19 10:46:56 +05:45
"type" => "TYPE_USER",
],
],
];
2025-03-20 18:06:19 +05:45
$notificationTypes = explode(',', $event['notificationTypes']);
foreach ($notificationTypes as $type) {
if ($type === "mail") {
$body["value"]["collectionValue"]["values"][] = [
"key" => "mail",
2025-06-19 10:46:56 +05:45
"boolValue" => $enableOrDisable === "enables",
];
} elseif ($type === "in-app") {
$body["value"]["collectionValue"]["values"][] = [
"key" => "in-app",
2025-06-19 10:46:56 +05:45
"boolValue" => $enableOrDisable === "enables",
];
}
}
2025-03-20 18:06:19 +05:45
return SettingsHelper::updateSettings(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
json_encode($body),
);
2025-03-20 18:06:19 +05:45
}
/**
* @Given /^user "([^"]*)" has (disabled|enabled) notification for the following event using the settings API:$/
*
* @param string $user
* @param string $enableOrDisable
* @param TableNode $table
*
* @return void
*/
public function userHasEnabledOrDisabledNotificationForTheFollowingEventUsingTheSettingsApi(
string $user,
string $enableOrDisable,
TableNode $table,
2025-03-20 18:06:19 +05:45
): void {
$event = $table->getRowsHash();
$response = $this->enableOrDisableNotification($user, $enableOrDisable, $event);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "", $response);
}
/**
* @When /^user "([^"]*)" (disables|enables) notification for the following event using the settings API:$/
*
* @param string $user
* @param string $enableOrDisable
* @param TableNode $table
*
* @return void
*/
public function userEnablesOrDisablesNotificationForTheFollowingEventUsingTheSettingsApi(
string $user,
string $enableOrDisable,
TableNode $table,
2025-03-20 18:06:19 +05:45
): void {
$event = $table->getRowsHash();
$response = $this->enableOrDisableNotification($user, $enableOrDisable, $event);
$this->featureContext->setResponse($response);
}
2025-03-06 09:43:33 +05:45
/**
* @param string $user
* @param string $interval
*
* @return ResponseInterface
* @throws GuzzleException
* @throws JsonException
*/
public function setEmailSendingInterval(string $user, string $interval): ResponseInterface {
$body = [
"value" => [
"account_uuid" => "me",
"bundleId" => SettingsHelper::getBundleId(),
"settingId" => SettingsHelper::getSettingIdUsingEventName("Email Sending Interval"),
"resource" => [
2025-06-19 10:46:56 +05:45
"type" => "TYPE_USER",
2025-03-06 09:43:33 +05:45
],
2025-06-19 10:46:56 +05:45
"stringValue" => $interval,
],
2025-03-06 09:43:33 +05:45
];
return SettingsHelper::updateSettings(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
json_encode($body, JSON_THROW_ON_ERROR),
);
}
/**
* @When /^user "([^"]*)" sets the email sending interval to "([^"]*)" using the settings API$/
*
* @param string $user
* @param string $interval
*
* @return void
2025-03-06 09:43:33 +05:45
* @throws Exception|GuzzleException
*/
public function userSetsTheEmailSendingIntervalToUsingTheSettingsAPI(
string $user,
string $interval,
): void {
2025-03-06 09:43:33 +05:45
$response = $this->setEmailSendingInterval($user, $interval);
$this->featureContext->setResponse($response);
}
/**
* @Given /^user "([^"]*)" has set the email sending interval to "([^"]*)" using the settings API$/
*
* @param string $user
* @param string $interval
*
* @return void
* @throws Exception|GuzzleException
*/
public function userHasSetTheEmailSendingIntervalToUsingTheSettingsAPI(
string $user,
string $interval,
): void {
2025-03-06 09:43:33 +05:45
$response = $this->setEmailSendingInterval($user, $interval);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "", $response);
}
2025-05-21 15:28:05 +05:45
/**
* @Then for user :user setting :setting should have value :value
*
* @param string $user
* @param string $settingName
* @param string $value
*
* @return void
* @throws Exception|GuzzleException
*/
public function forUserSettingShouldHaveValue(string $user, string $settingName, string $value): void {
$response = SettingsHelper::getValuesBySettingID(
$this->featureContext->getBaseUrl(),
SettingsHelper::PROFILE_SETTINGS[$settingName],
$user,
$this->featureContext->getPasswordForUser($user),
);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "", $response);
$setting = HttpRequestHelper::getJsonDecodedResponseBodyContent($response)->value->value;
if (\property_exists($setting, 'stringValue')) {
$settingValue = $setting->stringValue;
} elseif (\property_exists($setting, 'boolValue')) {
$settingValue = $setting->boolValue;
$value = $value === "true" ? true : false;
} elseif (\property_exists($setting, 'listValue')) {
$settingValue = $setting->listValue->values[0]->stringValue;
} else {
Assert::fail(
"Setting '$settingName' does not have a stringValue, boolValue or listValue."
. "\n"
. json_encode($setting),
2025-05-21 15:28:05 +05:45
);
}
Assert::assertSame(
$value,
$settingValue,
"Expected setting value '$value' but got '$settingValue'",
2025-05-21 15:28:05 +05:45
);
}
2022-11-18 17:17:32 +01:00
}