diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 3ba11b843c2f..13c88594bd5e 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -126,7 +126,7 @@ public function getUserDisplayName($username) { } /** - * returns an array of the display names, keyed by username + * returns an array of the user display names, keyed by username * if no "Display Name" is set the user-name is returned instead * * @return array @@ -139,6 +139,22 @@ public function getCreatedUserDisplayNames() { return $result; } + /** + * returns an array of the group display names, keyed by group name + * currently group name and display name are always the same, so this + * function is a convenience for getting the group names in a similar + * format to what getCreatedUserDisplayNames() returns + * + * @return array + */ + public function getCreatedGroupDisplayNames() { + $result = []; + foreach ($this->getCreatedGroups() as $groupName => $groupData) { + $result[$groupName] = $groupName; + } + return $result; + } + /** * * @param string $username diff --git a/tests/acceptance/features/bootstrap/WebUISharingContext.php b/tests/acceptance/features/bootstrap/WebUISharingContext.php index dfe779def359..95c1fbf1740e 100644 --- a/tests/acceptance/features/bootstrap/WebUISharingContext.php +++ b/tests/acceptance/features/bootstrap/WebUISharingContext.php @@ -187,12 +187,14 @@ public function theUserSharesFileFolderWithUserUsingTheWebUI( * * @param string $folder * @param string $group + * @param int $maxRetries + * @param bool $quiet * * @return void * @throws \Exception */ public function theUserSharesFileFolderWithGroupUsingTheWebUI( - $folder, $group + $folder, $group, $maxRetries = STANDARD_RETRY_COUNT, $quiet = false ) { $this->filesPage->waitTillPageIsloaded($this->getSession()); try { @@ -203,7 +205,9 @@ public function theUserSharesFileFolderWithGroupUsingTheWebUI( $this->sharingDialog = $this->filesPage->openSharingDialog( $folder, $this->getSession() ); - $this->sharingDialog->shareWithGroup($group, $this->getSession()); + $this->sharingDialog->shareWithGroup( + $group, $this->getSession(), $maxRetries, $quiet + ); $this->theUserClosesTheShareDialog(); } @@ -878,7 +882,7 @@ public function allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedIn $requiredString ) { $this->allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedInTheAutocompleteListExcept( - $requiredString, '', '' + $requiredString, 'user', '' ); } @@ -898,27 +902,37 @@ public function allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedIn $notToBeListed = $this->sharingDialog->groupStringsToMatchAutoComplete($notToBeListed); } + if ($userOrGroup === 'user') { + $notToBeListed + = $this->sharingDialog->userStringsToMatchAutoComplete($notToBeListed); + } $autocompleteItems = $this->sharingDialog->getAutocompleteItemsList(); // Keep separate arrays of users and groups, because the names can overlap - $createdElements = []; - $createdElements['groups'] = $this->sharingDialog->groupStringsToMatchAutoComplete( - $this->featureContext->getCreatedGroups() + $createdElementsWithDisplayNames = []; + $createdElementsWithFullDisplayText = []; + $createdElementsWithDisplayNames['groups'] = $this->featureContext->getCreatedGroupDisplayNames(); + $createdElementsWithFullDisplayText['groups'] = $this->sharingDialog->groupStringsToMatchAutoComplete( + $createdElementsWithDisplayNames['groups'] + ); + $createdElementsWithDisplayNames['users'] = $this->featureContext->getCreatedUserDisplayNames(); + $createdElementsWithFullDisplayText['users'] = $this->sharingDialog->userStringsToMatchAutoComplete( + $createdElementsWithDisplayNames['users'] ); - $createdElements['users'] = $this->featureContext->getCreatedUserDisplayNames(); $numExpectedItems = 0; - foreach ($createdElements as $elementArray) { - foreach ($elementArray as $internalName => $displayName) { + foreach ($createdElementsWithFullDisplayText as $usersOrGroups => $elementArray) { + foreach ($elementArray as $internalName => $fullDisplayText) { + $displayName = $createdElementsWithDisplayNames[$usersOrGroups][$internalName]; // Matching should be case-insensitive on the internal or display name if (((\stripos($internalName, $requiredString) !== false) || (\stripos($displayName, $requiredString) !== false)) - && ($displayName !== $notToBeListed) + && ($fullDisplayText !== $notToBeListed) && ($displayName !== $this->featureContext->getCurrentUser()) && ($displayName !== $this->featureContext->getCurrentUserDisplayName()) ) { PHPUnit\Framework\Assert::assertContains( - $displayName, + $fullDisplayText, $autocompleteItems, - "'$displayName' not in autocomplete list" + "'$fullDisplayText' not in autocomplete list" ); $numExpectedItems = $numExpectedItems + 1; } @@ -976,8 +990,9 @@ public function userShouldBeListedInTheAutocompleteListOnTheWebui($username) { */ public function userShouldNotBeListedInTheAutocompleteListOnTheWebui($username) { $names = $this->sharingDialog->getAutocompleteItemsList(); - if (\in_array($username, $names)) { - throw new Exception("$username found in autocomplete list but not expected"); + $userString = $this->sharingDialog->userStringsToMatchAutoComplete($username); + if (\in_array($userString, $names)) { + throw new Exception("$username ($userString) found in autocomplete list but not expected"); } } @@ -1171,28 +1186,44 @@ public function theNumberOfPublicLinksShouldBe($count) { } /** - * @Then /^it should not be possible to share (?:file|folder) "([^"]*)"(?: with "([^"]*)")? using the webUI$/ + * @Then /^it should not be possible to share (?:file|folder) "([^"]*)"(?: with (user|group) "([^"]*)")? using the webUI$/ * * @param string $fileName + * @param string $userOrGroup * @param string|null $shareWith * * @return void * @throws \Exception */ public function itShouldNotBePossibleToShareFileFolderUsingTheWebUI( - $fileName, $shareWith = null + $fileName, $userOrGroup = null, $shareWith = null ) { $sharingWasPossible = false; try { - $this->theUserSharesFileFolderWithUserUsingTheWebUI( - $fileName, null, $shareWith, 2, true - ); + if ($userOrGroup === "user") { + $this->theUserSharesFileFolderWithUserUsingTheWebUI( + $fileName, null, $shareWith, 2, true + ); + } else { + $this->theUserSharesFileFolderWithGroupUsingTheWebUI( + $fileName, $shareWith, 2, true + ); + } $sharingWasPossible = true; } catch (ElementNotFoundException $e) { + if ($shareWith === null) { + $shareWithText = ""; + } else { + if ($userOrGroup === "user") { + $shareWithText = $this->sharingDialog->userStringsToMatchAutoComplete($shareWith); + } else { + $shareWithText = $this->sharingDialog->groupStringsToMatchAutoComplete($shareWith); + } + } $possibleMessages = [ "could not find share-with-field", "could not find sharing button in fileRow", - "could not share with '$shareWith'" + "could not share with '$shareWithText'" ]; $foundMessage = false; foreach ($possibleMessages as $message) { diff --git a/tests/acceptance/features/lib/FilesPageElement/SharingDialog.php b/tests/acceptance/features/lib/FilesPageElement/SharingDialog.php index 3a655e1818ed..a02d54c423a6 100644 --- a/tests/acceptance/features/lib/FilesPageElement/SharingDialog.php +++ b/tests/acceptance/features/lib/FilesPageElement/SharingDialog.php @@ -46,8 +46,9 @@ class SharingDialog extends OwncloudPage { private $shareWithTooltipXpath = "/..//*[@class='tooltip-inner']"; private $shareWithAutocompleteListXpath = ".//ul[contains(@class,'ui-autocomplete')]"; private $autocompleteItemsTextXpath = "//*[@class='autocomplete-item-text']"; - private $suffixToIdentifyGroups = " (group)"; - private $suffixToIdentifyRemoteUsers = " (federated)"; + private $suffixToIdentifyGroups = " Group"; + private $suffixToIdentifyUsers = " User"; + private $suffixToIdentifyRemoteUsers = " Federated"; private $sharerInformationXpath = ".//*[@class='reshare']"; private $sharedWithAndByRegEx = "^(?:[A-Z]\s)?Shared with you(?: and the group (.*))? by (.*)$"; private $permissionsFieldByUserName = ".//*[@id='shareWithList']//*[@class='has-tooltip username' and .='%s']/.."; @@ -151,6 +152,25 @@ public function getAutocompleteNodeElement() { return $autocompleteNodeElement; } + /** + * returns the user names as they could appear in an autocomplete list + * + * @param string|array $userNames + * + * @return string|array + */ + public function userStringsToMatchAutoComplete($userNames) { + if (\is_array($userNames)) { + $autocompleteStrings = []; + foreach ($userNames as $userName => $userDisplayName) { + $autocompleteStrings[$userName] = $userDisplayName . $this->suffixToIdentifyUsers; + } + } else { + $autocompleteStrings = $userNames . $this->suffixToIdentifyUsers; + } + return $autocompleteStrings; + } + /** * returns the group names as they could appear in an autocomplete list * @@ -252,7 +272,8 @@ public function shareWithUser( $name, Session $session, $maxRetries = 5, $quiet = false ) { $this->shareWithUserOrGroup( - $name, $name, $session, $maxRetries, $quiet + $name, $name . $this->suffixToIdentifyUsers, + $session, $maxRetries, $quiet ); } diff --git a/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature b/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature index f566c7140324..4b946a785703 100644 --- a/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature +++ b/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature @@ -24,7 +24,7 @@ Feature: restrict Sharing Scenario: Restrict users to only share with users in their groups Given the setting "Restrict users to only share with users in their groups" in the section "Sharing" has been enabled When the user browses to the files page - Then it should not be possible to share folder "simple-folder" with "User Three" using the webUI + Then it should not be possible to share folder "simple-folder" with user "User Three" using the webUI When the user shares folder "simple-folder" with user "User One" using the webUI And the user re-logs in as "user1" using the webUI Then folder "simple-folder (2)" should be listed on the webUI @@ -34,7 +34,7 @@ Feature: restrict Sharing Scenario: Restrict users to only share with groups they are member of Given the setting "Restrict users to only share with groups they are member of" in the section "Sharing" has been enabled When the user browses to the files page - Then it should not be possible to share folder "simple-folder" with "grp2" using the webUI + Then it should not be possible to share folder "simple-folder" with group "grp2" using the webUI When the user shares folder "simple-folder" with group "grp1" using the webUI And the user re-logs in as "user1" using the webUI Then folder "simple-folder (2)" should be listed on the webUI @@ -52,8 +52,8 @@ Feature: restrict Sharing Scenario: Forbid sharing with groups Given the setting "Allow sharing with groups" in the section "Sharing" has been disabled When the user browses to the files page - Then it should not be possible to share folder "simple-folder" with "grp1" using the webUI - And it should not be possible to share folder "simple-folder" with "grp2" using the webUI + Then it should not be possible to share folder "simple-folder" with group "grp1" using the webUI + And it should not be possible to share folder "simple-folder" with group "grp2" using the webUI When the user shares folder "simple-folder" with user "User One" using the webUI And the user re-logs in as "user1" using the webUI Then folder "simple-folder (2)" should be listed on the webUI