diff --git a/module/VuFind/src/VuFindTest/Unit/UserCreationTrait.php b/module/VuFind/src/VuFindTest/Unit/UserCreationTrait.php index 077b6cf27f1bf1258222d9bbe8b6be81376319d9..9f1188abcf5c5f3155027496e27316c1ee833482 100644 --- a/module/VuFind/src/VuFindTest/Unit/UserCreationTrait.php +++ b/module/VuFind/src/VuFindTest/Unit/UserCreationTrait.php @@ -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). * diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/AccountActionsTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/AccountActionsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..00cee4785c41233827744b2869412f97146e59e0 --- /dev/null +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/AccountActionsTest.php @@ -0,0 +1,148 @@ +<?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']); + } +}