Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
UI test for disable user
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Jun 28, 2018
1 parent eb511e0 commit 1b81c7d
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 3 deletions.
41 changes: 39 additions & 2 deletions tests/acceptance/features/bootstrap/WebUIUsersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@
*
*/

require_once 'bootstrap.php';

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\RawMinkContext;
use Page\LoginPage;
use Page\UsersPage;

require_once 'bootstrap.php';

/**
* WebUI Users context.
*/
class WebUIUsersContext extends RawMinkContext implements Context {
private $usersPage;

/**
*
* @var LoginPage
*/
private $loginPage;

/**
Expand Down Expand Up @@ -209,6 +214,38 @@ public function theUserReloadsTheUsersPage() {
$this->usersPage->waitTillPageIsLoaded($this->getSession());
}

/**
* @When the admin disables the user :username using the webUI
*
* @param string $username
*
* @return void
*/
public function theAdminDisablesTheUserUsingTheWebui($username) {
$this->usersPage->openSettingsMenu();
$this->usersPage->setSetting("Show enabled/disabled option");
$this->usersPage->disableUser($username);
}

/**
* @When the disabled user :username tries to login using the password :password from the webUI
*
* @param string $username
*
* @param string $password
*
* @return void
*/
public function theDisabledUserTriesToLogin($username, $password) {
$this->webUIGeneralContext->theUserLogsOutOfTheWebUI();
/**
*
* @var DisabledUserPage $disabledPage
*/
$disabledPage = $this->loginPage->loginAs($username, $password, 'DisabledUserPage');
$disabledPage->waitTillPageIsLoaded($this->getSession());
}

/**
* @When the administrator deletes the user with the username :username using the webUI
*
Expand Down
68 changes: 68 additions & 0 deletions tests/acceptance/features/lib/DisabledUserPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* ownCloud
*
* @author Paurakh Sharma Humagain <paurakh@jankaritech.com>
* @copyright Copyright (c) 2018 Paurakh Sharma Humagain paurakh@jankaritech.com
*
* This code 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 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/>
*
*/

namespace Page;

use Behat\Mink\Session;

/**
* Disabled page.
*/
class DisabledUserPage extends OwncloudPage {

/**
* @var string $path
*/
protected $path = '/index.php/login';
protected $userDisabledXpath = ".//li[@class='error']";

/**
*
* @param Session $session
* @param int $timeout_msec
*
* @return void
* @throws \Exception
*/
public function waitTillPageIsLoaded(
Session $session,
$timeout_msec = STANDARDUIWAITTIMEOUTMILLISEC
) {
$currentTime = \microtime(true);
$end = $currentTime + ($timeout_msec / 1000);
while ($currentTime <= $end) {
if ($this->findAll("xpath", $this->userDisabledXpath)) {
break;
}
\usleep(STANDARDSLEEPTIMEMICROSEC);
$currentTime = \microtime(true);
}

if ($currentTime > $end) {
throw new \Exception(
__METHOD__ . " timeout waiting for page to load"
);
}

$this->waitForOutstandingAjaxCalls($session);
}
}
14 changes: 13 additions & 1 deletion tests/acceptance/features/lib/UsersPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class UsersPage extends OwncloudPage {
protected $newUserAddGroupBtnXpath = ".//*[@id='newuser']//ul[@class='multiselectoptions down']//li[@title='add group']";
protected $createGroupWithNewUserInputXpath = ".//*[@id='newuser']//ul[@class='multiselectoptions down']//input[@type='text']";
protected $groupListId = "usergrouplist";
protected $disableUserCheckboxXpath = "//input[@type='checkbox']";
protected $deleteUserBtnXpath = ".//td[@class='remove']/a[@class='action delete']";

/**
* @param string $username
*
Expand Down Expand Up @@ -411,6 +412,17 @@ public function addGroup($groupName, Session $session) {
$this->waitForAjaxCallsToStartAndFinish($session);
}

/**
*
* @param string $username
*
* @return void
*/
public function disableUser($username) {
$userTr = $this->findUserInTable($username);
$userTr->find("xpath", $this->disableUserCheckboxXpath)->click();
}

/**
*
* @param string $username
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@webUI @insulated @disablePreviews
Feature: disable users
As an admin
I want to disable users
So that I can remove access to unnecessary users

Background:
Given these users have been created but not initialized:
|username|password|displayname|email |
|user1 |1234 |User One |u1@oc.com.np|
|user2 |1234 |User Two |u2@oc.com.np|
And user admin has logged in using the webUI
And the administrator has browsed to the users page

Scenario: disable a user
When the admin disables the user "user1" using the webUI
And the disabled user "user1" tries to login using the password "1234" from the webUI
Then the user should be redirected to a webUI page with the title "ownCloud"
When the user has browsed to the login page
And the user logs in with username "user2" and password "1234" using the webUI
Then the user should be redirected to a webUI page with the title "Files - ownCloud"

0 comments on commit 1b81c7d

Please sign in to comment.