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 002f469 commit 69c4209
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 28 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
71 changes: 51 additions & 20 deletions tests/acceptance/features/bootstrap/WebUISharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}

Expand Down Expand Up @@ -878,7 +882,7 @@ public function allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedIn
$requiredString
) {
$this->allUsersAndGroupsThatContainTheStringInTheirNameShouldBeListedInTheAutocompleteListExcept(
$requiredString, '', ''
$requiredString, 'user', ''
);
}

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

Expand Down Expand Up @@ -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) {
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 69c4209

Please sign in to comment.