Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/ui/features/bootstrap/LoginContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LoginContext extends RawMinkContext implements Context
{
private $loginPage;
private $filesPage;
private $expectedPage;
private $featureContext;

public function __construct(LoginPage $loginPage)
Expand All @@ -59,6 +60,24 @@ public function iLoginWithUsernameAndPassword($username, $password)
$this->filesPage->waitTillPageIsLoaded($this->getSession());
}

/**
* @When I login with username :username and invalid password :password
*/
public function iLoginWithUsernameAndInvalidPassword($username, $password)
{
$this->loginPage->loginAs($username, $password, 'LoginPage');
$this->loginPage->waitTillPageIsLoaded($this->getSession());
}

/**
* @When I login with username :username and password :password after a redirect from the :page page
*/
public function iLoginWithUsernameAndPasswordAfterRedirectFromThePage($username, $password, $page)
{
$this->expectedPage = $this->loginPage->loginAs($username, $password, str_replace(' ', '', ucwords($page)) . 'Page');
$this->expectedPage->waitTillPageIsLoaded($this->getSession());
}

/**
* @When I login as a regular user with a correct password
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public function iAmOnThePersonalGeneralSettingsPage()
$this->personalGeneralSettingsPage->waitForOutstandingAjaxCalls($this->getSession());
}

/**
* @Given I go to the personal general settings page
*/
public function iGoToThePersonalGeneralSettingsPage()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOTO 😮

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some guys had a discussion about GoTo a long time ago?
https://www.cs.sjsu.edu/~mak/CS185C/KnuthStructuredProgrammingGoTo.pdf
https://www.cs.utexas.edu/users/EWD/transcriptions/EWD02xx/EWD215.html
"I am familiar with the observation that the quality of programmers is a decreasing function of the density of go to statements in the programs they produce" - Dijkstra
:)

{
$this->visitPath($this->personalGeneralSettingsPage->getPagePath());
$this->personalGeneralSettingsPage->waitForOutstandingAjaxCalls($this->getSession());
}

/**
* @When I change the language to :language
*/
Expand Down
28 changes: 24 additions & 4 deletions tests/ui/features/lib/LoginPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,39 @@
namespace Page;

use SensioLabs\Behat\PageObjectExtension\PageObject\Page;
use Behat\Mink\Session;

class LoginPage extends OwncloudPage
{
/**
* @var string $path
*/
protected $path = '/index.php/login';
protected $userInputId = "user";
protected $passwordInputId = "password";

public function loginAs($username, $password)
public function loginAs($username, $password, $target='FilesPage')
{
$this->fillField("user", $username);
$this->fillField("password", $password);
$this->fillField($this->userInputId, $username);
$this->fillField($this->passwordInputId, $password);
$this->findById("submit")->click();
return $this->getPage('FilesPage');
return $this->getPage($target);
}

//there is no reliable loading indicator on the login page, so just wait for
//the user and password to be there.
public function waitTillPageIsLoaded(Session $session, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC)
{
$currentTime = microtime(true);
$end = $currentTime + ($timeout_msec / 1000);
while ($currentTime <= $end) {
if (($this->findById($this->userInputId) !== null) &&
($this->findById($this->passwordInputId) !== null)) {
break;
}
usleep(STANDARDSLEEPTIMEMICROSEC);
$currentTime = microtime(true);
}
$this->waitForOutstandingAjaxCalls($session);
}
}
20 changes: 15 additions & 5 deletions tests/ui/features/lib/OwncloudPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public function waitTillPageIsLoaded(Session $session, $timeout_msec=STANDARDUIW
$end = $currentTime + ($timeout_msec / 1000);
while ($currentTime <= $end) {
$loadingIndicator=$this->find("css", '.loading');
$visibility = $this->elementHasCSSValue(
$loadingIndicator, 'visibility', 'visible'
);
if ($visibility===FALSE) {
break;
if (!is_null($loadingIndicator)) {
$visibility = $this->elementHasCSSValue(
$loadingIndicator, 'visibility', 'visible'
);
if ($visibility===FALSE) {
break;
}
}
usleep(STANDARDSLEEPTIMEMICROSEC);
$currentTime = microtime(true);
Expand Down Expand Up @@ -118,6 +120,14 @@ public function getMyUsername() {
return $this->findById($this->userNameDispayId)->getText();
}

/**
* return the path to the relevant page
* @return string
*/
public function getPagePath() {
return $this->getPath();
}

/**
* Gets the Coordinates of a Mink Element
*
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/features/lib/PersonalGeneralSettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace Page;

use SensioLabs\Behat\PageObjectExtension\PageObject\Page;
use Behat\Mink\Session;

class PersonalGeneralSettingsPage extends OwncloudPage
{
Expand All @@ -32,9 +33,26 @@ class PersonalGeneralSettingsPage extends OwncloudPage
*/
protected $path = '/index.php/settings/personal?sectionid=general';
protected $languageSelectId = "languageinput";
protected $personalProfilePanelId = "OC\Settings\Panels\Personal\Profile";

public function changeLanguage($language)
{
$this->selectFieldOption($this->languageSelectId, $language);
}

//there is no reliable loading indicator on the personal general settings page, so just wait for
//the personal profile panel to be there.
public function waitTillPageIsLoaded(Session $session, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC)
{
$currentTime = microtime(true);
$end = $currentTime + ($timeout_msec / 1000);
while ($currentTime <= $end) {
if ($this->findById($this->personalProfilePanelId) !== null) {
break;
}
usleep(STANDARDSLEEPTIMEMICROSEC);
$currentTime = microtime(true);
}
$this->waitForOutstandingAjaxCalls($session);
}
}
22 changes: 21 additions & 1 deletion tests/ui/features/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,24 @@ Feature: login
Scenario: admin login
Given I am on the login page
When I login with username "admin" and password "admin"
Then I should be redirected to a page with the title "Files - ownCloud"
Then I should be redirected to a page with the title "Files - ownCloud"

Scenario: admin login with invalid password
Given I am on the login page
When I login with username "admin" and invalid password "invalidpassword"
Then I should be redirected to a page with the title "ownCloud"

Scenario: access the personal general settings page when not logged in
Given I go to the personal general settings page
Then I should be redirected to a page with the title "ownCloud"
When I login with username "admin" and password "admin" after a redirect from the "personal general settings" page
Then I should be redirected to a page with the title "Settings - ownCloud"

@skip @entering-the-wrong-password-breaks-the-redirect-issue-28129
Scenario: access the personal general settings page when not logged in using incorrect then correct password
Given I go to the personal general settings page
Then I should be redirected to a page with the title "ownCloud"
When I login with username "admin" and invalid password "qwerty"
Then I should be redirected to a page with the title "ownCloud"
When I login with username "admin" and password "admin" after a redirect from the "personal general settings" page
Then I should be redirected to a page with the title "Settings - ownCloud"