diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-04-21 14:35:19 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-04-21 14:44:29 +0200 |
commit | 2f80025ec25dd3ce19c0664f07073399e9bf99e9 (patch) | |
tree | 9cb469bcf60bcb91c6462d8cd13834ad5d7a9482 /tests/acceptance/features/bootstrap | |
parent | f89c16f83e33a38bf9a906b990c661b69eddd1e5 (diff) | |
download | nextcloud-server-2f80025ec25dd3ce19c0664f07073399e9bf99e9.tar.gz nextcloud-server-2f80025ec25dd3ce19c0664f07073399e9bf99e9.zip |
Move acceptance tests from build/acceptance to tests/acceptance
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'tests/acceptance/features/bootstrap')
6 files changed, 491 insertions, 0 deletions
diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php new file mode 100644 index 00000000000..a125ea01ccc --- /dev/null +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -0,0 +1,37 @@ +<?php + +/** + * + * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.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 FeatureContext implements Context, ActorAwareInterface { + + use ActorAware; + + /** + * @When I visit the Home page + */ + public function iVisitTheHomePage() { + $this->actor->getSession()->visit($this->actor->locatePath("/")); + } + +} diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php new file mode 100644 index 00000000000..9702e64b552 --- /dev/null +++ b/tests/acceptance/features/bootstrap/FilesAppContext.php @@ -0,0 +1,39 @@ +<?php + +/** + * + * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.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 FilesAppContext implements Context, ActorAwareInterface { + + use ActorAware; + + /** + * @Then I see that the current page is the Files app + */ + public function iSeeThatTheCurrentPageIsTheFilesApp() { + PHPUnit_Framework_Assert::assertStringStartsWith( + $this->actor->locatePath("/apps/files/"), + $this->actor->getSession()->getCurrentUrl()); + } + +} diff --git a/tests/acceptance/features/bootstrap/LoginPageContext.php b/tests/acceptance/features/bootstrap/LoginPageContext.php new file mode 100644 index 00000000000..55db8c33bb7 --- /dev/null +++ b/tests/acceptance/features/bootstrap/LoginPageContext.php @@ -0,0 +1,137 @@ +<?php + +/** + * + * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.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; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; + +class LoginPageContext implements Context, ActorAwareInterface { + + use ActorAware; + + /** + * @var FeatureContext + */ + private $featureContext; + + /** + * @var FilesAppContext + */ + private $filesAppContext; + + /** + * @return Locator + */ + public static function userNameField() { + return Locator::forThe()->field("user")-> + describedAs("User name field in Login page"); + } + + /** + * @return Locator + */ + public static function passwordField() { + return Locator::forThe()->field("password")-> + describedAs("Password field in Login page"); + } + + /** + * @return Locator + */ + public static function loginButton() { + return Locator::forThe()->id("submit")-> + describedAs("Login button in Login page"); + } + + /** + * @return Locator + */ + public static function wrongPasswordMessage() { + return Locator::forThe()->content("Wrong password. Reset it?")-> + describedAs("Wrong password message in Login page"); + } + + /** + * @When I log in with user :user and password :password + */ + public function iLogInWithUserAndPassword($user, $password) { + $this->actor->find(self::userNameField(), 10)->setValue($user); + $this->actor->find(self::passwordField())->setValue($password); + $this->actor->find(self::loginButton())->click(); + } + + /** + * @Then I see that the current page is the Login page + */ + public function iSeeThatTheCurrentPageIsTheLoginPage() { + PHPUnit_Framework_Assert::assertStringStartsWith( + $this->actor->locatePath("/login"), + $this->actor->getSession()->getCurrentUrl()); + } + + /** + * @Then I see that a wrong password message is shown + */ + public function iSeeThatAWrongPasswordMessageIsShown() { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::wrongPasswordMessage(), 10)->isVisible()); + } + + /** + * @BeforeScenario + */ + public function getOtherRequiredSiblingContexts(BeforeScenarioScope $scope) { + $environment = $scope->getEnvironment(); + + $this->featureContext = $environment->getContext("FeatureContext"); + $this->filesAppContext = $environment->getContext("FilesAppContext"); + } + + /** + * @Given I am logged in + */ + public function iAmLoggedIn() { + $this->featureContext->iVisitTheHomePage(); + $this->iLogInWithUserAndPassword("user0", "123456"); + $this->filesAppContext->iSeeThatTheCurrentPageIsTheFilesApp(); + } + + /** + * @Given I am logged in as the admin + */ + public function iAmLoggedInAsTheAdmin() { + $this->featureContext->iVisitTheHomePage(); + $this->iLogInWithUserAndPassword("admin", "admin"); + $this->filesAppContext->iSeeThatTheCurrentPageIsTheFilesApp(); + } + + /** + * @Given I can not log in with user :user and password :password + */ + public function iCanNotLogInWithUserAndPassword($user, $password) { + $this->featureContext->iVisitTheHomePage(); + $this->iLogInWithUserAndPassword($user, $password); + $this->iSeeThatTheCurrentPageIsTheLoginPage(); + $this->iSeeThatAWrongPasswordMessageIsShown(); + } + +} diff --git a/tests/acceptance/features/bootstrap/NotificationContext.php b/tests/acceptance/features/bootstrap/NotificationContext.php new file mode 100644 index 00000000000..f8b784e2465 --- /dev/null +++ b/tests/acceptance/features/bootstrap/NotificationContext.php @@ -0,0 +1,54 @@ +<?php + +/** + * + * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.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 NotificationContext implements Context, ActorAwareInterface { + + use ActorAware; + + /** + * @return Locator + */ + public static function notificationMessage($message) { + return Locator::forThe()->content($message)->descendantOf(self::notificationContainer())-> + describedAs("$message notification"); + } + + /** + * @return Locator + */ + private static function notificationContainer() { + return Locator::forThe()->id("notification-container")-> + describedAs("Notification container"); + } + + /** + * @Then I see that the :message notification is shown + */ + public function iSeeThatTheNotificationIsShown($message) { + PHPUnit_Framework_Assert::assertTrue($this->actor->find( + self::notificationMessage($message), 10)->isVisible()); + } + +} diff --git a/tests/acceptance/features/bootstrap/SettingsMenuContext.php b/tests/acceptance/features/bootstrap/SettingsMenuContext.php new file mode 100644 index 00000000000..9ce8df4caef --- /dev/null +++ b/tests/acceptance/features/bootstrap/SettingsMenuContext.php @@ -0,0 +1,122 @@ +<?php + +/** + * + * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.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 SettingsMenuContext implements Context, ActorAwareInterface { + + use ActorAware; + + /** + * @return Locator + */ + public static function settingsMenuButton() { + return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'settings']")-> + describedAs("Settings menu button"); + } + + /** + * @return Locator + */ + public static function settingsMenu() { + return Locator::forThe()->id("expanddiv")->descendantOf(self::settingsMenuButton())-> + describedAs("Settings menu"); + } + + /** + * @return Locator + */ + public static function usersMenuItem() { + return self::menuItemFor("Users"); + } + + /** + * @return Locator + */ + public static function logOutMenuItem() { + return self::menuItemFor("Log out"); + } + + /** + * @return Locator + */ + private static function menuItemFor($itemText) { + return Locator::forThe()->content($itemText)->descendantOf(self::settingsMenu())-> + describedAs($itemText . " item in Settings menu"); + } + + /** + * @When I open the Settings menu + */ + public function iOpenTheSettingsMenu() { + $this->actor->find(self::settingsMenuButton(), 10)->click(); + } + + /** + * @When I open the User settings + */ + public function iOpenTheUserSettings() { + $this->iOpenTheSettingsMenu(); + + $this->actor->find(self::usersMenuItem(), 2)->click(); + } + + /** + * @When I log out + */ + public function iLogOut() { + $this->iOpenTheSettingsMenu(); + + $this->actor->find(self::logOutMenuItem(), 2)->click(); + } + + /** + * @Then I see that the Settings menu is shown + */ + public function iSeeThatTheSettingsMenuIsShown() { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::settingsMenu(), 10)->isVisible()); + } + + /** + * @Then I see that the :itemText item in the Settings menu is shown + */ + public function iSeeThatTheItemInTheSettingsMenuIsShown($itemText) { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::menuItemFor($itemText), 10)->isVisible()); + } + + /** + * @Then I see that the :itemText item in the Settings menu is not shown + */ + public function iSeeThatTheItemInTheSettingsMenuIsNotShown($itemText) { + $this->iSeeThatTheSettingsMenuIsShown(); + + try { + PHPUnit_Framework_Assert::assertFalse( + $this->actor->find(self::menuItemFor($itemText))->isVisible()); + } catch (NoSuchElementException $exception) { + } + } + +} diff --git a/tests/acceptance/features/bootstrap/UsersSettingsContext.php b/tests/acceptance/features/bootstrap/UsersSettingsContext.php new file mode 100644 index 00000000000..93ab7246eb6 --- /dev/null +++ b/tests/acceptance/features/bootstrap/UsersSettingsContext.php @@ -0,0 +1,102 @@ +<?php + +/** + * + * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.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 UsersSettingsContext implements Context, ActorAwareInterface { + + use ActorAware; + + /** + * @return Locator + */ + public static function userNameFieldForNewUser() { + return Locator::forThe()->field("newusername")-> + describedAs("User name field for new user in Users Settings"); + } + + /** + * @return Locator + */ + public static function passwordFieldForNewUser() { + return Locator::forThe()->field("newuserpassword")-> + describedAs("Password field for new user in Users Settings"); + } + + /** + * @return Locator + */ + public static function createNewUserButton() { + return Locator::forThe()->xpath("//form[@id = 'newuser']//input[@type = 'submit']")-> + describedAs("Create user button in Users Settings"); + } + + /** + * @return Locator + */ + public static function rowForUser($user) { + return Locator::forThe()->xpath("//table[@id = 'userlist']//th[normalize-space() = '$user']/..")-> + describedAs("Row for user $user in Users Settings"); + } + + /** + * @return Locator + */ + public static function passwordCellForUser($user) { + return Locator::forThe()->css(".password")->descendantOf(self::rowForUser($user))-> + describedAs("Password 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"); + } + + /** + * @When I create user :user with password :password + */ + public function iCreateUserWithPassword($user, $password) { + $this->actor->find(self::userNameFieldForNewUser(), 10)->setValue($user); + $this->actor->find(self::passwordFieldForNewUser())->setValue($password); + $this->actor->find(self::createNewUserButton())->click(); + } + + /** + * @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"); + } + + /** + * @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)); + } + +} |