annotate core/tests/Drupal/Nightwatch/Commands/drupalCreateUser.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@17 1 /**
Chris@17 2 * Logs into Drupal as the given user.
Chris@17 3 *
Chris@17 4 * @param {object} settings
Chris@17 5 * Settings object
Chris@17 6 * @param {string} settings.name
Chris@17 7 * The user name.
Chris@17 8 * @param {string} settings.password
Chris@17 9 * The user password.
Chris@17 10 * @param {array} [settings.permissions=[]]
Chris@17 11 * The list of permissions granted for the user.
Chris@17 12 * @param {function} callback
Chris@17 13 * A callback which will be called, when the creating the use is finished.
Chris@17 14 * @return {object}
Chris@17 15 * The drupalCreateUser command.
Chris@17 16 */
Chris@17 17 exports.command = function drupalCreateUser(
Chris@17 18 { name, password, permissions = [] },
Chris@17 19 callback,
Chris@17 20 ) {
Chris@17 21 const self = this;
Chris@17 22
Chris@17 23 let role;
Chris@17 24 this.perform((client, done) => {
Chris@17 25 if (permissions) {
Chris@17 26 client.drupalCreateRole({ permissions, name: null }, newRole => {
Chris@17 27 role = newRole;
Chris@17 28 done();
Chris@17 29 });
Chris@17 30 } else {
Chris@17 31 done();
Chris@17 32 }
Chris@17 33 }).drupalLoginAsAdmin(() => {
Chris@17 34 this.drupalRelativeURL('/admin/people/create')
Chris@17 35 .setValue('input[name="name"]', name)
Chris@17 36 .setValue('input[name="pass[pass1]"]', password)
Chris@17 37 .setValue('input[name="pass[pass2]"]', password)
Chris@17 38 .perform((client, done) => {
Chris@17 39 if (role) {
Chris@17 40 client.click(`input[name="roles[${role}]`, () => {
Chris@17 41 done();
Chris@17 42 });
Chris@17 43 } else {
Chris@17 44 done();
Chris@17 45 }
Chris@17 46 })
Chris@17 47 .submitForm('#user-register-form')
Chris@17 48 .assert.containsText(
Chris@17 49 '.messages',
Chris@17 50 'Created a new user account',
Chris@17 51 `User "${name}" was created succesfully.`,
Chris@17 52 );
Chris@17 53 });
Chris@17 54
Chris@17 55 if (typeof callback === 'function') {
Chris@17 56 callback.call(self);
Chris@17 57 }
Chris@17 58
Chris@17 59 return this;
Chris@17 60 };