Skip to content

Commit

Permalink
Adjust webUI acceptance tests for multi-line approach to display shar…
Browse files Browse the repository at this point in the history
…e autocomplete
  • Loading branch information
phil-davis committed Jun 3, 2019
1 parent e6f79f3 commit f11dd61
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
18 changes: 17 additions & 1 deletion tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
35 changes: 23 additions & 12 deletions tests/acceptance/features/bootstrap/WebUISharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public function allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedIn
$requiredString
) {
$this->allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedInTheAutocompleteListExcept(
$requiredString, '', ''
$requiredString, 'user', ''
);
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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");
}
}

Expand Down
27 changes: 24 additions & 3 deletions tests/acceptance/features/lib/FilesPageElement/SharingDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']/..";
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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
);
}

Expand Down

0 comments on commit f11dd61

Please sign in to comment.