Skip to content

Commit

Permalink
Merge pull request #40546 from owncloud/add-webui-test-sharing-with-m…
Browse files Browse the repository at this point in the history
…ultiple-users-at-once

[full-ci] [tests-only]WebUI tests added to share resource with multiple users at once
  • Loading branch information
phil-davis authored Jan 3, 2023
2 parents ec7ff7c + 77fc1bf commit 2adfe15
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 1 deletion.
37 changes: 37 additions & 0 deletions tests/acceptance/features/bootstrap/WebUISharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ public function theUserSharesFileFolderWithUserUsingTheWebUI(
);
}

/**
* @When the user shares file/folder :resource with users :users using the webUI
*
* @param string $resource
* @param string $users
*
* @return void
* @throws Exception
*/
public function theUserSharesFileFolderWithUsersUsingTheWebUI(
string $resource,
string $users
):void {
$this->theUserSharesFileFolderWithUserOrGroupUsingTheWebUI(
$resource,
"users",
null,
$users
);
}

/**
* @When /^the user tries to share (?:file|folder) "([^"]*)" with (?:(remote|federated)\s)?user "([^"]*)" ?(?:with displayname "([^"]*)")? using the webUI$/
*
Expand Down Expand Up @@ -448,6 +469,22 @@ public function theUserSharesUsingWebUIWithoutClosingDialog(
$maxRetries
);
}
} elseif ($userOrGroup === "users") {
$users = explode(",", $name);
$usersArray = [];
foreach ($users as $user) {
if ($this->featureContext->userExists($user)) {
$usersArray[] = $user;
}
}
$nameToMatch = join(", ", $usersArray);
$this->sharingDialog->shareWithUsers(
$name,
$nameToMatch,
$this->getSession(),
$quiet,
$maxRetries
);
} else {
$this->sharingDialog->shareWithGroup(
$name,
Expand Down
34 changes: 33 additions & 1 deletion tests/acceptance/features/lib/FilesPageElement/SharingDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SharingDialog extends OwncloudPage {
private $autocompleteItemsTextXpath = "//*[@class='autocomplete-item-text']";
private $suffixToIdentifyGroups = " Group";
private $suffixToIdentifyUsers = " User";
private $suffixToIdentifyMultipleUsers = " Add multiple users";
private $suffixToIdentifyRemoteUsers = " Federated";
private $sharerInformationXpath = ".//*[@class='reshare']";
private $sharedWithAndByRegEx = "Shared with you(?: and the group (.*))? by (.*)$";
Expand Down Expand Up @@ -352,7 +353,11 @@ public function shareWithUserOrGroup(
);
$userFound = false;
foreach ($userElements as $user) {
if ($this->getTrimmedText($user) === $nameToMatch) {
$trimmedText = $this->getTrimmedText($user);
// The logic is changed due to "Add multiple users" because the order of users in autocomplete items is not fixed
$trimmedUsers = preg_split("/[\s,]+/", $trimmedText);
$usersToMatch = preg_split("/[\s,]+/", $nameToMatch);
if (empty(array_diff($trimmedUsers, $usersToMatch))) {
$user->click();
$this->waitForAjaxCallsToStartAndFinish($session);
$userFound = true;
Expand Down Expand Up @@ -402,6 +407,33 @@ public function shareWithUser(
);
}

/**
*
* @param string|null $name
* @param string|null $nameToMatch
* @param Session $session
* @param boolean $quiet
* @param int $maxRetries
*
* @return void
* @throws ElementNotFoundException|Exception
*/
public function shareWithUsers(
string $name,
string $nameToMatch,
Session $session,
bool $quiet,
int $maxRetries = 5
): void {
$this->shareWithUserOrGroup(
$name,
$nameToMatch . $this->suffixToIdentifyMultipleUsers,
$session,
$quiet,
$maxRetries
);
}

/**
*
* @param string|null $name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,101 @@ Feature: Sharing files and folders with internal users
| 123 |
| -123 |
| 0.0 |


Scenario: user shares file with multiple users at once
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |
| Carol |
And user "Alice" has uploaded file "filesForUpload/lorem.txt" to "lorem.txt"
And user "Alice" has logged in using the webUI
When the user shares file "lorem.txt" with users "Brian,Carol" using the webUI
Then as "Brian" file "lorem.txt" should exist
And as "Carol" file "lorem.txt" should exist


Scenario: user shares folder with multiple users at once
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |
| Carol |
And user "Alice" has created folder "simple-folder"
And user "Alice" has logged in using the webUI
When the user shares folder "simple-folder" with users "Brian,Carol" using the webUI
Then as "Brian" folder "simple-folder" should exist
And as "Carol" folder "simple-folder" should exist


Scenario Outline: user shares file with multiple users including non-existing user at once
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |
| Carol |
And user "Alice" has uploaded file "filesForUpload/lorem.txt" to "lorem.txt"
And user "Alice" has logged in using the webUI
When the user shares file "lorem.txt" with users "<usernames>" using the webUI
Then a notification should be displayed on the webUI with the text "Could not be shared with the following users: David"
And as "Brian" file "lorem.txt" should exist
And as "Carol" file "lorem.txt" should exist
Examples:
| usernames |
| Brian,Carol,David |
| Brian,David,Carol |
| David,Brian,Carol |


Scenario Outline: user shares folder with multiple users including non-existing user at once
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |
| Carol |
And user "Alice" has created folder "simple-folder"
And user "Alice" has logged in using the webUI
When the user shares folder "simple-folder" with users "<usernames>" using the webUI
Then a notification should be displayed on the webUI with the text "Could not be shared with the following users: David"
And as "Brian" folder "simple-folder" should exist
And as "Carol" folder "simple-folder" should exist
Examples:
| usernames |
| Brian,Carol,David |
| Brian,David,Carol |
| David,Brian,Carol |


Scenario: user shares file with multiple users having exact same group name
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |
| Carol |
| David |
And group "Brian,Carol" has been created
And user "David" has been added to group "Brian,Carol"
And user "Alice" has uploaded file "filesForUpload/lorem.txt" to "lorem.txt"
And user "Alice" has logged in using the webUI
When the user shares file "lorem.txt" with users "Brian,Carol" using the webUI
Then as "Brian" file "lorem.txt" should exist
And as "Carol" file "lorem.txt" should exist
And as "David" file "lorem.txt" should not exist


Scenario: user shares folder with multiple users having exact same group name
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |
| Carol |
| David |
And group "Brian,Carol" has been created
And user "David" has been added to group "Brian,Carol"
And user "Alice" has created folder "simple-folder"
And user "Alice" has logged in using the webUI
When the user shares folder "simple-folder" with users "Brian,Carol" using the webUI
Then as "Brian" folder "simple-folder" should exist
And as "Carol" folder "simple-folder" should exist
And as "David" folder "simple-folder" should not exist

0 comments on commit 2adfe15

Please sign in to comment.