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

Refactored form filling functionality.

parent d4016aed
No related merge requests found
......@@ -28,6 +28,7 @@
* @link http://vufind.org/wiki/vufind2:unit_tests Wiki
*/
namespace VuFindTest\Unit;
use Behat\Mink\Element\Element;
/**
* Trait with utility methods for user creation/management. Assumes that it
......@@ -64,6 +65,34 @@ trait UserCreationTrait
}
}
/**
* Mink support function: fill in the account creation form.
*
* @param Element $page Page element.
* @param array $overrides Optional overrides for form values.
*
* @return void
*/
protected function fillInAccountForm(Element $page, $overrides = [])
{
$defaults = [
'firstname' => 'Tester',
'lastname' => 'McTestenson',
'email' => 'username1@ignore.com',
'username' => 'username1',
'password' => 'test',
'password2' => 'test'
];
foreach ($defaults as $field => $default) {
$element = $page->findById('account_' . $field);
$this->assertNotNull($element);
$element->setValue(
isset($overrides[$field]) ? $overrides[$field] : $default
);
}
}
/**
* Static teardown support function to destroy user accounts. Accounts are
* expected to exist, and the method will fail if they are missing.
......@@ -87,7 +116,7 @@ trait UserCreationTrait
foreach ((array)$users as $username) {
$user = $userTable->getByUsername($username, false);
if (empty($user)) {
throw new \Exception('Problem deleting expected user.');
throw new \Exception("Problem deleting expected user ($user).");
}
$user->delete();
}
......
......@@ -97,19 +97,13 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase
$page->find('css', '.modal-body .btn.btn-primary.disabled')
);
$page->find('css', '.modal-body .btn.btn-primary')->click();
$this->assertNotNull($page->findById('account_firstname'));
// Invalid email
$page->findById('account_firstname')->setValue('Tester');
$page->findById('account_lastname')->setValue('McTestenson');
$page->findById('account_email')->setValue('blargasaurus');
$page->findById('account_username')->setValue('username1');
$page->findById('account_password')->setValue('test');
$page->findById('account_password2')->setValue('test');
$this->fillInAccountForm($page, ['email' => 'blargasaurus']);
$this->assertNull(
$page->find('css', '.modal-body .btn.btn-primary.disabled')
);
$page->find('css', '.modal-body .btn.btn-primary')->click();
$this->assertNotNull($page->findById('account_firstname'));
// Correct
$page->findById('account_email')->setValue('username1@ignore.com');
$page->find('css', '.modal-body .btn.btn-primary')->click();
......@@ -230,19 +224,13 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase
$page->find('css', '.modal-body .btn.btn-primary.disabled')
);
$page->find('css', '.modal-body .btn.btn-primary')->click();
$this->assertNotNull($page->findById('account_firstname'));
$page->findById('account_firstname')->setValue('Tester');
$page->findById('account_lastname')->setValue('McTestenson');
$page->findById('account_password')->setValue('test');
$page->findById('account_password2')->setValue('test');
$page->findById('account_username')->setValue('username2');
// Invalid email
$page->findById('account_email')->setValue('blargasaurus');
$this->fillInAccountForm(
$page, ['username' => 'username2', 'email' => 'blargasaurus']
);
$this->assertNull(
$page->find('css', '.modal-body .btn.btn-primary.disabled')
);
$page->find('css', '.modal-body .btn.btn-primary')->click();
$this->assertNotNull($page->findById('account_firstname'));
$page->findById('account_email')->setValue('username2@ignore.com');
// Test taken
$page->findById('account_username')->setValue('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