Skip to content

Commit

Permalink
Teach UI tests to know if a user should exist or not
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Feb 21, 2018
1 parent f755322 commit c7344a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
13 changes: 7 additions & 6 deletions tests/ui/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,17 @@ public function setUpScenarioGetRegularUsersAndGroups(
*/
public function tearDownScenarioDeleteCreatedUsersAndGroups() {
$baseUrl = $this->getMinkParameter("base_url");
foreach ($this->getCreatedUserNames() as $user) {
foreach ($this->getCreatedUsers() as $username => $user) {
$result = UserHelper::deleteUser(
$baseUrl,
$user,
$username,
"admin",
$this->getUserPassword("admin")
);

if ($result->getStatusCode() !== 200) {
if ($user['shouldHaveBeenCreated'] && ($result->getStatusCode() !== 200)) {
error_log(
"INFORMATION: could not delete user. '" . $user . "'"
"INFORMATION: could not delete user '" . $username . "' "
. $result->getStatusCode() . " " . $result->getBody()
);
}
Expand Down Expand Up @@ -558,12 +558,13 @@ public function getCreatedGroupNames() {
* @return void
*/
public function addUserToCreatedUsersList(
$user, $password, $displayName = null, $email = null
$user, $password, $displayName = null, $email = null, $shouldHaveBeenCreated = true
) {
$this->createdUsers [$user] = [
"password" => $password,
"displayname" => $displayName,
"email" => $email
"email" => $email,
"shouldHaveBeenCreated" => $shouldHaveBeenCreated
];
}

Expand Down
9 changes: 6 additions & 3 deletions tests/ui/features/bootstrap/UsersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public function quotaOfUserIsSetTo($username, $quota) {
}

/**
* @When /^I create a user with the name "([^"]*)" (?:and )?the password "([^"]*)"(?: and the email "([^"]*)")?(?: that is a member of these groups)?$/
* @When /^I (attempt to |)create a user with the name "([^"]*)" (?:and )?the password "([^"]*)"(?: and the email "([^"]*)")?(?: that is a member of these groups)?$/
* @param string $username
* @param string $password
* @param string $email
* @param TableNode $groupsTable table of groups with a heading | group |
* @return void
*/
public function iCreateAUserInTheGUI(
$username, $password, $email=null, TableNode $groupsTable=null
$attemptTo, $username, $password, $email=null, TableNode $groupsTable=null
) {
if (!is_null($groupsTable)) {
$groups = $groupsTable->getColumn(0);
Expand All @@ -102,8 +102,11 @@ public function iCreateAUserInTheGUI(
$this->usersPage->createUser(
$this->getSession(), $username, $password, $email, $groups
);

$shouldHaveBeenCreated = ($attemptTo === "");

$this->featureContext->addUserToCreatedUsersList(
$username, $password, "", $email
$username, $password, "", $email, $shouldHaveBeenCreated
);
if (is_array($groups)) {
foreach ($groups as $group) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/features/other/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ So that unauthorised access is impossible
Scenario Outline: use the webUI to create a user with special invalid characters
Given I am logged in as admin
And I am on the users page
When I create a user with the name <user> and the password <pwd>
When I attempt to create a user with the name <user> and the password <pwd>
Then notifications should be displayed with the text
|Error creating user: Only the following characters are allowed in a username: "a-z", "A-Z", "0-9", and "_.@-'"|
And I should be redirected to a page with the title "Users - ownCloud"
Expand All @@ -49,15 +49,15 @@ So that unauthorised access is impossible
Scenario: use the webUI to create a user with empty password
Given I am logged in as admin
And I am on the users page
When I create a user with the name "bijay" and the password ""
When I attempt to create a user with the name "bijay" and the password ""
Then notifications should be displayed with the text
|Error creating user: A valid password must be provided|
And I should be redirected to a page with the title "Users - ownCloud"

Scenario Outline: use the webUI to create a user with less than 3 characters
Given I am logged in as admin
And I am on the users page
When I create a user with the name <user> and the password <pwd>
When I attempt to create a user with the name <user> and the password <pwd>
Then notifications should be displayed with the text
|Error creating user: The username must be at least 3 characters long|
Examples:
Expand Down

0 comments on commit c7344a9

Please sign in to comment.