Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI tests for federation sharing #29097

Merged
merged 1 commit into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ env:
- TC=litmus-v2
- SRV_HOST_NAME=owncloud
- SRV_HOST_PORT=8889
- REMOTE_FED_SRV_HOST_NAME=owncloud
- REMOTE_FED_SRV_HOST_PORT=8989
matrix:
- DB=sqlite

Expand Down
5 changes: 5 additions & 0 deletions tests/travis/start_php_dev_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ fi

start_php_dev_server $SRV_HOST_NAME:$SRV_HOST_PORT primary

if [ ! -z "$REMOTE_FED_SRV_HOST_NAME" ] && [ ! -z "$REMOTE_FED_SRV_HOST_PORT" ]
then
start_php_dev_server $REMOTE_FED_SRV_HOST_NAME:$REMOTE_FED_SRV_HOST_PORT REMOTE_FEDERATION
fi

if [ ! -z "$IPV4_HOST_NAME" ] && [ "$SRV_HOST_NAME" != "$IPV4_HOST_NAME" ]
then
start_php_dev_server $IPV4_HOST_NAME:$SRV_HOST_PORT IPv4
Expand Down
12 changes: 12 additions & 0 deletions tests/travis/start_ui_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,18 @@ else
fi

BASE_URL="http://$SRV_HOST_NAME"
REMOTE_FED_BASE_URL=$REMOTE_FED_SRV_HOST_NAME

if [ ! -z "$SRV_HOST_PORT" ] && [ "$SRV_HOST_PORT" != "80" ]
then
BASE_URL="$BASE_URL:$SRV_HOST_PORT"
fi

if [ ! -z "$REMOTE_FED_SRV_HOST_PORT" ] && [ "$REMOTE_FED_SRV_HOST_PORT" != "80" ]
then
REMOTE_FED_BASE_URL="$REMOTE_FED_BASE_URL:$REMOTE_FED_SRV_HOST_PORT"
fi

IPV4_URL="$BASE_URL"

if [ ! -z "$IPV4_HOST_NAME" ]
Expand Down Expand Up @@ -125,6 +131,11 @@ then
IPV6_URL="$IPV6_URL/$SRV_HOST_URL"
fi

if [ -n "$REMOTE_FED_SRV_HOST_URL" ]
then
REMOTE_FED_BASE_URL="$REMOTE_FED_BASE_URL/$REMOTE_FED_SRV_HOST_URL"
fi

if [ "$BROWSER" == "firefox" ]
then
#set screen resolution so that hopefully dragable elements will be visible
Expand All @@ -143,6 +154,7 @@ echo "Running tests on '$BROWSER' ($BROWSER_VERSION) on $PLATFORM"
export BEHAT_PARAMS='{"extensions" : {"Behat\\MinkExtension" : {"browser_name": "'$BROWSER'", "base_url" : "'$BASE_URL'", "selenium2":{"capabilities": {"browser": "'$BROWSER'", "version": "'$BROWSER_VERSION'", "platform": "'$PLATFORM'", "name": "'$TRAVIS_REPO_SLUG' - '$TRAVIS_JOB_NUMBER'", "extra_capabilities": {'$EXTRA_CAPABILITIES'}}, "wd_host":"http://'$SAUCE_USERNAME:$SAUCE_ACCESS_KEY'@localhost:4445/wd/hub"}}}}'
export IPV4_URL
export IPV6_URL
export REMOTE_FED_BASE_URL

lib/composer/bin/behat -c $BEHAT_YML $BEHAT_SUITE_OPTION $BEHAT_TAG_OPTION $BEHAT_TAGS $BEHAT_FEATURE -v

Expand Down
26 changes: 26 additions & 0 deletions tests/ui/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,17 @@ public function getUserPassword($username) {
return (string) $password;
}

/**
* gets the base url but without "http(s)://" in front of it
*
* @return string
*/
public function getBaseUrlWithoutScheme() {
return preg_replace(
"(^https?://)", "", $this->getMinkParameter('base_url')
);
}

/**
* substitutes codes like %base_url% with the value
* if the given value does not have anything to be substituted
Expand All @@ -406,6 +417,21 @@ public function substituteInLineCodes($value) {
"base_url"
]
],
[
"code" => "%remote_server%",
"function" => "getenv",
"parameter" => [
"REMOTE_FED_BASE_URL"
]
],
[
"code" => "%local_server%",
"function" => [
$this,
"getBaseUrlWithoutScheme"
],
"parameter" => [ ]
],
[
"code" => "%regularuser%",
"function" => [
Expand Down
25 changes: 25 additions & 0 deletions tests/ui/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ public function notificationsShouldBeDisplayedWithTheText(TableNode $table) {
}
}

/**
* @Then dialogs should be displayed
* @param TableNode $table of expected dialogs format must be:
* | title | content |
* @return void
*/
public function dialogsShouldBeDisplayed(TableNode $table) {
$dialogs = $this->owncloudPage->getOcDialogs();
$dialogCounter = 0;
foreach ($table as $expectedDialog) {
PHPUnit_Framework_Assert::assertEquals(
$expectedDialog['title'],
$dialogs[$dialogCounter]->getTitle()
);
$expectedDialog['content'] = $this->substituteInLineCodes(
$expectedDialog['content']
);
PHPUnit_Framework_Assert::assertEquals(
$expectedDialog['content'],
$dialogs[$dialogCounter]->getMessage()
);
$dialogCounter++;
}
}

/**
* @Then I should be redirected to a page with the title :title
* @param string $title
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/features/bootstrap/LoginContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ public function iLoginWithUsernameAndPassword($username, $password) {
$this->filesPage->waitTillPageIsLoaded($this->getSession());
}

/**
* @When I login with username :username and password :password to :server
* @param string $username
* @param string $password
* @param string $server
* @return void
*/
public function iLoginWithUsernameAndPasswordToSrv(
$username, $password, $server
) {
$server = $this->featureContext->substituteInLineCodes($server);
$this->loginPage->setPagePath(
$server . $this->loginPage->getOriginalPath()
);
$this->loginPage->open();
$this->iLoginWithUsernameAndPassword($username, $password);
}

/**
* @When I login with username :username and invalid password :password
* @param string $username
Expand Down
36 changes: 27 additions & 9 deletions tests/ui/features/bootstrap/SharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SharingContext extends RawMinkContext implements Context {
private $regularUserNames;
private $regularGroupName;
private $regularGroupNames;
private $featureContext;

/**
* SharingContext constructor.
Expand All @@ -51,17 +52,23 @@ public function __construct(FilesPage $filesPage) {
}

/**
* @Given the file/folder :folder is shared with the user :user
* @Given /^the (?:file|folder) "([^"]*)" is shared with the (?:(remote)\s)?user "([^"]*)"$/
* @param string $folder
* @param string $remote
* @param string $user
* @return void
*/
public function theFileFolderIsSharedWithTheUser($folder, $user) {
public function theFileFolderIsSharedWithTheUser($folder, $remote, $user) {
$this->filesPage->waitTillPageIsloaded($this->getSession());
$this->sharingDialog = $this->filesPage->openSharingDialog(
$folder, $this->getSession()
);
$this->sharingDialog->shareWithUser($user, $this->getSession());
$user = $this->featureContext->substituteInLineCodes($user);
if ($remote === "remote") {
$this->sharingDialog->shareWithRemoteUser($user, $this->getSession());
} else {
$this->sharingDialog->shareWithUser($user, $this->getSession());
}
$this->iCloseTheShareDialog();
}

Expand Down Expand Up @@ -124,12 +131,23 @@ public function iTypeInTheShareWithField($input) {
public function theSharingPermissionsOfAreSetTo(
$userName, $fileName, TableNode $permissionsTable
) {
$userName = $this->featureContext->substituteInLineCodes($userName);
$this->theShareDialogForTheFileFolderIsOpen($fileName);
$this->sharingDialog->setSharingPermissions(
$userName, $permissionsTable->getRowsHash()
);
}

/**
* @When the offered remote shares are accepted
* @return void
*/
public function theOfferedRemoteSharesAreAccepted() {
foreach (array_reverse($this->filesPage->getOcDialogs()) as $ocDialog) {
$ocDialog->accept($this->getSession());
}
}

/**
* @Then all users and groups that contain the string :requiredString in their name should be listed in the autocomplete list
* @param string $requiredString
Expand Down Expand Up @@ -270,7 +288,7 @@ public function theFileFolderShouldBeMarkedAsSharedBy(
*/
public function itShouldNotBePossibleToShare($name) {
try {
$this->theFileFolderIsSharedWithTheUser($name, null);
$this->theFileFolderIsSharedWithTheUser($name, null, null);
} catch (ElementNotFoundException $e) {
PHPUnit_Framework_Assert::assertSame(
'could not find share-with-field',
Expand All @@ -290,10 +308,10 @@ public function before(BeforeScenarioScope $scope) {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$featureContext = $environment->getContext('FeatureContext');
$this->regularUserNames = $featureContext->getRegularUserNames();
$this->regularUserName = $featureContext->getRegularUserName();
$this->regularGroupNames = $featureContext->getRegularGroupNames();
$this->regularGroupName = $featureContext->getRegularGroupName();
$this->featureContext = $environment->getContext('FeatureContext');
$this->regularUserNames = $this->featureContext->getRegularUserNames();
$this->regularUserName = $this->featureContext->getRegularUserName();
$this->regularGroupNames = $this->featureContext->getRegularGroupNames();
$this->regularGroupName = $this->featureContext->getRegularGroupName();
}
}
2 changes: 1 addition & 1 deletion tests/ui/features/lib/FilesPageBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function openFile($name, Session $session) {
public function deleteFile($name, Session $session) {
$row = $this->findFileRowByName($name, $session);
$row->delete();
$this->waitForAjaxCallsToStartAndFinish($session);
$this->waitForOutstandingAjaxCalls($session);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/ui/features/lib/FilesPageElement/FileRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function rename($toName) {
public function delete() {
$actionMenu = $this->openFileActionsMenu();
$actionMenu->delete();
$this->waitTillElementIsNull($this->fileBusyIndicatorXpath);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/features/lib/FilesPageElement/SharingDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SharingDialog extends OwncloudPage {
protected $autocompleteItemsTextXpath = "//*[@class='autocomplete-item-text']";
protected $shareWithCloseXpath = "/..//*[@class='close icon-close']";
protected $suffixToIdentifyGroups = " (group)";
protected $suffixToIdentifyRemoteUsers = " (remote)";
protected $sharerInformationXpath = ".//*[@class='reshare']";
protected $sharedWithAndByRegEx = "^(?:[A-Z]\s)?Shared with you(?: and the group (.*))? by (.*)$";
protected $thumbnailContainerXpath = ".//*[contains(@class,'thumbnailContainer')]";
Expand Down Expand Up @@ -184,6 +185,19 @@ public function shareWithUser($name, Session $session) {
return $this->shareWithUserOrGroup($name, $name, $session);
}

/**
*
* @param string $name
* @param Session $session
* @throws \SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException
* @return void
*/
public function shareWithRemoteUser($name, Session $session) {
return $this->shareWithUserOrGroup(
$name, $name . $this->suffixToIdentifyRemoteUsers, $session
);
}

/**
*
* @param string $name
Expand Down
60 changes: 57 additions & 3 deletions tests/ui/features/lib/OwncloudPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@
use Behat\Mink\Element\NodeElement;
use WebDriver\Exception as WebDriverException;
use WebDriver\Key;
use Page\OwncloudPageElement\OCDialog;

/**
* Owncloud page.
*/
class OwncloudPage extends Page {

protected $userNameDispayId = "expandDisplayName";
protected $userNameDisplayId = "expandDisplayName";
protected $ocDialogXpath = ".//*[@class='oc-dialog']";

/**
* used to store the unchanged path string when $path gets changed
*
* @var string
*/
protected $originalPath = null;

/**
* @param Session $session
Expand Down Expand Up @@ -138,13 +147,33 @@ public function getNotifications() {
return $notificationsText;
}

/**
* Get all open oc dialogs
*
* @return OCDialog[]
*/
public function getOcDialogs() {
$ocDialogs = [];
$ocDialogElements = $this->findAll("xpath", $this->ocDialogXpath);
foreach ($ocDialogElements as $element) {
/**
*
* @var \Page\OwncloudPageElement\OCDialog $ocDialog
*/
$ocDialog = $this->getPage("OwncloudPageElement\\OCDialog");
$ocDialog->setElement($element);
$ocDialogs[] = $ocDialog;
}
return $ocDialogs;
}

/**
* Open the settings menu
*
* @return Page
*/
public function openSettingsMenu() {
$this->findById($this->userNameDispayId)->click();
$this->findById($this->userNameDisplayId)->click();
return $this->getPage("OwncloudPageElement\\SettingsMenu");
}
/**
Expand All @@ -153,7 +182,7 @@ public function openSettingsMenu() {
* @return string
*/
public function getMyUsername() {
return $this->findById($this->userNameDispayId)->getText();
return $this->findById($this->userNameDisplayId)->getText();
}

/**
Expand All @@ -165,6 +194,31 @@ public function getPagePath() {
return $this->getPath();
}

/**
*
* @param string $path
* @return void
*/
public function setPagePath($path) {
if ($this->originalPath === null) {
$this->originalPath = $this->path;
}
$this->path = $path;
}

/**
* returns the unchanged path
*
* @return string
*/
public function getOriginalPath() {
if ($this->originalPath !== null) {
return $this->originalPath;
} else {
return $this->getPath();
}
}

/**
* Gets the Coordinates of a Mink Element
*
Expand Down
Loading