Add acceptance tests related to login

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2017-04-04 17:20:19 +02:00
parent 6a15d9da9c
commit 1203369ea6
8 changed files with 471 additions and 0 deletions

View File

@ -10,8 +10,17 @@ default:
- NextcloudTestServerContext
- FeatureContext
- FilesAppContext
- LoginPageContext
- NotificationContext
- SettingsMenuContext
- UsersSettingsContext
extensions:
Behat\MinkExtension:
sessions:
default:
selenium2: ~
John:
selenium2: ~
Jane:
selenium2: ~

View File

@ -27,4 +27,11 @@ class FeatureContext implements Context, ActorAwareInterface {
use ActorAware;
/**
* @When I visit the Home page
*/
public function iVisitTheHomePage() {
$this->actor->getSession()->visit($this->actor->locatePath("/"));
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,76 @@
<?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 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::settingsMenuButton())->
describedAs($itemText . " item in Settings menu");
}
/**
* @When I open the User settings
*/
public function iOpenTheUserSettings() {
$this->actor->find(self::settingsMenuButton(), 10)->click();
$this->actor->find(self::usersMenuItem(), 2)->click();
}
/**
* @When I log out
*/
public function iLogOut() {
$this->actor->find(self::settingsMenuButton(), 10)->click();
$this->actor->find(self::logOutMenuItem(), 2)->click();
}
}

View File

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

View File

@ -0,0 +1,47 @@
Feature: login
Scenario: log in with valid user and password
Given I visit the Home page
When I log in with user user0 and password 123456
Then I see that the current page is the Files app
Scenario: try to log in with valid user and invalid password
Given I visit the Home page
When I log in with user user0 and password 654321
Then I see that the current page is the Login page
And I see that a wrong password message is shown
Scenario: log in with valid user and invalid password once fixed by admin
Given I act as John
And I can not log in with user user0 and password 654231
When I act as Jane
And I am logged in as the admin
And I open the User settings
And I set the password for user0 to 654321
And I see that the "Password successfully changed" notification is shown
And I act as John
And I log in with user user0 and password 654321
Then I see that the current page is the Files app
Scenario: try to log in with invalid user
Given I visit the Home page
When I log in with user unknownUser and password 123456
Then I see that the current page is the Login page
And I see that a wrong password message is shown
Scenario: log in with invalid user once fixed by admin
Given I act as John
And I can not log in with user unknownUser and password 123456
When I act as Jane
And I am logged in as the admin
And I open the User settings
And I create user unknownUser with password 123456
And I see that the list of users contains the user unknownUser
And I act as John
And I log in with user unknownUser and password 123456
Then I see that the current page is the Files app
Scenario: log out
Given I am logged in
When I log out
Then I see that the current page is the Login page