Skip to content

Commit

Permalink
Merge pull request #28793 from owncloud/stable10-ui-tests-sharing
Browse files Browse the repository at this point in the history
[stable10] UI tests for sharing feature
  • Loading branch information
Vincent Petry authored Aug 24, 2017
2 parents ff02ba2 + ebb85b0 commit 72bc588
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 6 deletions.
8 changes: 8 additions & 0 deletions tests/ui/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
44 changes: 44 additions & 0 deletions tests/ui/features/bootstrap/SharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/features/lib/FilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
36 changes: 31 additions & 5 deletions tests/ui/features/lib/FilesPageElement/FileRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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
*
Expand Down
96 changes: 95 additions & 1 deletion tests/ui/features/lib/FilesPageElement/SharingDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down Expand Up @@ -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
*
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/features/lib/OwncloudPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions tests/ui/features/lib/OwncloudPageElement/SettingsMenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* ownCloud
*
* @author Artur Neumann <artur@jankaritech.com>
* @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 <http://www.gnu.org/licenses/>.
*
*/

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();
}
}

45 changes: 45 additions & 0 deletions tests/ui/features/other/sharing.feature
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 72bc588

Please sign in to comment.