Skip to content
Snippets Groups Projects
Commit 0b0746ff authored by Demian Katz's avatar Demian Katz
Browse files

Test password change functionality.

parent b96bb692
Branches
Tags
No related merge requests found
...@@ -134,6 +134,29 @@ trait UserCreationTrait ...@@ -134,6 +134,29 @@ trait UserCreationTrait
} }
} }
/**
* Mink support function: fill in the change password form.
*
* @param Element $page Page element.
* @param string $old Old password
* @param string $new New password
* @param bool $inModal Should we assume the login box is in a lightbox?
* @param string $prefix Extra selector prefix
*
* @return void
*/
protected function fillInChangePasswordForm(Element $page, $old, $new,
$inModal = false, $prefix = '#newpassword '
) {
$prefix = ($inModal ? '.modal-body ' : '') . $prefix;
$usernameField = $this->findCss($page, $prefix . '[name="oldpwd"]');
$usernameField->setValue($old);
$passwordField = $this->findCss($page, $prefix . '[name="password"]');
$passwordField->setValue($new);
$password2Field = $this->findCss($page, $prefix . '[name="password2"]');
$password2Field->setValue($new);
}
/** /**
* Submit the login form (assuming it's open). * Submit the login form (assuming it's open).
* *
......
<?php
/**
* Mink account actions test class.
*
* PHP version 5
*
* Copyright (C) Villanova University 2011.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/
namespace VuFindTest\Mink;
use Behat\Mink\Element\Element;
/**
* Mink account actions test class.
*
* @category VuFind
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/
class AccountActionsTest extends \VuFindTest\Unit\MinkTestCase
{
use \VuFindTest\Unit\UserCreationTrait;
/**
* Standard setup method.
*
* @return mixed
*/
public static function setUpBeforeClass()
{
return static::failIfUsersExist();
}
/**
* Standard setup method.
*
* @return void
*/
public function setUp()
{
// Give up if we're not running in CI:
if (!$this->continuousIntegrationRunning()) {
return $this->markTestSkipped('Continuous integration not running.');
}
}
/**
* Test changing a password.
*
* @return void
*/
public function testChangePassword()
{
$session = $this->getMinkSession();
$session->visit($this->getVuFindUrl());
$page = $session->getPage();
// Create account
$this->findCss($page, '#loginOptions a')->click();
$this->snooze();
$this->findCss($page, '.modal-body .createAccountLink')->click();
$this->fillInAccountForm($page);
$this->findCss($page, '.modal-body .btn.btn-primary')->click();
$this->snooze();
// Log out
$this->findCss($page, '.logoutOptions a.logout')->click();
$this->snooze();
// Log back in
$this->findCss($page, '#loginOptions a')->click();
$this->fillInLoginForm($page, 'username1', 'test');
$this->findCss($page, '.modal-body .btn.btn-primary')->click();
$this->snooze();
// We should now be on account screen; go to change password page
$this->findAndAssertLink($page, 'Change Password')->click();
$this->snooze();
// Change the password (but get the old password wrong)
$this->fillInChangePasswordForm($page, 'bad', 'good');
$this->findCss($page, '#newpassword .btn.btn-primary')->click();
$this->snooze();
$this->assertEquals(
'Invalid login -- please try again.',
$this->findCss($page, '.alert-danger')->getText()
);
// Change the password successfully:
$this->fillInChangePasswordForm($page, 'test', 'good');
$this->findCss($page, '#newpassword .btn.btn-primary')->click();
$this->snooze();
$this->assertEquals(
'Your password has successfully been changed',
$this->findCss($page, '.alert-success')->getText()
);
// Log out
$this->findCss($page, '.logoutOptions a.logout')->click();
$this->snooze();
// Log back in (using old credentials, which should now fail):
$this->findCss($page, '#loginOptions a')->click();
$this->fillInLoginForm($page, 'username1', 'test');
$this->findCss($page, '.modal-body .btn.btn-primary')->click();
$this->assertLightboxWarning($page, 'Invalid login -- please try again.');
$this->snooze();
// Now log in successfully:
$this->fillInLoginForm($page, 'username1', 'good');
$this->findCss($page, '.modal-body .btn.btn-primary')->click();
$this->snooze();
// One final log out (to confirm that log in really worked).
$this->findCss($page, '.logoutOptions a.logout')->click();
$this->snooze();
}
/**
* Standard teardown method.
*
* @return void
*/
public static function tearDownAfterClass()
{
static::removeUsers(['username1']);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment