diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-05-09 19:53:08 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-05-16 09:50:23 +0200 |
commit | 07a592bd27e297390b8d47a26381d38429cd13b4 (patch) | |
tree | 63cee6430f3e0d6223522ba31a5dcbcaa0353672 /tests | |
parent | f3a06259e4a58ba7e7b6b55bb595c98867add1bb (diff) | |
download | nextcloud-server-07a592bd27e297390b8d47a26381d38429cd13b4.tar.gz nextcloud-server-07a592bd27e297390b8d47a26381d38429cd13b4.zip |
Users list acceptance tests
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/acceptance/config/behat.yml | 2 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/AppNavigationContext.php | 119 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/AppSettingsContext.php | 101 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/DialogContext.php | 67 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/UsersSettingsContext.php | 61 | ||||
-rw-r--r-- | tests/acceptance/features/core/ElementWrapper.php | 38 | ||||
-rw-r--r-- | tests/acceptance/features/users.feature | 50 |
7 files changed, 394 insertions, 44 deletions
diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 3cd71eec047..bfdbfbacba2 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -8,8 +8,10 @@ default: - NextcloudTestServerContext - AppNavigationContext + - AppSettingsContext - CommentsAppContext - ContactsMenuContext + - DialogContext - FeatureContext - FileListContext - FilesAppContext diff --git a/tests/acceptance/features/bootstrap/AppNavigationContext.php b/tests/acceptance/features/bootstrap/AppNavigationContext.php index 9ef71a06065..a573c1fe222 100644 --- a/tests/acceptance/features/bootstrap/AppNavigationContext.php +++ b/tests/acceptance/features/bootstrap/AppNavigationContext.php @@ -1,9 +1,9 @@ <?php /** - * * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) - * + * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> + * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -25,45 +25,92 @@ use Behat\Behat\Context\Context; class AppNavigationContext implements Context, ActorAwareInterface { - use ActorAware; + use ActorAware; - /** - * @return Locator - */ - public static function appNavigation() { - return Locator::forThe()->id("app-navigation")-> - describedAs("App navigation"); - } + /** + * @return Locator + */ + public static function appNavigation() { + return Locator::forThe()->id("app-navigation")-> + describedAs("App navigation"); + } - /** - * @return Locator - */ - public static function appNavigationSectionItemFor($sectionText) { - return Locator::forThe()->xpath("//li[normalize-space() = '$sectionText']")-> - descendantOf(self::appNavigation())-> - describedAs($sectionText . " section item in App Navigation"); - } + /** + * @return Locator + */ + public static function appNavigationSectionItemFor($sectionText) { + return Locator::forThe()->xpath("//li/a[normalize-space() = '$sectionText']/..")-> + descendantOf(self::appNavigation())-> + describedAs($sectionText . " section item in App Navigation"); + } - /** - * @return Locator - */ - public static function appNavigationCurrentSectionItem() { - return Locator::forThe()->css(".active")->descendantOf(self::appNavigation())-> - describedAs("Current section item in App Navigation"); - } + /** + * @return Locator + */ + public static function appNavigationCurrentSectionItem() { + return Locator::forThe()->css(".active")-> + descendantOf(self::appNavigation())-> + describedAs("Current section item in App Navigation"); + } - /** - * @Given I open the :section section - */ - public function iOpenTheSection($section) { - $this->actor->find(self::appNavigationSectionItemFor($section), 10)->click(); - } + /** + * @return Locator + */ + public static function buttonForTheSection($class, $section) { + return Locator::forThe()->css("." . $class)-> + descendantOf(self::appNavigationSectionItemFor($section))-> + describedAs("The $class button on the $section section in App Navigation"); + } - /** - * @Then I see that the current section is :section - */ - public function iSeeThatTheCurrentSectionIs($section) { - PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::appNavigationCurrentSectionItem(), 10)->getText(), $section); + /** + * @return Locator + */ + public static function counterForTheSection($section) { + return Locator::forThe()->css(".app-navigation-entry-utils-counter")-> + descendantOf(self::appNavigationSectionItemFor($section))-> + describedAs("The counter for the $section section in App Navigation"); + } + + /** + * @Given I open the :section section + */ + public function iOpenTheSection($section) { + $this->actor->find(self::appNavigationSectionItemFor($section), 10)->click(); + } + + /** + * @Given I click the :class button on the :section section + */ + public function iClickTheButtonInTheSection($class, $section) { + $this->actor->find(self::buttonForTheSection($class, $section), 10)->click(); + } + + /** + * @Then I see that the current section is :section + */ + public function iSeeThatTheCurrentSectionIs($section) { + PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::appNavigationCurrentSectionItem(), 10)->getText(), $section); + } + + /** + * @Then I see that the section :section is shown + */ + public function iSeeThatTheSectionIsShown($section) { + WaitFor::elementToBeEventuallyShown($this->actor, self::appNavigationSectionItemFor($section)); + } + + /** + * @Then I see that the section :section is not shown + */ + public function iSeeThatTheSectionIsNotShown($section) { + WaitFor::elementToBeEventuallyNotShown($this->actor, self::appNavigationSectionItemFor($section)); } + /** + * @Then I see that the section :section has a count of :count + */ + public function iSeeThatTheSectionHasACountOf($section, $count) { + PHPUnit_Framework_Assert::assertEquals($this->actor->find(self::counterForTheSection($section), 10)->getText(), $count); + } + } diff --git a/tests/acceptance/features/bootstrap/AppSettingsContext.php b/tests/acceptance/features/bootstrap/AppSettingsContext.php new file mode 100644 index 00000000000..6b77b3aac00 --- /dev/null +++ b/tests/acceptance/features/bootstrap/AppSettingsContext.php @@ -0,0 +1,101 @@ +<?php + +/** + * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) + * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +use Behat\Behat\Context\Context; + +class AppSettingsContext implements Context, ActorAwareInterface { + + use ActorAware; + + /** + * @return Locator + */ + public static function appSettings() { + return Locator::forThe()->id("app-settings")-> + describedAs("App settings"); + } + /** + * @return Locator + */ + public static function appSettingsContent() { + return Locator::forThe()->id("app-settings-content")-> + descendantOf(self::appSettings())-> + describedAs("App settings"); + } + + /** + * @return Locator + */ + public static function appSettingsOpenButton() { + return Locator::forThe()->xpath("//div[@id = 'app-settings-header']/button")-> + descendantOf(self::appSettings())-> + describedAs("The button to open the app settings"); + } + + /** + * @return Locator + */ + public static function checkboxInTheSettings($id) { + return Locator::forThe()->xpath("//input[@id = '$id']")-> + descendantOf(self::appSettingsContent())-> + describedAs("The $id checkbox in the settings"); + } + + /** + * @return Locator + */ + public static function checkboxLabelInTheSettings($id) { + return Locator::forThe()->xpath("//label[@for = '$id']")-> + descendantOf(self::appSettingsContent())-> + describedAs("The label for the $id checkbox in the settings"); + } + + /** + * @Given I open the settings + */ + public function iOpenTheSettings() { + $this->actor->find(self::appSettingsOpenButton())->click(); + } + + /** + * @Given I toggle the :id checkbox in the settings + */ + public function iToggleTheCheckboxInTheSettingsTo($id) { + $locator = self::CheckboxInTheSettings($id); + + // If locator is not visible, fallback to label + if (!$this->actor->find(self::CheckboxInTheSettings($id))->isVisible()) { + $locator = self::checkboxLabelInTheSettings($id); + } + + $this->actor->find($locator)->click(); + } + + /** + * @Then I see that the settings are opened + */ + public function iSeeThatTheSettingsAreOpened() { + WaitFor::elementToBeEventuallyShown($this->actor, self::appSettingsContent()); + } + +} diff --git a/tests/acceptance/features/bootstrap/DialogContext.php b/tests/acceptance/features/bootstrap/DialogContext.php new file mode 100644 index 00000000000..5fa2ad45f72 --- /dev/null +++ b/tests/acceptance/features/bootstrap/DialogContext.php @@ -0,0 +1,67 @@ +<?php + +/** + * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +use Behat\Behat\Context\Context; + +class DialogContext implements Context, ActorAwareInterface { + + use ActorAware; + + /** + * @return Locator + */ + public static function theDialog() { + return Locator::forThe()->css(".oc-dialog")-> + describedAs("The dialog"); + } + + /** + * @return Locator + */ + public static function theDialogButton($text) { + return Locator::forThe()->xpath("//button[normalize-space() = '$text']")-> + descendantOf(self::theDialog())-> + describedAs($text . " button of the dialog"); + } + + /** + * @Given I click the :text button of the confirmation dialog + */ + public function iClickTheDialogButton($text) { + $this->actor->find(self::theDialogButton($text), 10)->click(); + } + + /** + * @Then I see that the confirmation dialog is shown + */ + public function iSeeThatTheConfirmationDialogIsShown() { + WaitFor::elementToBeEventuallyShown($this->actor, self::theDialog()); + } + + /** + * @Then I see that the confirmation dialog is not shown + */ + public function iSeeThatTheConfirmationDialogIsNotShown() { + WaitFor::elementToBeEventuallyNotShown($this->actor, self::theDialog()); + } + +} diff --git a/tests/acceptance/features/bootstrap/UsersSettingsContext.php b/tests/acceptance/features/bootstrap/UsersSettingsContext.php index 1f488e4f52b..0e26f3e9b21 100644 --- a/tests/acceptance/features/bootstrap/UsersSettingsContext.php +++ b/tests/acceptance/features/bootstrap/UsersSettingsContext.php @@ -1,8 +1,8 @@ <?php /** - * * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) + * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> * * @license GNU AGPL version 3 or any later version * @@ -86,6 +86,14 @@ class UsersSettingsContext implements Context, ActorAwareInterface { /** * @return Locator */ + public static function groupsCellForUser($user) { + return Locator::forThe()->css(".groups")->descendantOf(self::rowForUser($user))-> + describedAs("Groups cell for user $user in Users Settings"); + } + + /** + * @return Locator + */ public static function passwordInputForUser($user) { return Locator::forThe()->css("input")->descendantOf(self::passwordCellForUser($user))-> describedAs("Password input for user $user in Users Settings"); @@ -94,6 +102,22 @@ class UsersSettingsContext implements Context, ActorAwareInterface { /** * @return Locator */ + public static function groupsInputForUser($user) { + return Locator::forThe()->css("input")->descendantOf(self::groupsCellForUser($user))-> + describedAs("Groups input for user $user in Users Settings"); + } + + /** + * @return Locator + */ + public static function groupOptionInInputForUser($user) { + return Locator::forThe()->css(".multiselect__option--highlight")->descendantOf(self::groupsCellForUser($user))-> + describedAs("Group option for input for user $user in Users Settings"); + } + + /** + * @return Locator + */ public static function actionsMenuOf($user) { return Locator::forThe()->css(".icon-more")->descendantOf(self::rowForUser($user))-> describedAs("Actions menu for user $user in Users Settings"); @@ -103,12 +127,20 @@ class UsersSettingsContext implements Context, ActorAwareInterface { * @return Locator */ public static function theAction($action, $user) { - return Locator::forThe()->xpath("//button/span[normalize-space() = '$action']/..")-> + return Locator::forThe()->xpath("//button[normalize-space() = '$action']")-> descendantOf(self::rowForUser($user))-> describedAs("$action action for the user $user"); } /** + * @return Locator + */ + public static function theColumn($column) { + return Locator::forThe()->xpath("//div[@class='user-list-grid']//div[normalize-space() = '$column']")-> + describedAs("The $column column"); + } + + /** * @When I click the New user button */ public function iClickTheNewUserButton() { @@ -116,7 +148,7 @@ class UsersSettingsContext implements Context, ActorAwareInterface { } /** - * @When I click the $action action in the $user actions menu + * @When I click the :action action in the :user actions menu */ public function iClickTheAction($action, $user) { $this->actor->find(self::theAction($action, $user))->click(); @@ -142,22 +174,29 @@ class UsersSettingsContext implements Context, ActorAwareInterface { * @When I set the password for :user to :password */ public function iSetThePasswordForUserTo($user, $password) { - $this->actor->find(self::passwordCellForUser($user), 10)->click(); $this->actor->find(self::passwordInputForUser($user), 2)->setValue($password . "\r"); } /** + * @When I assign the user :user to the group :group + */ + public function iAssignTheUserToTheGroup($user, $group) { + $this->actor->find(self::groupsInputForUser($user))->setValue($group); + $this->actor->find(self::groupOptionInInputForUser($user))->click(); + } + + /** * @Then I see that the list of users contains the user :user */ public function iSeeThatTheListOfUsersContainsTheUser($user) { - PHPUnit_Framework_Assert::assertNotNull($this->actor->find(self::rowForUser($user), 10)); + WaitFor::elementToBeEventuallyShown($this->actor, self::rowForUser($user)); } /** * @Then I see that the list of users does not contains the user :user */ public function iSeeThatTheListOfUsersDoesNotContainsTheUser($user) { - PHPUnit_Framework_Assert::assertNull($this->actor->find(self::rowForUser($user), 10)); + WaitFor::elementToBeEventuallyNotShown($this->actor, self::rowForUser($user)); } /** @@ -169,11 +208,19 @@ class UsersSettingsContext implements Context, ActorAwareInterface { } /** - * @Then I see the $action action in the $user actions menu + * @Then I see that the :action action in the :user actions menu is shown */ public function iSeeTheAction($action, $user) { PHPUnit_Framework_Assert::assertTrue( $this->actor->find(self::theAction($action, $user), 10)->isVisible()); } + /** + * @Then I see that the :column column is shown + */ + public function iSeeThatTheColumnIsShown($column) { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::theColumn($column), 10)->isVisible()); + } + } diff --git a/tests/acceptance/features/core/ElementWrapper.php b/tests/acceptance/features/core/ElementWrapper.php index 7d7a86149ed..c866ea699fe 100644 --- a/tests/acceptance/features/core/ElementWrapper.php +++ b/tests/acceptance/features/core/ElementWrapper.php @@ -148,6 +148,18 @@ class ElementWrapper { } /** + * Returns whether the wrapped element is checked or not. + * + * @return bool true if the wrapped element is checked, false otherwise. + */ + public function isChecked() { + $commandCallback = function() { + return $this->element->isChecked(); + }; + return $this->executeCommand($commandCallback, "check state could not be got"); + } + + /** * Returns the text of the wrapped element. * * If the wrapped element is not visible the returned text is an empty @@ -206,6 +218,32 @@ class ElementWrapper { } /** + * Check the wrapped element. + * + * If automatically waits for the wrapped element to be visible (up to the + * timeout set when finding it). + */ + public function check() { + $commandCallback = function() { + $this->element->check(); + }; + $this->executeCommand($commandCallback, "could not be checked"); + } + + /** + * uncheck the wrapped element. + * + * If automatically waits for the wrapped element to be visible (up to the + * timeout set when finding it). + */ + public function uncheck() { + $commandCallback = function() { + $this->element->uncheck(); + }; + $this->executeCommand($commandCallback, "could not be unchecked"); + } + + /** * Executes the given command. * * If a StaleElementReference or a NoSuchElement exception is thrown the diff --git a/tests/acceptance/features/users.feature b/tests/acceptance/features/users.feature index 3b916285501..8c9ffb57fb5 100644 --- a/tests/acceptance/features/users.feature +++ b/tests/acceptance/features/users.feature @@ -15,7 +15,55 @@ Feature: users And I open the User settings And I see that the list of users contains the user user0 And I open the actions menu for the user user0 - And I see the "Delete user" action in the user0 actions menu + And I see that the "Delete user" action in the user0 actions menu is shown When I click the "Delete user" action in the user0 actions menu Then I see that the list of users does not contains the user user0 + Scenario: disable a user + Given I act as Jane + And I am logged in as the admin + And I open the User settings + And I see that the list of users contains the user user0 + And I open the actions menu for the user user0 + And I see that the "Disable user" action in the user0 actions menu is shown + When I click the "Disable user" action in the user0 actions menu + Then I see that the list of users does not contains the user user0 + When I open the "Disabled users" section + Then I see that the list of users contains the user user0 + + Scenario: assign user to a group + Given I act as Jane + And I am logged in as the admin + And I open the User settings + And I see that the list of users contains the user user0 + When I assign the user user0 to the group admin + Then I see that the section Admins is shown + And I see that the section Admins has a count of 2 + + Scenario: create and delete a group + Given I act as Jane + And I am logged in as the admin + And I open the User settings + And I see that the list of users contains the user user0 + And I assign the user user0 to the group Group1 + And I see that the section Group1 is shown + And I click the "icon-delete" button on the Group1 section + And I see that the confirmation dialog is shown + When I click the "Yes" button of the confirmation dialog + Then I see that the section Group1 is not shown + + Scenario: change columns visibility + Given I act as Jane + And I am logged in as the admin + And I open the User settings + And I open the settings + And I see that the settings are opened + When I toggle the showLanguages checkbox in the settings + Then I see that the "Languages" column is shown + When I toggle the showLastLogin checkbox in the settings + Then I see that the "Last login" column is shown + When I toggle the showStoragePath checkbox in the settings + Then I see that the "Storage location" column is shown + When I toggle the showUserBackend checkbox in the settings + Then I see that the "User backend" column is shown + |