From f11dd6197fd50b7b26bd9dac6ab04392caab28d5 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 3 Jun 2019 12:34:11 +0545 Subject: [PATCH] Adjust webUI acceptance tests for multi-line approach to display share autocomplete --- .../features/bootstrap/Provisioning.php | 18 +++++++++- .../bootstrap/WebUISharingContext.php | 35 ++++++++++++------- .../lib/FilesPageElement/SharingDialog.php | 27 ++++++++++++-- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 87b39850ed97..9a8bccc682e1 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..6f4e9a2ffacc 100644 --- a/tests/acceptance/features/bootstrap/WebUISharingContext.php +++ b/tests/acceptance/features/bootstrap/WebUISharingContext.php @@ -878,7 +878,7 @@ public function allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedIn $requiredString ) { $this->allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedInTheAutocompleteListExcept( - $requiredString, '', '' + $requiredString, 'user', '' ); } @@ -898,27 +898,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 +986,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"); } } 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 ); }