From ebb85b013469473c7dd5d88950bd3699be980b49 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Thu, 24 Aug 2017 15:32:39 +0545 Subject: [PATCH] UI tests for sharing feature --- .../ui/features/bootstrap/BasicStructure.php | 8 ++ .../ui/features/bootstrap/SharingContext.php | 44 +++++++++ tests/ui/features/lib/FilesPage.php | 11 +++ .../features/lib/FilesPageElement/FileRow.php | 36 ++++++- .../lib/FilesPageElement/SharingDialog.php | 96 ++++++++++++++++++- tests/ui/features/lib/OwncloudPage.php | 4 + .../lib/OwncloudPageElement/SettingsMenu.php | 44 +++++++++ tests/ui/features/other/sharing.feature | 45 +++++++++ 8 files changed, 282 insertions(+), 6 deletions(-) create mode 100644 tests/ui/features/lib/OwncloudPageElement/SettingsMenu.php create mode 100644 tests/ui/features/other/sharing.feature diff --git a/tests/ui/features/bootstrap/BasicStructure.php b/tests/ui/features/bootstrap/BasicStructure.php index cdd1c10d0216..8aa5945dd61c 100644 --- a/tests/ui/features/bootstrap/BasicStructure.php +++ b/tests/ui/features/bootstrap/BasicStructure.php @@ -67,6 +67,14 @@ public function iAmLoggedInAsARegularUser() $this->filesPage->waitTillPageIsLoaded($this->getSession()); } + /** + * @When I logout + */ + public function iLogout() { + $settingsMenu = $this->owncloudPage->openSettingsMenu(); + $settingsMenu->logout(); + } + /** * @Given a regular user exists */ diff --git a/tests/ui/features/bootstrap/SharingContext.php b/tests/ui/features/bootstrap/SharingContext.php index 3b3343eee16b..5d5260e22015 100644 --- a/tests/ui/features/bootstrap/SharingContext.php +++ b/tests/ui/features/bootstrap/SharingContext.php @@ -166,6 +166,50 @@ public function theAutocompleteListShouldNotBeDisplayed() ); } + /** + * @Then /^the (file|folder) "([^"]*)" should be marked as shared(?: with "([^"]*)")? by "([^"]*)"$/ + * @return void + */ + public function theFileFolderShouldBeMarkedAsSharedBy( + $fileOrFolder, $itemName, $sharedWithGroup, $sharerName + ) { + //close any open sharing dialog + //if there is no dialog open and we try to close it + //an exception will be thrown, but we do not care + try { + $this->filesPage->closeSharingDialog(); + } catch (Exception $e) { + } + + $row = $this->filesPage->findFileRowByName($itemName, $this->getSession()); + $sharingBtn = $row->findSharingButton(); + PHPUnit_Framework_Assert::assertSame( + $sharerName, $sharingBtn->getText() + ); + $sharingDialog = $this->filesPage->openSharingDialog( + $itemName, $this->getSession() + ); + PHPUnit_Framework_Assert::assertSame( + $sharerName, $sharingDialog->getSharerName() + ); + if ($fileOrFolder === "folder") { + PHPUnit_Framework_Assert::assertContains( + "folder-shared.svg", + $row->findThumbnail()->getAttribute("style") + ); + PHPUnit_Framework_Assert::assertContains( + "folder-shared.svg", + $sharingDialog->findThumbnail()->getAttribute("style") + ); + } + if ($sharedWithGroup !== "") { + PHPUnit_Framework_Assert::assertSame( + $sharedWithGroup, + $sharingDialog->getSharedWithGroupName() + ); + } + } + /** * @BeforeScenario * This will run before EVERY scenario. diff --git a/tests/ui/features/lib/FilesPage.php b/tests/ui/features/lib/FilesPage.php index 5a6cb581c953..ec6177d118d1 100644 --- a/tests/ui/features/lib/FilesPage.php +++ b/tests/ui/features/lib/FilesPage.php @@ -201,6 +201,17 @@ public function openSharingDialog($fileName, Session $session) { return $fileRow->openSharingDialog(); } + /** + * closes an open sharing dialog + * + * @throws \SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException + * if no sharing dialog is open + * @return void + */ + public function closeSharingDialog() { + $this->getPage('FilesPageElement\\SharingDialog')->closeSharingDialog(); + } + /** * scrolls down the file list, to load not yet displayed files * diff --git a/tests/ui/features/lib/FilesPageElement/FileRow.php b/tests/ui/features/lib/FilesPageElement/FileRow.php index 855cbc5415ed..e2204c22f416 100644 --- a/tests/ui/features/lib/FilesPageElement/FileRow.php +++ b/tests/ui/features/lib/FilesPageElement/FileRow.php @@ -48,6 +48,7 @@ class FileRow extends OwnCloudPage { protected $fileRenameInputXpath = "//input[contains(@class,'filename')]"; protected $fileBusyIndicatorXpath = ".//*[@class='thumbnail' and contains(@style,'loading')]"; protected $fileTooltipXpath = ".//*[@class='tooltip-inner']"; + protected $thumbnailXpath = "//*[@class='thumbnail']"; /** * sets the NodeElement for the current file row @@ -113,21 +114,31 @@ public function openFileActionsMenu() { $actionMenu->setElement($actionMenuElement); return $actionMenu; } - + /** - * opens the sharing dialog + * finds and returns the share button element * * @throws ElementNotFoundException - * @return SharingDialog + * @return \Behat\Mink\Element\NodeElement */ - public function openSharingDialog() { + public function findSharingButton() { $shareBtn = $this->rowElement->find("xpath", $this->shareBtnXpath); if (is_null($shareBtn)) { throw new ElementNotFoundException( "could not find sharing button in fileRow" ); } - $shareBtn->click(); + return $shareBtn; + } + + /** + * opens the sharing dialog + * + * @throws ElementNotFoundException + * @return SharingDialog + */ + public function openSharingDialog() { + $this->findSharingButton()->click(); $this->waitTillElementIsNull($this->loadingIndicatorXpath); return $this->getPage("FilesPageElement\\SharingDialog"); } @@ -180,6 +191,21 @@ public function findTooltipElement() { return $element; } + /** + * finds and returns the thumbnail of the file + * + * @throws ElementNotFoundException + * @return \Behat\Mink\Element\NodeElement + */ + public function findThumbnail() { + $thumbnail = $this->rowElement->find("xpath", $this->thumbnailXpath); + if (is_null($thumbnail)) { + throw new ElementNotFoundException( + "could not find thumbnail of file " . $this->name + ); + } + return $thumbnail; + } /** * returns the tooltip text * diff --git a/tests/ui/features/lib/FilesPageElement/SharingDialog.php b/tests/ui/features/lib/FilesPageElement/SharingDialog.php index e08ac31a6479..2376e6b9db4f 100644 --- a/tests/ui/features/lib/FilesPageElement/SharingDialog.php +++ b/tests/ui/features/lib/FilesPageElement/SharingDialog.php @@ -45,6 +45,12 @@ class SharingDialog extends OwncloudPage { protected $autocompleteItemsTextXpath = "//*[@class='autocomplete-item-text']"; protected $shareWithCloseXpath = "/..//*[@class='close icon-close']"; protected $suffixToIdentifyGroups = " (group)"; + protected $sharerInformationXpath = ".//*[@class='reshare']"; + protected $sharedWithAndByRegEx = "^(?:[A-Z]\s)?Shared with you(?: and the group (.*))? by (.*)$"; + protected $thumbnailContainerXpath = ".//*[contains(@class,'thumbnailContainer')]"; + protected $thumbnailFromContainerXpath = "/a"; + + protected $sharedWithGroupAndSharerName = null; /** * @@ -173,7 +179,7 @@ private function shareWithUserOrGroup( } if ($userFound !== true) { - throw new ElementNotFoundException("could not share with '$name'"); + throw new ElementNotFoundException("could not share with '$nameToMatch'"); } } @@ -247,6 +253,94 @@ public function getShareWithTooltip() { return $shareWithTooltip->getText(); } + /** + * gets the Element with the information about who has shared the current file/folder + * this Element will contain the Avatar and some text + * + * @throws ElementNotFoundException + * @return \Behat\Mink\Element\NodeElement + */ + public function findSharerInformationItem() { + $sharerInformation = $this->find("xpath", $this->sharerInformationXpath); + if (is_null($sharerInformation)) { + throw new ElementNotFoundException("could not find sharer information"); + } + return $sharerInformation; + } + + /** + * gets the group that the file/folder was shared with + * and the user that shared it + * + * @throws \Exception + * @return array ["sharedWithGroup" => string, "sharer" => string] + */ + public function getSharedWithGroupAndSharerName() { + if (is_null($this->sharedWithGroupAndSharerName)) { + $text = $this->findSharerInformationItem()->getText(); + if (preg_match("/" . $this->sharedWithAndByRegEx . "/", $text, $matches)) { + $this->sharedWithGroupAndSharerName = [ + "sharedWithGroup" => $matches [1], + "sharer" => $matches [2] + ]; + } else { + throw new \Exception( + "could not find shared with group or sharer name" + ); + } + } + return $this->sharedWithGroupAndSharerName; + } + + /** + * gets the group that the file/folder was shared with + * + * @return mixed + */ + public function getSharedWithGroupName() { + return $this->getSharedWithGroupAndSharerName()["sharedWithGroup"]; + } + + /** + * gets the display name of the user that has shared the current file/folder + * + * @throws \Exception + * @return string + */ + public function getSharerName() { + return $this->getSharedWithGroupAndSharerName()["sharer"]; + } + + /** + * + * @throws ElementNotFoundException + * @return \Behat\Mink\Element\NodeElement of the whole container holding the + * thumbnail + */ + public function findThumbnailContainer() { + $thumbnailContainer = $this->find("xpath", $this->thumbnailContainerXpath); + if (is_null($thumbnailContainer)) { + throw new ElementNotFoundException("could not find thumbnailContainer"); + } + return $thumbnailContainer; + } + + /** + * + * @throws ElementNotFoundException + * @return \Behat\Mink\Element\NodeElement + */ + public function findThumbnail() { + $thumbnailContainer = $this->findThumbnailContainer(); + $thumbnail = $thumbnailContainer->find( + "xpath", $this->thumbnailFromContainerXpath + ); + if (is_null($thumbnail)) { + throw new ElementNotFoundException("could not find thumbnail"); + } + return $thumbnail; + } + /** * closes the sharing dialog panel * diff --git a/tests/ui/features/lib/OwncloudPage.php b/tests/ui/features/lib/OwncloudPage.php index 8865e6bb2ade..01e7b98a17e4 100644 --- a/tests/ui/features/lib/OwncloudPage.php +++ b/tests/ui/features/lib/OwncloudPage.php @@ -114,6 +114,10 @@ public function getNotifications() return $notificationsText; } + public function openSettingsMenu () { + $this->findById($this->userNameDispayId)->click(); + return $this->getPage("OwncloudPageElement\\SettingsMenu"); + } /** * finds the logged-in username displayed in the top right corner * @return string diff --git a/tests/ui/features/lib/OwncloudPageElement/SettingsMenu.php b/tests/ui/features/lib/OwncloudPageElement/SettingsMenu.php new file mode 100644 index 000000000000..3f8717a05644 --- /dev/null +++ b/tests/ui/features/lib/OwncloudPageElement/SettingsMenu.php @@ -0,0 +1,44 @@ + + * @copyright 2017 Artur Neumann artur@jankaritech.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ + +namespace Page\OwncloudPageElement; + +use Page\OwncloudPage; +use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException; + +/** + * The Settings Menu + * + */ +class SettingsMenu extends OwncloudPage { + protected $logoutButtonId = 'logout'; + + public function logout() { + $logoutButton = $this->findById($this->logoutButtonId); + if (is_null($logoutButton)) { + throw new ElementNotFoundException("could not find logout button"); + } + $logoutButton->click(); + } +} + \ No newline at end of file diff --git a/tests/ui/features/other/sharing.feature b/tests/ui/features/other/sharing.feature new file mode 100644 index 000000000000..d21949650c78 --- /dev/null +++ b/tests/ui/features/other/sharing.feature @@ -0,0 +1,45 @@ +Feature: Sharing + + Background: + Given these users exist: + |username|password|displayname|email | + |user1 |1234 |User One |u1@oc.com.np| + |user2 |1234 |User Two |u2@oc.com.np| + |user3 |1234 |User Three |u2@oc.com.np| + And these groups exist: + |groupname| + |grp1 | + And the user "user1" is in the group "grp1" + And the user "user2" is in the group "grp1" + And I am on the login page + And I login with username "user1" and password "1234" + And I logout + And I login with username "user2" and password "1234" + + Scenario: share a file & folder with another internal user + And the folder "simple-folder" is shared with the user "User One" + And the file "testimage.jpg" is shared with the user "User One" + And I logout + And I login with username "user1" and password "1234" + Then the folder "simple-folder (2)" should be listed + And the folder "simple-folder (2)" should be marked as shared by "User Two" + And the file "testimage (2).jpg" should be listed + And the file "testimage (2).jpg" should be marked as shared by "User Two" + + Scenario: share a folder with an internal group + And I logout + And I login with username "user3" and password "1234" + And the folder "simple-folder" is shared with the group "grp1" + And the file "testimage.jpg" is shared with the group "grp1" + And I logout + And I login with username "user1" and password "1234" + Then the folder "simple-folder (2)" should be listed + And the folder "simple-folder (2)" should be marked as shared with "grp1" by "User Three" + And the file "testimage (2).jpg" should be listed + And the file "testimage (2).jpg" should be marked as shared with "grp1" by "User Three" + And I logout + And I login with username "user2" and password "1234" + Then the folder "simple-folder (2)" should be listed + And the folder "simple-folder (2)" should be marked as shared with "grp1" by "User Three" + And the file "testimage (2).jpg" should be listed + And the file "testimage (2).jpg" should be marked as shared with "grp1" by "User Three" \ No newline at end of file