Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/acceptance/bootstrap/CliContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1304,4 +1304,18 @@ public function theCommandShouldNotBeSuccessful(): void {
"Expected command to fail with a non-zero exit code, but got 0. Message: " . $jsonResponse["message"]
);
}

/**
* @param string $interval
*
* @return void
*/
#[When('the administrator sends the grouped :interval email notifications using the CLI')]
public function theAdministratorSendsTheGroupedEmailNotifications(string $interval): void {
$body = [
"command" => "notifications send-email --$interval"
];
$this->featureContext->setResponse(CliHelper::runCommand($body));
$this->theCommandShouldBeSuccessful();
}
}
103 changes: 103 additions & 0 deletions tests/acceptance/bootstrap/NotificationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,71 @@ public function userShouldNotHaveANotificationRelatedToResourceWithSubject(
);
}

/**
* filter notification according to subject and space
*
* @param string $subject
* @param string $space
* @param ResponseInterface|null $response
*
* @return array
*/
public function filterNotificationsBySubjectAndSpace(
string $subject,
string $space,
?ResponseInterface $response = null
): array {
$filteredNotifications = [];
$response = $response ?? $this->featureContext->getResponse();
$responseObject = $this->featureContext->getJsonDecodedResponseBodyContent($response);

if (!isset($responseObject->ocs->data)) {
Assert::fail("Response doesn't contain notification: " . print_r($responseObject, true));
}

$notifications = $responseObject->ocs->data;
foreach ($notifications as $notification) {
if (isset($notification->subject) && $notification->subject === $subject
&& isset($notification->messageRichParameters->space->name)
&& $notification->messageRichParameters->space->name === $space
) {
$this->notificationIds[] = $notification->notification_id;
$filteredNotifications[] = $notification;
}
}
return $filteredNotifications;
}

/**
*
* @param string $user
* @param string $resourceOrSpace
* @param string $resource
* @param string $subject
*
* @return void
*/
#[Then('/^user "([^"]*)" should not have a notification related to (resource|space) "([^"]*)" with subject "([^"]*)"$/')]
public function userShouldNotHaveANotificationRelatedToResourceOrSpaceWithSubject(
string $user,
string $resourceOrSpace,
string $resource,
string $subject
): void {
$response = $this->listAllNotifications($user);
if ($resourceOrSpace === "space") {
$filteredResponse = $this->filterNotificationsBySubjectAndSpace($subject, $resource, $response);
} else {
$filteredResponse = $this->filterNotificationsBySubjectAndResource($subject, $resource, $response);
}
Assert::assertCount(
0,
$filteredResponse,
"Response should not contain notification related to $resourceOrSpace '$resource'"
. " with subject '$subject' but found" . print_r($filteredResponse, true)
);
}

/**
*
* @param string $user
Expand Down Expand Up @@ -763,4 +828,42 @@ public function userDeletesDeprovisioningNotification(?string $user = null): voi
);
$this->featureContext->setResponse($response);
}

/**
*
* @param string $user
* @param string $count
*
* @return void
*
* @throws GuzzleException
*/
#[Then('user :user should have :count emails')]
public function userShouldHaveEmails(string $user, string $count): void {
$expectedCount = (int)$count;
$address = $this->featureContext->getEmailAddressForUser($user);
$this->featureContext->pushEmailRecipientAsMailBox($address);
$mailBox = EmailHelper::getMailBoxFromEmail($address);

// assert with retries as email delivery might be delayed
$retried = 0;
do {
$mailBoxInfo = EmailHelper::getMailBoxInformation($mailBox, $this->featureContext->getStepLineRef());
$actualCount = \count($mailBoxInfo);
$tryAgain = $actualCount !== $expectedCount && $retried <= STANDARD_RETRY_COUNT;
$retried++;
if ($tryAgain) {
echo "[INFO] Expected '$expectedCount' emails for mailbox '$mailBox'"
. " but got '$actualCount'. (Retry $retried)\n";
// wait for 1 second before trying again
sleep(1);
}
} while ($tryAgain);

Assert::assertCount(
$expectedCount,
$mailBoxInfo,
"Expected '$expectedCount' emails for user '$user' but found '" . \count($mailBoxInfo) . "'"
);
}
}
192 changes: 192 additions & 0 deletions tests/acceptance/bootstrap/SettingsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,196 @@ public function userDisablesAutoAcceptingUsingSettingsApi(string $user): void {
$this->featureContext->setResponse($response);
$this->featureContext->rememberUserAutoSyncSetting($user, false);
}

/**
* maps a notification event name
*/
private const EVENT_TO_SETTING = [
"Share Received" => "event-share-created-options",
"Share Removed" => "event-share-removed-options",
"Share Expired" => "event-share-expired-options",
"Added As Space Member" => "event-space-shared-options",
"Removed As Space Member" => "event-space-unshared-options",
"Space Membership Expired" => "event-space-membership-expired-options",
"Space Disabled" => "event-space-disabled-options",
"Space Deleted" => "event-space-deleted-options",
"File Rejected" => "event-postprocessing-step-finished-options",
];

/**
* @param string $user
* @param string $enableOrDisable
* @param array $event
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestToEnableOrDisableNotificationForEvent(
string $user,
string $enableOrDisable,
array $event
): ResponseInterface {
Assert::assertArrayHasKey(
$event['event'],
self::EVENT_TO_SETTING,
"Unknown notification event '{$event['event']}'"
);
$settingName = self::EVENT_TO_SETTING[$event['event']];

$profileBundlesList = $this->getBundleByName($user, "Profile");
Assert::assertNotEmpty($profileBundlesList, "bundles list is empty");

$settingId = '';
foreach ($profileBundlesList["settings"] as $value) {
if ($value["name"] === $settingName) {
$settingId = $value["id"];
break;
}
}
Assert::assertNotEmpty($settingId, "settingId for '$settingName' is empty");

$enable = \in_array($enableOrDisable, ["enables", "enabled"], true);
$value = [
"account_uuid" => "me",
"bundleId" => $profileBundlesList["id"],
"settingId" => $settingId,
"resource" => [
"type" => "TYPE_USER"
],
];
foreach (explode(',', $event['notificationTypes']) as $type) {
$value["collectionValue"]["values"][] = [
"key" => $type,
"boolValue" => $enable,
];
}
$body = json_encode(["value" => $value], JSON_THROW_ON_ERROR);

return SettingsHelper::updateSettings(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$body,
$this->featureContext->getStepLineRef()
);
}

/**
* @param string $user
* @param string $enableOrDisable
* @param TableNode $table
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
#[When('/^user "([^"]*)" (disables|enables) notification for the following event using the settings API:$/')]
public function userEnablesOrDisablesNotificationForTheFollowingEventUsingTheSettingsApi(
string $user,
string $enableOrDisable,
TableNode $table
): void {
$response = $this->sendRequestToEnableOrDisableNotificationForEvent(
$user,
$enableOrDisable,
$table->getRowsHash()
);
$this->featureContext->setResponse($response);
}

/**
* @param string $user
* @param string $enableOrDisable
* @param TableNode $table
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
#[Given('/^user "([^"]*)" has (disabled|enabled) notification for the following event using the settings API:$/')]
public function userHasEnabledOrDisabledNotificationForTheFollowingEventUsingTheSettingsApi(
string $user,
string $enableOrDisable,
TableNode $table
): void {
$response = $this->sendRequestToEnableOrDisableNotificationForEvent(
$user,
$enableOrDisable,
$table->getRowsHash()
);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201",
$response
);
}

/**
* @param string $user
* @param string $interval
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestToSetEmailSendingInterval(string $user, string $interval): ResponseInterface {
$profileBundlesList = $this->getBundleByName($user, "Profile");
Assert::assertNotEmpty($profileBundlesList, "bundles list is empty");

$settingId = '';
foreach ($profileBundlesList["settings"] as $value) {
if ($value["name"] === "email-sending-interval-options") {
$settingId = $value["id"];
break;
}
}
Assert::assertNotEmpty($settingId, "settingId for 'email-sending-interval-options' is empty");

$body = json_encode(
[
"value" => [
"accountUuid" => "me",
"bundleId" => $profileBundlesList["id"],
"settingId" => $settingId,
"resource" => [
"type" => "TYPE_USER"
],
"stringValue" => $interval
]
],
JSON_THROW_ON_ERROR
);

return SettingsHelper::updateSettings(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
$body,
$this->featureContext->getStepLineRef()
);
}

/**
* @param string $user
* @param string $interval
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
#[Given('user :user has set the email sending interval to :interval using the settings API')]
public function userHasSetTheEmailSendingInterval(string $user, string $interval): void {
$response = $this->sendRequestToSetEmailSendingInterval($user, $interval);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201",
$response
);
}
}
4 changes: 4 additions & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ default:
- OcConfigContext:
- SharingNgContext:
- OcmContext:
- CliContext:

apiAntivirus:
paths:
Expand Down Expand Up @@ -347,6 +348,9 @@ default:
- FeatureContext: *common_feature_context_params
- GraphContext:
- SettingsContext:
- SpacesContext:
- SharingNgContext:
- NotificationContext:

apiSharingNgShareInvitation:
paths:
Expand Down
5 changes: 5 additions & 0 deletions tests/acceptance/expected-failures-decomposed-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ _ocdav: api compatibility, return correct status code_
- [apiSharingNg1/shareFileVersions.feature:55](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiSharingNg1/shareFileVersions.feature#L55)
- [apiSharingNg1/shareFileVersions.feature:56](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiSharingNg1/shareFileVersions.feature#L56)

### notification issue #323
- [apiNotification/emailNotification.feature:280](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiNotification/emailNotification.feature#L280)
- [apiNotification/emailNotification.feature:298](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiNotification/emailNotification.feature#L298)
- [apiNotification/spaceNotification.feature:463](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiNotification/spaceNotification.feature#L463)

### Won't fix

Not everything needs to be implemented for opencloud.
Expand Down
5 changes: 5 additions & 0 deletions tests/acceptance/expected-failures-posix-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ tests/acceptance/features/cliCommands/restoreTrashBinItems.feature
- [apiSharingNg1/shareFileVersions.feature:55](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiSharingNg1/shareFileVersions.feature#L55)
- [apiSharingNg1/shareFileVersions.feature:56](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiSharingNg1/shareFileVersions.feature#L56)

### notification issue #323
- [apiNotification/emailNotification.feature:280](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiNotification/emailNotification.feature#L280)
- [apiNotification/emailNotification.feature:298](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiNotification/emailNotification.feature#L298)
- [apiNotification/spaceNotification.feature:463](https://github.com/opencloud-eu/opencloud/blob/main/tests/acceptance/features/apiNotification/spaceNotification.feature#L463)

### Won't fix

Not everything needs to be implemented for opencloud.
Expand Down
Loading